74 lines
5.6 KiB
JavaScript
74 lines
5.6 KiB
JavaScript
"use strict";
|
|
const plugins = require("./npmci.plugins");
|
|
let nvmSourceString = '';
|
|
exports.nvmAvailable = false;
|
|
let checkNvm = () => {
|
|
let localExec = plugins.shelljs.exec;
|
|
if (localExec(`bash -c "source /usr/local/nvm/nvm.sh"`, { silent: true }).code === 0) {
|
|
nvmSourceString = `source /usr/local/nvm/nvm.sh && `;
|
|
exports.nvmAvailable = true;
|
|
}
|
|
else if (localExec(`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
|
|
* @param commandArg - The command to execute
|
|
* @param retryArg - The retryArg: 0 to any positive number will retry, -1 will always succeed, -2 will return undefined
|
|
*/
|
|
exports.bash = (commandArg, retryArg = 2, bareArg = false) => {
|
|
let exitCode;
|
|
let stdOut;
|
|
let execResult;
|
|
let failOnError = true;
|
|
if (retryArg === -1) {
|
|
failOnError = false;
|
|
retryArg = 0;
|
|
}
|
|
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) {
|
|
if (failOnError) {
|
|
process.exit(1);
|
|
}
|
|
}
|
|
else if (exitCode === 0) {
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYmFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDJDQUEwQztBQUUxQyxJQUFJLGVBQWUsR0FBVyxFQUFFLENBQUE7QUFDckIsUUFBQSxZQUFZLEdBQVksS0FBSyxDQUFBO0FBQ3hDLElBQUksUUFBUSxHQUFHO0lBQ2IsSUFBSSxTQUFTLEdBQVEsT0FBTyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUE7SUFDekMsRUFBRSxDQUFDLENBQUMsU0FBUyxDQUFDLHdDQUF3QyxFQUFFLEVBQUUsTUFBTSxFQUFFLElBQUksRUFBRSxDQUFDLENBQUMsSUFBSSxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDckYsZUFBZSxHQUFHLGtDQUFrQyxDQUFBO1FBQ3BELG9CQUFZLEdBQUcsSUFBSSxDQUFBO0lBQ3JCLENBQUM7SUFBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQUMsU0FBUyxDQUFDLGdDQUFnQyxFQUFFLEVBQUUsTUFBTSxFQUFFLElBQUksRUFBRSxDQUFDLENBQUMsSUFBSSxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDcEYsZUFBZSxHQUFHLDBCQU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