73 lines
5.5 KiB
JavaScript
73 lines
5.5 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
|
|
* @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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYmFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDJDQUEwQztBQUUxQyxJQUFJLGVBQWUsR0FBVyxFQUFFLENBQUE7QUFDckIsUUFBQSxZQUFZLEdBQVksS0FBSyxDQUFBO0FBQ3hDLElBQUksUUFBUSxHQUFHO0lBQ1gsRUFBRSxDQUFDLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsd0NBQXdDLEVBQUMsRUFBQyxNQUFNLEVBQUUsSUFBSSxFQUFDLENBQUMsQ0FBQyxJQUFJLEtBQUssQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUMzRixlQUFlLEdBQUcsa0NBQWtDLENBQUE7UUFDcEQsb0JBQVksR0FBRyxJQUFJLENBQUE7SUFDdkIsQ0FBQztJQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxnQ0FBZ0MsRUFBQyxFQUFDLE1BQU0sRUFBRSxJQUFJLEVBQUMsQ0FBQyxDQUFDLElBQUksS0FBSyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzFGLGVBQWUsR0FBRywwQkFBMEIsQ0FBQTtRQUM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