-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand-sequence.js
More file actions
46 lines (38 loc) · 1.37 KB
/
command-sequence.js
File metadata and controls
46 lines (38 loc) · 1.37 KB
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
const child_process = require("child_process");
module.exports = function executeSequence(sequence, workingDirectory, doneCallback) {
if (doneCallback === undefined) {
doneCallback = null;
}
const errorList = [];
const stdoutList = [];
_executeSequence(sequence, workingDirectory, 0, errorList, stdoutList, doneCallback);
}
function _executeSequence(sequence, workingDirectory, i, errorList, stdoutList, doneCallback) {
if (i >= sequence.length) {
const errors = errorList.join("\n\n");
const stdout = stdoutList.join("\n\n");
if (doneCallback !== null) {
doneCallback(errors, stdout);
}
return;
}
if (sequence[i] === undefined || sequence[i] === null) {
_executeSequence(sequence, workingDirectory, i + 1, errorList, stdoutList, doneCallback);
return;
}
child_process.exec(sequence[i], {
cwd: workingDirectory
}, (error, stdout) => {
if (error) {
errorList.push(error);
const errors = errorList.join("\n\n");
const stdout = stdoutList.join("\n\n");
if (doneCallback !== null) {
doneCallback(errors, stdout);
}
} else {
stdoutList.push(stdout);
_executeSequence(sequence, workingDirectory, i + 1, errorList, stdoutList, doneCallback);
}
});
}