1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const spawn = require('cross-spawn');
|
6 | const args = process.argv.slice(2);
|
7 |
|
8 | const scriptIndex = args.findIndex(
|
9 | x => x === 'build' || x === 'update' || x === 'start' || x === 'test' || x === 'mock'
|
10 | );
|
11 | const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
|
12 | const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
13 |
|
14 | switch (script) {
|
15 | case 'build':
|
16 | case 'update':
|
17 | case 'start':
|
18 | case 'mock':
|
19 | case 'test': {
|
20 | const result = spawn.sync(
|
21 | 'node',
|
22 | nodeArgs
|
23 | .concat(require.resolve('./scripts/' + script))
|
24 | .concat(args.slice(scriptIndex + 1)),
|
25 | { stdio: 'inherit' }
|
26 | );
|
27 | if (result.signal) {
|
28 | if (result.signal === 'SIGKILL') {
|
29 | console.log(
|
30 | 'The build failed because the process exited too early. ' +
|
31 | 'This probably means the system ran out of memory or someone called ' +
|
32 | '`kill -9` on the process.'
|
33 | );
|
34 | } else if (result.signal === 'SIGTERM') {
|
35 | console.log(
|
36 | 'The build failed because the process exited too early. ' +
|
37 | 'Someone might have called `kill` or `killall`, or the system could ' +
|
38 | 'be shutting down.'
|
39 | );
|
40 | }
|
41 | process.exit(1);
|
42 | }
|
43 | process.exit(result.status);
|
44 | break;
|
45 | }
|
46 | default:
|
47 | console.log('Unknown script "' + script + '".');
|
48 | console.log('Perhaps you need to update earth-scripts?');
|
49 | console.log(
|
50 | 'you can call David Feng ! 😜'
|
51 | );
|
52 | break;
|
53 | } |
\ | No newline at end of file |