-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsoleExec.js
35 lines (34 loc) · 1.65 KB
/
consoleExec.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
const { exec } = require('child_process');
const color = require('./colors');
global.strError;
global.strError = '';
module.exports = function(){
this.execCommand = function(strcommand, indexToReturn, directory){
return new Promise((resolve, reject) => {
exec(strcommand,{maxBuffer: 1024 * 500}, (error, stdout, stderr) => {
if (error) {
console.log('Executed: '+color.colorize(directory, color.CYAN)+' and '+color.colorize('failed', color.RED)+'!');
errorString = error.message.length > 0 ? ' |redcolor|'+error.message+'|/redcolor|' : '';
outputString = stdout.length > 0 ? ' |purplecolor| Output: |/purplecolor|'+stdout : '';
global.strError += '|getParentDiv| [Erro Nº '+ indexToReturn+ ']:' + errorString + '|getDiv|'+ outputString + '|/getDiv|' + '|/getParentDiv|';
// console.error(color.colorize(`${error}`, color.RED));
resolve({
currentIndex: indexToReturn,
output: global.strError
});
} else {
console.log('Executed: '+color.colorize(directory, color.CYAN)+' and '+color.colorize('passed on', color.GREEN)+'!');
// console.log(`${stdout}`);
// if(stderr.length > 0){
// console.log(`${stderr}`);
// }
resolve({
currentIndex: indexToReturn,
output: global.strError
});
}
});
});
};
return this;
}