npmci/dist/npmci.bash.js

64 lines
5.0 KiB
JavaScript

"use strict";
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();
/**
* bash() allows using bash with nvm in path
*/
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;
// determine how bash reacts to error and success
if (exitCode !== 0 && i === retryArg) {
process.exit(1);
}
else if (exitCode === 0 || retryArg === -1) {
i = retryArg + 1; // retry +1 breaks for loop, 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;
};
/**
* bashBare allows usage of bash without sourcing any files like nvm
*/
exports.bashBare = (commandArg, retryArg = 2) => {
return exports.bash(commandArg, retryArg, true);
};
/**
* bashNoError allows executing stuff without throwing an error
*/
exports.bashNoError = (commandArg) => {
return exports.bash(commandArg, -1);
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYmFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLmJhc2g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