npmci/dist/npmci.bash.js

45 lines
5.5 KiB
JavaScript
Raw Permalink Normal View History

2016-05-30 01:40:07 +00:00
"use strict";
require("typings-global");
var plugins = require("./npmci.plugins");
2016-06-07 01:59:47 +00:00
exports.bash = function (commandArg, retryArg, bareArg) {
if (retryArg === void 0) { retryArg = 2; }
2016-06-07 01:59:47 +00:00
if (bareArg === void 0) { bareArg = false; }
var exitCode;
var stdOut;
var execResult;
2016-06-05 12:55:08 +00:00
if (!process.env.NPMTS_TEST) {
for (var i = 0; i <= retryArg; i++) {
2016-06-07 01:59:47 +00:00
if (!bareArg) {
execResult = plugins.shelljs.exec("bash -c \"source /usr/local/nvm/nvm.sh &&" +
commandArg +
2016-06-07 02:55:28 +00:00
"\"");
}
2016-06-05 19:11:30 +00:00
else {
2016-06-07 03:37:02 +00:00
execResult = plugins.shelljs.exec(commandArg);
2016-06-05 19:11:30 +00:00
}
2016-06-07 01:59:47 +00:00
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
}
2016-06-05 19:11:30 +00:00
else {
2016-06-06 21:57:23 +00:00
plugins.beautylog.warn("Something went wrong! Exit Code: " + exitCode.toString());
2016-06-06 21:53:14 +00:00
plugins.beautylog.info("Retry " + (i + 1).toString() + " of " + retryArg.toString());
2016-06-05 19:11:30 +00:00
}
2016-06-05 12:55:08 +00:00
}
}
else {
plugins.beautylog.log("ShellExec would be: " + commandArg.blue);
2016-05-30 01:54:14 +00:00
}
2016-06-07 01:59:47 +00:00
return stdOut;
};
exports.bashBare = function (commandArg, retryArg) {
if (retryArg === void 0) { retryArg = 2; }
return exports.bash(commandArg, retryArg, true);
2016-05-30 01:40:07 +00:00
};
2016-06-07 08:21:56 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJhc2gudHMiXSwibmFtZX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