Skip to content

Commit 532aedd

Browse files
authored
Merge pull request #9 from ara-framework/develop
Add command for Nova Cluster
2 parents 49ed111 + 35e4ab9 commit 532aedd

4 files changed

Lines changed: 76 additions & 1 deletion

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Nova Proxy needs a configuration file:
6565
}
6666
]
6767
}
68+
```
6869

6970
Before to run the command we need to set the `HYPERNOVA_BATCH` variable using the Nova service endpoint.
7071

@@ -75,4 +76,24 @@ export HYPERNOVA_BATCH=http://localhost:3000/batch
7576
The command uses a configuration file named `nova-proxy.json` in the folder where the command is running, otherwise you need to pass the `--config` parameter with a different path.
7677
```
7778
ara run:proxy --config ./nova-proxy.json
79+
```
80+
81+
### Run Nova Cluster
82+
83+
Nova Cluster needs a configuration file in order to map the views with their nova servers.
84+
85+
```json
86+
{
87+
"Navbar": {
88+
"server": "http://localhost:3031/batch"
89+
},
90+
"Home": {
91+
"server": "http://localhost:3030/batch"
92+
}
93+
}
94+
```
95+
96+
The command uses a configuration file named `views.json` in the folder where the command is running, otherwise you need to pass the `--config` parameter with a different path.
97+
```
98+
ara run:cluster --config ./views.json
7899
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ara-cli",
3-
"version": "1.0.0-alpha.1",
3+
"version": "1.0.0-alpha.2",
44
"description": "Ara Framework Command Line Interface",
55
"keywords": [
66
"ara",

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)