npmci/dist/npmci.bash.js

52 lines
4.4 KiB
JavaScript
Raw Permalink Normal View History

2016-05-30 01:40:07 +00:00
"use strict";
require("typings-global");
2016-07-18 14:56:53 +00:00
const plugins = require("./npmci.plugins");
let nvmSourceString = "";
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) {
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;
}
;
};
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) {
execResult = plugins.shelljs.exec(`bash -c "${nvmSourceString} ${commandArg}"`);
}
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;
if (exitCode !== 0 && i == retryArg) {
process.exit(1);
}
else if (exitCode == 0) {
i = retryArg + 1; // if everything works out ok retrials are not wanted
}
2016-06-05 19:11:30 +00:00
else {
2016-06-06 21:57:23 +00:00
plugins.beautylog.warn("Something went wrong! Exit Code: " + exitCode.toString());
2016-06-06 21:53:14 +00:00
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 {
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-09-20 10:43:37 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYmFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QjtBQUN4QiwyQ0FBMkM7QUFHM0MsSUFBSSxlQUFlLEdBQVcsRUFBRSxDQUFDO0FBQ3RCLFFBQUEsWUFBWSxHQUFZLEtBQUssQ0FBQztBQUN6QyxJQUFJLFFBQVEsR0FBRztJQUNYLEVBQUUsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLHdDQUF3QyxFQUFDLEVBQUMsTUFBTSxFQUFDLElBQUksRUFBQyxDQUFDLENBQUMsSUFBSSxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDMUYsZUFBZSxHQUFHLGtDQUFrQyxDQUFBO1FBQ3BELG9CQUFZLEdBQUcsSUFBSSxDQUFDO0lBQ3hCLENBQUM7SUFBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsZ0NBQWdDLEVBQUMsRUFBQyxNQUFNLEVBQUMsSUFBSSxFQUFDLENBQUMsQ0FBQyxJQUFJLEtBQUssQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUN6RixlQUFlLEdBQUcsMEJBQTBCLENBQUE7UUFDNUMsb0JBQVksR0FBRyxJQUFJLENBQUM7SUFDeEIsQ0FBQztJQUFBLENBQUM7QUFDTixDQUFDLENBQUM7QUFDRixRQUFRLE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