1 | ;
|
2 | /**
|
3 | * @author: JP Lew (jp@cto.ai)
|
4 | * @date: Friday, 10th May 2019 12:10:47 pm
|
5 | * @lastModifiedBy: JP Lew (jp@cto.ai)
|
6 | * @lastModifiedTime: Thursday, 6th June 2019 6:28:12 pm
|
7 | * @copyright (c) 2019 CTO.ai
|
8 | */
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | // import { promisify } from 'util'
|
11 | /*
|
12 | * this is based on @rauschma/stringio's onExit utility:
|
13 | * http://2ality.com/2018/05/child-process-streams.html.
|
14 | * In our case, we don't want the promise to reject in case of error, because
|
15 | * this will exit the whole process. We want to continue execution in spite of
|
16 | * errors. *
|
17 | */
|
18 | function onExit(childProcess) {
|
19 | return new Promise((resolve, reject) => {
|
20 | childProcess.once('exit', (code, signal) => {
|
21 | if (code === 0) {
|
22 | resolve(undefined);
|
23 | }
|
24 | else {
|
25 | resolve({ code, signal });
|
26 | }
|
27 | });
|
28 | childProcess.once('error', (err) => {
|
29 | reject(err);
|
30 | });
|
31 | });
|
32 | }
|
33 | exports.onExit = onExit;
|
34 | // alternative is to promisify child process
|
35 | // const promisifiedSpawn: (
|
36 | // command: string,
|
37 | // params: string[],
|
38 | // options: SpawnOptions,
|
39 | // ) => Promise<ChildProcess> = promisify(spawn)
|