1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const spawn = require('cross-spawn');
|
6 |
|
7 | const args = process.argv.slice(2);
|
8 | const scriptIndex = args.findIndex(x => x === 'dev' || x === 'build');
|
9 | const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
|
10 | const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
11 |
|
12 | const runScript = script => {
|
13 | const result = spawn.sync(
|
14 | 'node',
|
15 | nodeArgs
|
16 | .concat(require.resolve('../scripts/' + script))
|
17 | .concat(args.slice(scriptIndex + 1)),
|
18 | { stdio: 'inherit' }
|
19 | );
|
20 | if (result.signal) {
|
21 | if (result.signal === 'SIGKILL') {
|
22 | console.log(
|
23 | 'The build failed because the process exited too early. ' +
|
24 | 'This probably means the system ran out of memory or someone called ' +
|
25 | '`kill -9` on the process.'
|
26 | );
|
27 | } else if (result.signal === 'SIGTERM') {
|
28 | console.log(
|
29 | 'The build failed because the process exited too early. ' +
|
30 | 'Someone might have called `kill` or `killall`, or the system could ' +
|
31 | 'be shutting down.'
|
32 | );
|
33 | }
|
34 | process.exit(1);
|
35 | }
|
36 | process.exit(result.status);
|
37 | };
|
38 |
|
39 | switch (script) {
|
40 | case 'dev':
|
41 | case 'build': {
|
42 | runScript(script);
|
43 | break;
|
44 | }
|
45 | default:
|
46 | console.log('Unknown script "' + script + '".');
|
47 | console.log('See: https://github.com/shrynx/nodify/blob/master/README.md');
|
48 | break;
|
49 | }
|