npmci/dist/npmci.bash.js

52 lines
4.5 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYmFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixNQUFZLE9BQU8sV0FBTSxpQkFBaUIsQ0FBQyxDQUFBO0FBRzNDLElBQUksZUFBZSxHQ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