1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const cp = require('child_process');
|
12 |
|
13 | module.exports = function spawn(
|
14 | commandString /*: string */
|
15 | ) /*: Promise<void> */ {
|
16 | const [command, ...args] = commandString.split(' ');
|
17 | const child = cp.spawn(command, args, {stdio: 'inherit'});
|
18 | return new Promise((resolve, reject) => {
|
19 | child.on('exit', code => {
|
20 | if (code === 0) {
|
21 | return resolve();
|
22 | }
|
23 | return reject(
|
24 | new Error(`Command: '${commandString}' exited with code: ${code}`)
|
25 | );
|
26 | });
|
27 | child.on('error', err => {
|
28 | return reject(err);
|
29 | });
|
30 | });
|
31 | };
|