-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
56 lines (48 loc) · 1.33 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var Q = require('q');
var proc = require('child_process');
module.exports = function(result, script) {
var def = Q.defer();
if (!script) {
def.resolve(result);
} else if (script.shell) {
console.log('spawning shell');
console.log(script);
proc.exec(script.shell, function(error, stdout, stderr) {
if (error) {
console.log("exec error: " + error);
//TODO: should this be rejecting the result?
def.reject(result);
}
if (script.logOutput) {
console.log("exec stdout: " + stdout);
console.log("exec stderr: " + stderr);
}
def.resolve(result);
});
} else if (script.bashScript) {
var child = proc.spawn(script.bashScript, script.bashParams);
console.log('spawning script');
console.log(script);
child.stdout.on('data', function(data) {
if (script.logOutput) {
console.log("exec stdout: " + data);
}
});
child.stderr.on('data', function(data) {
if (script.logOutput) {
console.log("exec stderr: " + data);
}
});
child.on('exit', function(code) {
if (code != 0) {
def.reject(new Error('error running bash script'));
} else {
def.resolve(result)
}
});
} else {
//odd to do this first and last.
def.resolve(result);
}
return def.promise;
}