1 | #!/usr/bin/env node
|
2 | const program = require('commander');
|
3 | const packageInfo = require('../package.json');
|
4 | const checkNodeVersion = require('../lib/utils/checkNodeVersion');
|
5 | const build = require('./build');
|
6 | const start = require('./start');
|
7 | const test = require('./test');
|
8 |
|
9 | (async () => {
|
10 | console.log(packageInfo.name, packageInfo.version);
|
11 |
|
12 | checkNodeVersion(packageInfo.engines.node);
|
13 |
|
14 | program
|
15 | .version(packageInfo.version)
|
16 | .usage('<command> [options]');
|
17 |
|
18 | program
|
19 | .command('build')
|
20 | .description('build project')
|
21 | .allowUnknownOption()
|
22 | .option('--config <config>', 'use custom config')
|
23 | .action(build);
|
24 |
|
25 | program
|
26 | .command('start')
|
27 | .description('start server')
|
28 | .allowUnknownOption()
|
29 | .option('--config <config>', 'use custom config')
|
30 | .option('--inspect', 'enable the Node.js inspector')
|
31 | .option('-h, --host <host>', 'dev server host', '0.0.0.0')
|
32 | .option('-p, --port <port>', 'dev server port')
|
33 | .action(start);
|
34 |
|
35 | program
|
36 | .command('test')
|
37 | .description('run tests with jest')
|
38 | .allowUnknownOption()
|
39 | .option('--config <config>', 'use custom config')
|
40 | .action(test);
|
41 |
|
42 | program.parse(process.argv);
|
43 |
|
44 | const proc = program.runningCommand;
|
45 |
|
46 | if (proc) {
|
47 | proc.on('close', process.exit.bind(process));
|
48 | proc.on('error', () => {
|
49 | process.exit(1);
|
50 | });
|
51 | }
|
52 |
|
53 | const subCmd = program.args[0];
|
54 | if (!subCmd) {
|
55 | program.help();
|
56 | }
|
57 | })();
|