improve bash, implement retagging

This commit is contained in:
2016-06-07 03:57:43 +02:00
parent 8dc0db3b71
commit 5a05092bc8
3 changed files with 74 additions and 33 deletions

View File

@@ -1,13 +1,23 @@
import "typings-global";
import * as plugins from "./npmci.plugins";
export let bash = (commandArg:string,retryArg = 2) => {
export let bash = (commandArg:string,retryArg = 2,bareArg = false) => {
let exitCode:number;
let stdOut:string;
let execResult;
if(!process.env.NPMTS_TEST){
for (let i = 0; i <= retryArg; i++){
let exitCode:number = plugins.shelljs.exec(
"bash -c \"source /usr/local/nvm/nvm.sh &&" +
commandArg +
"\""
).code;
if(!bareArg){
execResult = plugins.shelljs.exec(
"bash -c \"source /usr/local/nvm/nvm.sh &&" +
commandArg +
"\""
).code;
} else {
execResult = plugins.shelljs.exec(bareArg);
}
exitCode = execResult.code;
stdOut = execResult.stdout;
if(exitCode !== 0 && i == retryArg){
process.exit(1);
} else if(exitCode == 0){
@@ -20,22 +30,9 @@ export let bash = (commandArg:string,retryArg = 2) => {
} else {
plugins.beautylog.log("ShellExec would be: " + commandArg.blue)
}
return stdOut;
}
export let bashBare = (commandArg,retryArg = 2) => {
if (!process.env.NPMTS_TEST){
for(let i = 0; i <= retryArg; i++){
let exitCode:number = plugins.shelljs.exec(commandArg).code;
if(exitCode !== 0 && i == retryArg){
process.exit(1);
} else if(exitCode == 0){
i = retryArg + 1; // if everything works out ok retrials are not wanted
} else {
plugins.beautylog.warn("Something went wrong! Exit Code: " + exitCode.toString());
plugins.beautylog.info("Retry " + (i + 1).toString() + " of " + retryArg.toString());
}
}
} else {
plugins.beautylog.log("ShellExec would be: " + commandArg.blue)
}
return bash(commandArg,retryArg,true);
}