forked from abhisheknaiidu/todoist-readme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec.js
38 lines (32 loc) · 833 Bytes
/
exec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const {spawn} = require('child_process');
const exec = (cmd, args = [], options = {}) => new Promise((resolve, reject) => {
console.log(`Started: ${cmd} ${args.join(' ')}`);
const optionsToCLI = {
...options
};
if (!optionsToCLI.stdio) {
Object.assign(optionsToCLI, {stdio: ['inherit', 'inherit', 'inherit']});
}
const app = spawn(cmd, args, optionsToCLI);
app.on('close', code => {
if (code !== 0) {
reject(new Error(`Command "${cmd} ${args.join(' ')}" exited with code ${code}`));
return;
}
resolve();
}
);
app.on('error', error => {
reject(error);
}
);
app.on('exit', code => {
if (code !== 0) {
reject(new Error(`Command "${cmd} ${args.join(' ')}" exited with code ${code}`));
return;
}
resolve();
}
);
});
module.exports = exec;