-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
38 lines (33 loc) · 835 Bytes
/
util.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
// Dependencies
const readline = require('readline');
const { exec } = require('child_process');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function input(str){
return new Promise((resolve, reject) => {
rl.question(str, (ans) => {
resolve(ans);
});
});
};
const execCmd = (command, cwd, callback) => {
let cmd = exec(command, {cwd: cwd}, function(error, stdout, stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: '+error.code);
console.log('Signal received: '+error.signal);
}
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
callback();
});
cmd.on('exit', code => {
console.log('Process exited with code '+code);
});
}
module.exports = {
input,
execCmd
}