forked from abhisheknaiidu/todoist-readme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.js
More file actions
23 lines (21 loc) · 634 Bytes
/
exec.js
File metadata and controls
23 lines (21 loc) · 634 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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) {
const err = new Error(`Invalid status code: ${code}`);
err.code = code;
return reject(err);
}
return resolve(code);
});
app.on('error', reject);
});
module.exports = exec;