npmci/dist/npmci.bash.js

45 lines
5.5 KiB
JavaScript

"use strict";
require("typings-global");
var plugins = require("./npmci.plugins");
exports.bash = function (commandArg, retryArg, bareArg) {
if (retryArg === void 0) { retryArg = 2; }
if (bareArg === void 0) { bareArg = false; }
var exitCode;
var stdOut;
var execResult;
if (!process.env.NPMTS_TEST) {
for (var i = 0; i <= retryArg; i++) {
if (!bareArg) {
execResult = plugins.shelljs.exec("bash -c \"source /usr/local/nvm/nvm.sh &&" +
commandArg +
"\"");
}
else {
execResult = plugins.shelljs.exec(commandArg);
}
exitCode = execResult.code;
stdOut = execResult.stdout;
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 stdOut;
};
exports.bashBare = function (commandArg, retryArg) {
if (retryArg === void 0) { retryArg = 2; }
return exports.bash(commandArg, retryArg, true);
};
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU8sV0FBTSxpQkFBaUIsQ0FBQyxDQUFBO0FBRWhDLFlBQUksR0FBRyxVQUFDLFVBQWlCLEVBQUMsUUFBWSxFQUFDLE9BQWU7SUFBNUIsd0JBQVksR0FBWixZQUFZO0lBQUMsdUJBQWUsR0FBZixlQUFlO0lBQzdELElBQUksUUFBZSxDQUFDO0lBQ3BCLElBQUksTUFBYSxDQUFDO0lBQ2xCLElBQUksVUFBVSxDQUFDO0lBQ2YsRUFBRSxDQUFBLENBQUMsQ0FBQyxPQUFPLENBQUMsR0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gICAgICAgICAgIGlmKCFiYXJlQXJnKXtcclxuICAgICAgICAgICAgICAgIGV4ZWNSZXN1bHQgPSBwbHVnaW5zLnNoZWxsanMuZXhlYyhcclxuICAgICAgICAgICAgICAgICAgICBcImJhc2ggLWMgXFxcInNvdXJjZSAvdXNyL2xvY2FsL252bS9udm0uc2ggJiZcIiArXHJcbiAgICAgICAgICAgICAgICAgICAgY29tbWFuZEFyZyArXHJcbiAgICAgICAgICAgICAgICAgICAgXCJcXFwiXCJcclxuICAgICAgICAgICAgICAgICk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBleGVjUmVzdWx0ID0gcGx1Z2lucy5zaGVsbGpzLmV4ZWMoY29tbWFuZEFyZyk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgZXhpdENvZGUgPSBleGVjUmVzdWx0LmNvZGU7XHJcbiAgICAgICAgICAgIHN0ZE91dCA9IGV4ZWNSZXN1bHQuc3Rkb3V0O1xyXG4gICAgICAgICAgICBpZihleGl0Q29kZSAhPT0gMCAmJiBpID09IHJldHJ5QXJnKXtcclxuICAgICAgICAgICAgICAgIHByb2Nlc3MuZXhpdCgxKTtcclxuICAgICAgICAgICAgfSBlbHNlIGlmKGV4aXRDb2RlID09IDApe1xyXG4gICAgICAgICAgICAgICAgaSA9IHJldHJ5QXJnICsgMTsgLy8gaWYgZXZlcnl0aGluZyB3b3JrcyBvdXQgb2sgcmV0cmlhbHMgYXJlIG5vdCB3YW50ZWRcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIHBsdWdpbnMuYmVhdXR5bG9nLndhcm4oXCJTb21ldGhpbmcgd2VudCB3cm9uZyEgRXhpdCBDb2RlOiBcIiArIGV4aXRDb2RlLnRvU3RyaW5nKCkpO1xyXG4gICAgICAgICAgICAgICAgcGx1Z2lucy5iZWF1dHlsb2cuaW5mbyhcIlJldHJ5IFwiICsgKGkgKyAxKS50b1N0cmluZygp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