npmci/dist/npmci.bash.js
2016-06-07 03:59:47 +02:00

45 lines
5.4 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 +
"\"").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) {
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU8sV0FBTSxpQkFBaUIsQ0FBQyxDQUFBO0FBRWhDLFlBQUksR0FBRyxVQUFDLFVBQWlCLEVBQUMsUUFBWSxFQUFDLE9BQWU7SUFBNUIsd0JBQVksR0FBWixZQUFZO0lBQUMsdUJBQWUsR0FBZixlQUFlO0lBQzdELElBQUksUUFBZSxDQUFDO0lBQ3BCLElBQUksTUFBYSxDQUFDO0lBQ2xCLElBQUksVUFBVSxDQUFDO0lBQ2YsRUFBRSxDQUFBLENBQUMsQ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XG4gICAgICAgICAgICBpZighYmFyZUFyZyl7XG4gICAgICAgICAgICAgICAgZXhlY1Jlc3VsdCA9IHBsdWdpbnMuc2hlbGxqcy5leGVjKFxuICAgICAgICAgICAgICAgICAgICBcImJhc2ggLWMgXFxcInNvdXJjZSAvdXNyL2xvY2FsL252bS9udm0uc2ggJiZcIiArXG4gICAgICAgICAgICAgICAgICAgIGNvbW1hbmRBcmcgK1xuICAgICAgICAgICAgICAgICAgICBcIlxcXCJcIlxuICAgICAgICAgICAgICAgICkuY29kZTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgZXhlY1Jlc3VsdCA9IHBsdWdpbnMuc2hlbGxqcy5leGVjKGJhcmVBcmcpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZXhpdENvZGUgPSBleGVjUmVzdWx0LmNvZGU7XG4gICAgICAgICAgICBzdGRPdXQgPSBleGVjUmVzdWx0LnN0ZG91dDtcbiAgICAgICAgICAgIGlmKGV4aXRDb2RlICE9PSAwICYmIGkgPT0gcmV0cnlBcmcpe1xuICAgICAgICAgICAgICAgIHByb2Nlc3MuZXhpdCgxKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZihleGl0Q29kZSA9PSAwKXtcbiAgICAgICAgICAgICAgICBpID0gcmV0cnlBcmcgKyAxOyAvLyBpZiBldmVyeXRoaW5nIHdvcmtzIG91dCBvayByZXRyaWFscyBhcmUgbm90IHdhbnRlZFxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBwbHVnaW5zLmJlYXV0eWxvZy53YXJuKFwiU29tZXRoaW5nIHdlbnQgd3JvbmchIEV4aXQgQ29kZTogXCIgKyBleGl0Q29kZS50b1N0cmluZygpKTtcbiAgICAgICAgICAgICAgICBwbHVnaW5zLmJlYXV0eWxvZy5pbmZvKFwiUmV0cnkgXCIgKyAoaSArIDEpLnRvU3RyaW5nKCkgKyBcIiBvZiBcIiArICByZXRyeUFyZy50b1N0cmluZyg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