forked from mrsone40/vets-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
34 lines (28 loc) · 859 Bytes
/
utils.js
File metadata and controls
34 lines (28 loc) · 859 Bytes
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
const { spawn, spawnSync } = require('child_process');
const runCommand = cmd => {
const child = spawn(cmd, [], { shell: true, stdio: 'inherit' });
// If the child process exits abnormally, exit parent with the same code
child.on('exit', code => {
if (code) {
process.exit(code);
}
});
// When we ^C out of the parent Node script, also interrupt the child
process.on('SIGINT', () => {
child.kill('SIGINT');
});
};
const runCommandSync = cmd => {
const child = spawnSync(cmd, [], { shell: true, stdio: 'inherit' });
return child.status;
};
/**
* Returns a promise that resolves after specified time, for use with await()
* @param {number} ms time to wait before resolving promise
*/
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
module.exports = {
runCommand,
runCommandSync,
sleep,
};