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 13:07:36 +00:00
|
|
|
const paths = require("./npmci.paths");
|
2017-03-11 00:10:37 +00:00
|
|
|
const smartq = require("smartq");
|
|
|
|
/**
|
|
|
|
* wether nvm is available or not
|
|
|
|
*/
|
|
|
|
exports.nvmAvailable = smartq.defer();
|
2017-03-11 13:07:36 +00:00
|
|
|
exports.yarnAvailable = smartq.defer();
|
2017-03-11 00:10:37 +00:00
|
|
|
/**
|
|
|
|
* the smartshell instance for npmci
|
|
|
|
*/
|
|
|
|
let npmciSmartshell = new plugins.smartshell.Smartshell({
|
|
|
|
executor: 'bash',
|
|
|
|
sourceFilePaths: []
|
|
|
|
});
|
2017-03-11 13:07:36 +00:00
|
|
|
/**
|
|
|
|
* check for tools.
|
|
|
|
*/
|
|
|
|
let checkToolsAvailable = () => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
// check for nvm
|
2017-04-02 21:41:51 +00:00
|
|
|
if (!process.env.NPMTS_TEST) {
|
|
|
|
if ((yield plugins.smartshell.execSilent(`bash -c "source /usr/local/nvm/nvm.sh"`)).exitCode === 0) {
|
|
|
|
npmciSmartshell.addSourceFiles([`/usr/local/nvm/nvm.sh`]);
|
|
|
|
exports.nvmAvailable.resolve(true);
|
|
|
|
}
|
|
|
|
else if ((yield plugins.smartshell.execSilent(`bash -c "source ~/.nvm/nvm.sh"`)).exitCode === 0) {
|
|
|
|
npmciSmartshell.addSourceFiles([`~/.nvm/nvm.sh`]);
|
|
|
|
exports.nvmAvailable.resolve(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
exports.nvmAvailable.resolve(false);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
// check for yarn
|
|
|
|
yield plugins.smartshell.which('yarn').then(() => {
|
|
|
|
plugins.smartshell.exec(`yarn config set cache-folder ${plugins.path.join(paths.cwd, '.yarn')}`);
|
|
|
|
exports.yarnAvailable.resolve(true);
|
|
|
|
}, () => { exports.yarnAvailable.resolve(false); });
|
2017-03-11 00:10:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-04-02 21:41:51 +00:00
|
|
|
exports.nvmAvailable.resolve(true);
|
2017-03-11 13:07:36 +00:00
|
|
|
exports.yarnAvailable.resolve(true);
|
2017-04-02 21:41:51 +00:00
|
|
|
}
|
2017-03-11 00:10:37 +00:00
|
|
|
});
|
2017-03-11 13:07:36 +00:00
|
|
|
checkToolsAvailable();
|
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-04-02 21:41:51 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYmFzaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLDJDQUEwQztBQUMxQyx1Q0FBc0M7QUFFdEMsaUNBQWdDO0FBRWhDOztHQUVHO0FBQ1EsUUFBQSxZQUFZLEdBQUcsTUFBTSxDQUFDLEtBQUssRUFBVyxDQUFBO0FBQ3RDLFFBQUEsYUFBYSxHQUFHLE1BQU0sQ0FBQyxLQUFLLEVBQVcsQ0FBQTtBQUNsRDs7R0FFRztBQUNILElBQUksZUFBZSxHQUFHLElBQUksT0FBTyxDQUFDLFVBQVUsQ0FBQyxVQUFVLENBQUM7SUFDd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