2016-05-30 01:40:07 +00:00
|
|
|
"use strict";
|
2016-07-18 14:56:53 +00:00
|
|
|
const plugins = require("./npmci.plugins");
|
2016-11-24 22:21:40 +00:00
|
|
|
let nvmSourceString = '';
|
2016-08-02 14:20:32 +00:00
|
|
|
exports.nvmAvailable = false;
|
|
|
|
let checkNvm = () => {
|
2017-02-19 13:46:05 +00:00
|
|
|
let localExec = plugins.shelljs.exec;
|
|
|
|
if (localExec(`bash -c "source /usr/local/nvm/nvm.sh"`, { silent: true }).code === 0) {
|
2016-08-02 14:20:32 +00:00
|
|
|
nvmSourceString = `source /usr/local/nvm/nvm.sh && `;
|
|
|
|
exports.nvmAvailable = true;
|
|
|
|
}
|
2017-02-19 13:46:05 +00:00
|
|
|
else if (localExec(`bash -c "source ~/.nvm/nvm.sh"`, { silent: true }).code === 0) {
|
2016-08-02 21:11:42 +00:00
|
|
|
nvmSourceString = `source ~/.nvm/nvm.sh && `;
|
|
|
|
exports.nvmAvailable = true;
|
|
|
|
}
|
|
|
|
;
|
2016-08-02 14:20:32 +00:00
|
|
|
};
|
|
|
|
checkNvm();
|
2016-12-10 21:43:14 +00:00
|
|
|
/**
|
|
|
|
* bash() allows using bash with nvm in path
|
2016-12-14 22:10:54 +00:00
|
|
|
* @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
|
2016-12-10 21:43:14 +00:00
|
|
|
*/
|
2016-07-18 14:56:53 +00:00
|
|
|
exports.bash = (commandArg, retryArg = 2, bareArg = false) => {
|
|
|
|
let exitCode;
|
|
|
|
let stdOut;
|
|
|
|
let execResult;
|
2016-12-14 22:10:54 +00:00
|
|
|
let failOnError = true;
|
|
|
|
if (retryArg === -1) {
|
|
|
|
failOnError = false;
|
|
|
|
retryArg = 0;
|
|
|
|
}
|
2016-06-05 12:55:08 +00:00
|
|
|
if (!process.env.NPMTS_TEST) {
|
2016-07-18 14:56:53 +00:00
|
|
|
for (let i = 0; i <= retryArg; i++) {
|
2016-06-07 01:59:47 +00:00
|
|
|
if (!bareArg) {
|
2016-08-02 14:20:32 +00:00
|
|
|
execResult = plugins.shelljs.exec(`bash -c "${nvmSourceString} ${commandArg}"`);
|
2016-06-05 18:51:13 +00:00
|
|
|
}
|
2016-06-05 19:11:30 +00:00
|
|
|
else {
|
2016-06-07 03:37:02 +00:00
|
|
|
execResult = plugins.shelljs.exec(commandArg);
|
2016-06-05 19:11:30 +00:00
|
|
|
}
|
2016-06-07 01:59:47 +00:00
|
|
|
exitCode = execResult.code;
|
|
|
|
stdOut = execResult.stdout;
|
2016-12-10 21:43:14 +00:00
|
|
|
// determine how bash reacts to error and success
|
2016-11-24 22:21:40 +00:00
|
|
|
if (exitCode !== 0 && i === retryArg) {
|
2016-12-14 22:10:54 +00:00
|
|
|
if (failOnError) {
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-06-05 18:51:13 +00:00
|
|
|
}
|
2016-12-14 22:10:54 +00:00
|
|
|
else if (exitCode === 0) {
|
2016-12-10 21:43:14 +00:00
|
|
|
i = retryArg + 1; // retry +1 breaks for loop, if everything works out ok retrials are not wanted
|
2016-06-05 18:51:13 +00:00
|
|
|
}
|
2016-06-05 19:11:30 +00:00
|
|
|
else {
|
2016-11-24 22:21:40 +00:00
|
|
|
plugins.beautylog.warn('Something went wrong! Exit Code: ' + exitCode.toString());
|
|
|
|
plugins.beautylog.info('Retry ' + (i + 1).toString() + ' of ' + retryArg.toString());
|
2016-06-05 19:11:30 +00:00
|
|
|
}
|
2016-06-05 12:55:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2016-11-24 22:21:40 +00:00
|
|
|
plugins.beautylog.log('ShellExec would be: ' + commandArg);
|
2016-05-30 01:54:14 +00:00
|
|
|
}
|
2016-06-07 01:59:47 +00:00
|
|
|
return stdOut;
|
|
|
|
};
|
2016-12-10 21:43:14 +00:00
|
|
|
/**
|
|
|
|
* bashBare allows usage of bash without sourcing any files like nvm
|
|
|
|
*/
|
2016-07-18 14:56:53 +00:00
|
|
|
exports.bashBare = (commandArg, retryArg = 2) => {
|
2016-06-07 01:59:47 +00:00
|
|
|
return exports.bash(commandArg, retryArg, true);
|
2016-05-30 01:40:07 +00:00
|
|
|
};
|
2016-12-10 21:43:14 +00:00
|
|
|
/**
|
|
|
|
* bashNoError allows executing stuff without throwing an error
|
|
|
|
*/
|
|
|
|
exports.bashNoError = (commandArg) => {
|
|
|
|
return exports.bash(commandArg, -1);
|
|
|
|
};
|
2017-02-19 13:46:05 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYmFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDJDQUEwQztBQUUxQyxJQUFJLGVBQWUsR0FBVyxFQUFFLENBQUE7QUFDckIsUUFBQSxZQUFZLEdBQVksS0FBSyxDQUFBO0FBQ3hDLElBQUksUUFBUSxHQUFHO0lBQ2IsSUFBSSxTQUFTLEdBQVEsT0FBTyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUE7SUFDekMsRUFBRSxDQUFDLENBQUMsU0FBUyxDQUFDLHdDQUF3QyxFQUFFLEVBQUUsTUFBTSxFQUFFLElBQUksRUFBRSxDQUFDLENBQUMsSUFBSSxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDckYsZUFBZSxHQUFHLGtDQUFrQyxDQUFBO1FBQ3BELG9CQUFZLEdBQUcsSUFBSSxDQUFBO0lBQ3JCLENBQUM7SUFBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQUMsU0FBUyxDQUFDLGdDQUFnQyxFQUFFLEVBQUUsTUFBTSxFQUFFLElBQUksRUFBRSxDQUFDLENBQUMsSUFBSSxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDcEYsZUFBZSxH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