Skip to content

Commit ffd8388

Browse files
committed
Add run:proxy command
1 parent 4737cce commit ffd8388

4 files changed

Lines changed: 64 additions & 15 deletions

File tree

.gitignore

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@ lib
3232
npm-shrinkwrap.json
3333
yarn.lock
3434
package-lock.json
35-
© 2019 GitHub, Inc.
36-
Terms
37-
Privacy
38-
Security
39-
Status
40-
Help
41-
Contact GitHub
42-
Pricing
43-
API
44-
Training
45-
Blog
46-
About
35+
36+
# Ara bins
37+
.ara

package.json

Lines changed: 4 additions & 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.0",
3+
"version": "1.0.0-alpha.1",
44
"description": "Ara Framework Command Line Interface",
55
"keywords": [
66
"ara",
@@ -24,7 +24,10 @@
2424
"aws-sdk": "^2.509.0",
2525
"cac": "^6.5.2",
2626
"chalk": "^2.4.2",
27+
"download": "^7.1.0",
28+
"execa": "^2.0.4",
2729
"majo": "^0.7.1",
30+
"ora": "^3.4.0",
2831
"s3rver": "^3.3.0",
2932
"sao": "^1.6.1",
3033
"serverless-offline": "^5.10.1",

src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env node
22
const cli = require('cac')();
3-
4-
const path = require('path');
53
const sao = require('sao');
4+
const path = require('path');
65

76
const generateProject = require('./generators/project');
87
const runLambda = require('./run/lambda');
98
const serveAsset = require('./run/asset');
9+
const runProxy = require('./run/proxy');
1010

1111
cli.command('new:project <outDir>', 'New Project')
1212
.action(outDir => generateProject(outDir));
@@ -41,4 +41,8 @@ cli.command('run:lambda', 'Run Hypernova lambda function')
4141
}
4242
});
4343

44+
cli.command('run:proxy', 'Run Nova Proxy')
45+
.option('--config [config]', 'Configuration file')
46+
.action(({ config = './nova-proxy.json' }) => runProxy(config, path.join(__dirname, '../.ara')));
47+
4448
cli.parse();

src/run/proxy.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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-proxy';
12+
const platform = os.platform();
13+
if (platform === 'darwin') {
14+
url = 'https://github.com/ara-framework/nova-proxy/releases/download/1.0.5/nova-proxy-darwin-amd64';
15+
} else if (platform === 'win32') {
16+
url = 'https://github.com/ara-framework/nova-proxy/releases/download/1.0.5/nova-proxy-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-proxy').start();
25+
try {
26+
await download(url, dest, { filename: fileName });
27+
fs.chmodSync(executable, 755);
28+
spinner.succeed('Downloaded nova-proxy');
29+
} catch (error) {
30+
spinner.fail('Downloadind nova-proxy failed');
31+
return null;
32+
}
33+
} else {
34+
return console.error(chalk.red(`run:proxy command is not supported in "${platform}"`));
35+
}
36+
}
37+
38+
try {
39+
process.env.CONFIG_FILE = process.env.CONFIG_FILE || config;
40+
41+
if (!process.env.HYPERNOVA_BATCH) {
42+
return console.error(chalk.red('HYPERNOVA_BATCH environment variable is required'));
43+
}
44+
console.log(chalk.green('Nova proxy running!!'));
45+
await execa(executable);
46+
} catch (error) {
47+
console.error(chalk.red(error.stderr || 'Nova proxy failed when running'));
48+
}
49+
50+
return null;
51+
};

0 commit comments

Comments
 (0)