npmci/dist/npmci.bash.js
2016-09-20 12:43:37 +02:00

52 lines
4.4 KiB
JavaScript

"use strict";
require("typings-global");
const plugins = require("./npmci.plugins");
let nvmSourceString = "";
exports.nvmAvailable = false;
let checkNvm = () => {
if (plugins.shelljs.exec(`bash -c "source /usr/local/nvm/nvm.sh"`, { silent: true }).code === 0) {
nvmSourceString = `source /usr/local/nvm/nvm.sh && `;
exports.nvmAvailable = true;
}
else if (plugins.shelljs.exec(`bash -c "source ~/.nvm/nvm.sh"`, { silent: true }).code === 0) {
nvmSourceString = `source ~/.nvm/nvm.sh && `;
exports.nvmAvailable = true;
}
;
};
checkNvm();
exports.bash = (commandArg, retryArg = 2, bareArg = false) => {
let exitCode;
let stdOut;
let execResult;
if (!process.env.NPMTS_TEST) {
for (let i = 0; i <= retryArg; i++) {
if (!bareArg) {
execResult = plugins.shelljs.exec(`bash -c "${nvmSourceString} ${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);
}
return stdOut;
};
exports.bashBare = (commandArg, retryArg = 2) => {
return exports.bash(commandArg, retryArg, true);
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYmFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QjtBQUN4QiwyQ0FBMkM7QUFHM0MsSUFBSSxlQUFlLEdBQVcsRUFBRSxDQUFDO0FBQ3RCLFFBQUEs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