Skip to content

Commit b27f295

Browse files
committed
feat: add run:cluster command
1 parent ffd8388 commit b27f295

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const generateProject = require('./generators/project');
77
const runLambda = require('./run/lambda');
88
const serveAsset = require('./run/asset');
99
const runProxy = require('./run/proxy');
10+
const runCluster = require('./run/cluster');
1011

1112
cli.command('new:project <outDir>', 'New Project')
1213
.action(outDir => generateProject(outDir));
@@ -45,4 +46,10 @@ cli.command('run:proxy', 'Run Nova Proxy')
4546
.option('--config [config]', 'Configuration file')
4647
.action(({ config = './nova-proxy.json' }) => runProxy(config, path.join(__dirname, '../.ara')));
4748

49+
cli.command('run:cluster', 'Run Nova Cluster')
50+
.option('--config [config]', 'Configuration file')
51+
.action(({ config = './views.json' }) => runCluster(config, path.join(__dirname, '../.ara')));
52+
53+
cli.help();
54+
4855
cli.parse();

src/run/cluster.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const os = require('os');
2+
const download = require('download');
3+
const fs = require('fs');
4+
const path = require('path');
5+
const ora = require('ora');
6+
const chalk = require('chalk');
7+
const execa = require('execa');
8+
9+
module.exports = async (config, dest) => {
10+
let url;
11+
let fileName = 'nova-cluster';
12+
const platform = os.platform();
13+
if (platform === 'darwin') {
14+
url = 'https://github.com/ara-framework/nova-cluster/releases/download/1.2.0/nova-cluster-darwin-amd64';
15+
} else if (platform === 'win32') {
16+
url = 'https://github.com/ara-framework/nova-cluster/releases/download/1.2.0/nova-cluster-windows-amd64.exe';
17+
fileName = `${fileName}.exe`;
18+
}
19+
20+
const executable = path.join(dest, fileName);
21+
22+
if (!fs.existsSync(executable)) {
23+
if (url) {
24+
const spinner = ora('Downloading nova-cluster').start();
25+
try {
26+
await download(url, dest, { filename: fileName });
27+
fs.chmodSync(executable, 755);
28+
spinner.succeed('Downloaded nova-cluster');
29+
} catch (error) {
30+
spinner.fail('Downloadind nova-cluster failed');
31+
return null;
32+
}
33+
} else {
34+
return console.error(chalk.red(`run:cluster command is not supported in "${platform}"`));
35+
}
36+
}
37+
38+
try {
39+
process.env.CONFIG_FILE = process.env.CONFIG_FILE || config;
40+
41+
execa(executable).stdout.pipe(process.stdout);
42+
} catch (error) {
43+
console.error(chalk.red(error.stderr || 'Nova cluster failed when running'));
44+
}
45+
46+
return null;
47+
};

0 commit comments

Comments
 (0)