-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·46 lines (38 loc) · 844 Bytes
/
script.js
File metadata and controls
executable file
·46 lines (38 loc) · 844 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
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
// This script run synchronously the Commands in data.json data field
'use strict';
const { exec } = require('child_process');
const data = require('./data.json');
function runCommands(cmds) {
if(cmds && cmds.length > 0){
runCommand(cmds[0], ()=> {
cmds.splice(0,1);
runCommands(cmds);
});
}
}
function runCommand(cmd, next) {
let res = "";
const run = exec(cmd);
run.stdout.on('data', (data) => {
res+=data;
console.log(`${data}`);
});
run.stderr.on('data', (data) => {
res+=data;
console.error(`ERROR: ${data}`);
});
run.on('close', (code) => {
if(code !== 0){
console.error(`ERROR: child process exited with code ${code}`);
}
if(next){
next(res);
}
});
}
runCommands(data.data);
module.exports = {
runCommand,
runCommands,
};