-
Notifications
You must be signed in to change notification settings - Fork 15
/
Executer.js
43 lines (38 loc) · 1.36 KB
/
Executer.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
var spawn = require('child_process').spawn;
var constants = require('./constants');
module.exports = class Executer {
constructor(helmCommand, output) {
this.output = output ? output : constants.DefaultOutput;
this.helmCommand = helmCommand ? helmCommand : constants.DefaultHelmCommand;
}
callByArguments(args, callback, isJsonOutputSupported = false) {
if(isJsonOutputSupported){
args.push(constants.OutputCommand);
args.push(this.output);
}
this.execute(args, callback);
}
callByCommand(command, callback, isJsonOutputSupported = false) {
var args = command.split(' ');
if(isJsonOutputSupported){
args.push(constants.OutputCommand);
args.push(this.output);
}
this.execute(args, callback);
}
execute(args, callback) {
let helmProcess = spawn(this.helmCommand, args), stdout = '', stderr = '';
helmProcess.stdout.on('data', function (data) {
stdout += data;
});
helmProcess.stderr.on('data', function (data) {
stderr += data;
});
helmProcess.on('close', function (code) {
if (!stderr) {
stderr = undefined;
}
callback(stderr, stdout);
});
}
}