1 | #!/usr/bin/env node
|
2 |
|
3 | const { spawnSync } = require('child_process')
|
4 |
|
5 | process.on('unhandledRejection', err => {
|
6 | throw err
|
7 | })
|
8 |
|
9 | const args = process.argv.slice(2)
|
10 |
|
11 | const scriptIndex = args.findIndex(
|
12 | x => x === 'start' || x === 'test' || x === 'build' || x === 'create'
|
13 | )
|
14 |
|
15 | const script = scriptIndex === -1 ? args[0] : args[scriptIndex]
|
16 | const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []
|
17 |
|
18 | switch (script) {
|
19 | case 'migration/tslint-to-eslint':
|
20 | case 'build':
|
21 | case 'test':
|
22 | case 'create':
|
23 | case 'start': {
|
24 | const result = spawnSync(
|
25 | 'node',
|
26 | nodeArgs
|
27 | .concat(require.resolve('../build/scripts/' + script))
|
28 | .concat(args.slice(scriptIndex + 1)),
|
29 | {
|
30 | stdio: 'inherit',
|
31 | }
|
32 | )
|
33 | if (result.signal) {
|
34 | if (result.signal === 'SIGKILL') {
|
35 | console.log(
|
36 | 'The build failed because the process exited too early. ' +
|
37 | 'This probably means the system ran out of memory or someone called ' +
|
38 | '`kill -9` on the process.'
|
39 | )
|
40 | } else if (result.signal === 'SIGTERM') {
|
41 | console.log(
|
42 | 'The build failed because the process exited too early. ' +
|
43 | 'Someone might have called `kill` or `killall`, or the system could ' +
|
44 | 'be shutting down.'
|
45 | )
|
46 | }
|
47 | process.exit(1)
|
48 | }
|
49 | process.exit(result.status)
|
50 | break
|
51 | }
|
52 | case undefined: {
|
53 | console.log('No command provided.')
|
54 | break
|
55 | }
|
56 | default:
|
57 | console.log('Unknown script "' + script + '".')
|
58 | break
|
59 | }
|