2016-05-30 01:40:07 +00:00
|
|
|
"use strict";
|
2017-03-11 00:10:37 +00:00
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2016-07-18 14:56:53 +00:00
|
|
|
const plugins = require("./npmci.plugins");
|
2017-03-11 00:10:37 +00:00
|
|
|
const smartq = require("smartq");
|
|
|
|
/**
|
|
|
|
* wether nvm is available or not
|
|
|
|
*/
|
|
|
|
exports.nvmAvailable = smartq.defer();
|
|
|
|
/**
|
|
|
|
* the smartshell instance for npmci
|
|
|
|
*/
|
|
|
|
let npmciSmartshell = new plugins.smartshell.Smartshell({
|
|
|
|
executor: 'bash',
|
|
|
|
sourceFilePaths: []
|
|
|
|
});
|
|
|
|
let checkNvm = () => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
if ((yield plugins.smartshell.execSilent(`bash -c "source /usr/local/nvm/nvm.sh"`)).exitCode === 0) {
|
2017-03-11 02:35:15 +00:00
|
|
|
npmciSmartshell.addSourceFiles([`/usr/local/nvm/nvm.sh`]);
|
2017-03-11 00:10:37 +00:00
|
|
|
exports.nvmAvailable.resolve(true);
|
2016-08-02 14:20:32 +00:00
|
|
|
}
|
2017-03-11 00:10:37 +00:00
|
|
|
else if ((yield plugins.smartshell.execSilent(`bash -c "source ~/.nvm/nvm.sh"`)).exitCode === 0) {
|
2017-03-11 02:35:15 +00:00
|
|
|
npmciSmartshell.addSourceFiles([`~/.nvm/nvm.sh`]);
|
2017-03-11 00:10:37 +00:00
|
|
|
exports.nvmAvailable.resolve(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
exports.nvmAvailable.resolve(false);
|
2016-08-02 21:11:42 +00:00
|
|
|
}
|
|
|
|
;
|
2017-03-11 00:10:37 +00:00
|
|
|
});
|
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
|
|
|
*/
|
2017-03-11 00:10:37 +00:00
|
|
|
exports.bash = (commandArg, retryArg = 2, bareArg = false) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
yield exports.nvmAvailable.promise; // make sure nvm check has run
|
2016-07-18 14:56:53 +00:00
|
|
|
let execResult;
|
2017-03-11 00:10:37 +00:00
|
|
|
// determine if we fail
|
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) {
|
2017-03-11 01:41:18 +00:00
|
|
|
execResult = yield npmciSmartshell.exec(commandArg);
|
2016-06-05 18:51:13 +00:00
|
|
|
}
|
2016-06-05 19:11:30 +00:00
|
|
|
else {
|
2017-03-11 00:10:37 +00:00
|
|
|
execResult = yield plugins.smartshell.exec(commandArg);
|
2016-06-05 19:11:30 +00:00
|
|
|
}
|
2016-12-10 21:43:14 +00:00
|
|
|
// determine how bash reacts to error and success
|
2017-03-11 00:10:37 +00:00
|
|
|
if (execResult.exitCode !== 0 && i === retryArg) {
|
2016-12-14 22:10:54 +00:00
|
|
|
if (failOnError) {
|
2017-03-11 00:10:37 +00:00
|
|
|
plugins.beautylog.error('something went wrong and retries are exhausted');
|
2016-12-14 22:10:54 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-06-05 18:51:13 +00:00
|
|
|
}
|
2017-03-11 00:10:37 +00:00
|
|
|
else if (execResult.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 {
|
2017-03-11 00:10:37 +00:00
|
|
|
plugins.beautylog.warn('Something went wrong! Exit Code: ' + execResult.exitCode.toString());
|
2016-11-24 22:21:40 +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 {
|
2016-11-24 22:21:40 +00:00
|
|
|
plugins.beautylog.log('ShellExec would be: ' + commandArg);
|
2017-03-11 01:27:48 +00:00
|
|
|
yield plugins.smartdelay.delayFor(100);
|
2017-03-11 00:10:37 +00:00
|
|
|
execResult = {
|
|
|
|
exitCode: 0,
|
|
|
|
stdout: 'testOutput'
|
|
|
|
};
|
2016-05-30 01:54:14 +00:00
|
|
|
}
|
2017-03-11 00:10:37 +00:00
|
|
|
return execResult.stdout;
|
|
|
|
});
|
2016-12-10 21:43:14 +00:00
|
|
|
/**
|
|
|
|
* bashBare allows usage of bash without sourcing any files like nvm
|
|
|
|
*/
|
2017-03-11 00:34:03 +00:00
|
|
|
exports.bashBare = (commandArg, retryArg = 2) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
return yield exports.bash(commandArg, retryArg, true);
|
|
|
|
});
|
2016-12-10 21:43:14 +00:00
|
|
|
/**
|
|
|
|
* bashNoError allows executing stuff without throwing an error
|
|
|
|
*/
|
2017-03-11 00:34:03 +00:00
|
|
|
exports.bashNoError = (commandArg) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
return yield exports.bash(commandArg, -1);
|
|
|
|
});
|
2017-03-11 02:35:15 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYmFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLDJDQUEwQztBQUMxQyxpQ0FBZ0M7QUFFaEM7O0dBRUc7QUFDUSxRQUFBLFlBQVksR0FBRyxNQUFNLENBQUMsS0FBSyxFQUFXLENBQUE7QUFFakQ7O0dBRUc7QUFDSCxJQUFJLGVBQWUsR0FBRyxJQUFJLE9BQU8sQ0FBQyxVQUFVLENBQUMsVUFBVSxDQUFDO0lBQ3RELFFBQVEsRUFBRSxNQUFNO0lBQ2hCLGVBQWUsRUFBRSxFQUFFO0NBQ3BCLENBQUMsQ0FBQTtBQUVGLElBQUksUUFBUSxHQUFHO0lBQ2IsRUFBRSxDQUFDLENBQ0QsQ0FBQyxNQUFNLE9BQU8sQ0FBQyxVQUFVLENBQUMsVUFBVSxDQUFDLHdDQUF3QyxDQUFDLENBQUMsQ0FBQyxRQUFRLEtBQUssQ0FDL0YsQ0FBQyxDQUFDLENBQUM7UUFDRCxlQUFlLENBQUMsY0FBYyxDQUFDLENBQUMsdUJBQXVCLENBQUMsQ0FBQyxDQUFBO1FBQ3pELG9CQUFZLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFBO0lBQzVCLENBQUM7SUFBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQ1IsQ0FBQyxNQUFNLE9BQU8sQ0FBQyxVQUFVLENBQUMsVUFBVSxDQUFDLGdDQUFnQyxDQUFD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