51 lines
4.4 KiB
JavaScript
51 lines
4.4 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();
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYmFzaC5qcyIsInNv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