UNPKG

778 BJavaScriptView Raw
1/** Copyright (c) 2018 Uber Technologies, Inc.
2 *
3 * This source code is licensed under the MIT license found in the
4 * LICENSE file in the root directory of this source tree.
5 *
6 * @flow
7 */
8
9/* eslint-env node */
10
11const cp = require('child_process');
12
13module.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};