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 = () => {
|
2016-08-02 21:11:42 +00:00
|
|
|
if (plugins.shelljs.exec(`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;
|
|
|
|
}
|
2016-08-02 21:11:42 +00:00
|
|
|
else if (plugins.shelljs.exec(`bash -c "source ~/.nvm/nvm.sh"`, { silent: true }).code === 0) {
|
|
|
|
nvmSourceString = `source ~/.nvm/nvm.sh && `;
|
|
|
|
exports.nvmAvailable = true;
|
|
|
|
}
|
|
|
|
;
|
2016-08-02 14:20:32 +00:00
|
|
|
};
|
|
|
|
checkNvm();
|
2016-07-18 14:56:53 +00:00
|
|
|
exports.bash = (commandArg, retryArg = 2, bareArg = false) => {
|
|
|
|
let exitCode;
|
|
|
|
let stdOut;
|
|
|
|
let execResult;
|
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-11-24 22:21:40 +00:00
|
|
|
if (exitCode !== 0 && i === retryArg) {
|
2016-06-05 18:51:13 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-11-24 22:21:40 +00:00
|
|
|
else if (exitCode === 0) {
|
2016-06-05 20:51:59 +00:00
|
|
|
i = retryArg + 1; // 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-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-11-24 23:07:20 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYmFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDJDQUEwQztBQUUxQyxJQUFJLGVBQWUsR0FBVyxFQUFFLENBQUE7QUFDckIsUUFBQSxZQUFZLEdBQVksS0FBSyxDQUFBO0FBQ3hDLElBQUksUUFBUSxHQUFHO0lBQ1gsRUFBRSxDQUFDLENBQUMsT0FBT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