From 1e9c2c850c8f62c444914bd0934f2d62ef5e8c35 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 5 Jun 2016 20:51:13 +0200 Subject: [PATCH] added automatic retrial of failed commands --- dist/npmci.bash.d.ts | 4 ++-- dist/npmci.bash.js | 34 +++++++++++++++++++++++----------- ts/npmci.bash.ts | 32 ++++++++++++++++++++------------ 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/dist/npmci.bash.d.ts b/dist/npmci.bash.d.ts index 28b5086..5c08c0f 100644 --- a/dist/npmci.bash.d.ts +++ b/dist/npmci.bash.d.ts @@ -1,3 +1,3 @@ import "typings-global"; -export declare let bash: (commandArg: any) => void; -export declare let bashBare: (commandArg: any) => void; +export declare let bash: (commandArg: string, retryArg?: number) => void; +export declare let bashBare: (commandArg: any, retryArg?: number) => void; diff --git a/dist/npmci.bash.js b/dist/npmci.bash.js index 327418f..5ee77ad 100644 --- a/dist/npmci.bash.js +++ b/dist/npmci.bash.js @@ -1,24 +1,36 @@ "use strict"; require("typings-global"); var plugins = require("./npmci.plugins"); -exports.bash = function (commandArg) { +exports.bash = function (commandArg, retryArg) { + if (retryArg === void 0) { retryArg = 2; } if (!process.env.NPMTS_TEST) { - var exitCode = plugins.shelljs.exec("bash -c \"source /usr/local/nvm/nvm.sh &&" + - commandArg + - "\"").code; - if (exitCode !== 0) { - process.exit(1); + for (var i = 0; i <= retryArg; i++) { + var exitCode = plugins.shelljs.exec("bash -c \"source /usr/local/nvm/nvm.sh &&" + + commandArg + + "\"").code; + if (exitCode !== 0 && i == retryArg) { + process.exit(1); + } + else if (exitCode == 0) { + i = retryArg + 1; + } } } else { plugins.beautylog.log("ShellExec would be: " + commandArg.blue); } }; -exports.bashBare = function (commandArg) { +exports.bashBare = function (commandArg, retryArg) { + if (retryArg === void 0) { retryArg = 3; } if (!process.env.NPMTS_TEST) { - var exitCode = plugins.shelljs.exec(commandArg).code; - if (exitCode !== 0) { - process.exit(1); + for (var i = 0; i <= retryArg; i++) { + var exitCode = plugins.shelljs.exec(commandArg).code; + if (exitCode !== 0 && i == retryArg) { + process.exit(1); + } + else if (exitCode == 0) { + i = retryArg + 1; + } } } else { @@ -26,4 +38,4 @@ exports.bashBare = function (commandArg) { } }; -//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU8sV0FBTSxpQkFBaUIsQ0FBQyxDQUFBO0FBQ2hDLFlBQUksR0FBRyxVQUFDLFVBQVU7SUFDekIsRUFBRSxDQUFBLENBQUMsQ0FBQyxPQUFPLENBQUMsR0FBRyxDQUFDLFVBQVUsQ0FBQyxDQUFBLENBQUM7UUFDeEIsSUFBSSxRQUFRLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQy9CLDJDQUEyQztZQUMzQyxVQUFVO1lBQ1YsSUFBSSxDQUNQLENBQUMsSUFBSSxDQUFDO1FBQ1AsRUFBRSxDQUFBLENBQUMsUUFBUSxLQUFLLENBQUMsQ0FBQyxDQUFBLENBQUM7WUFDZixPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQ3BCLENBQUM7SUFDTCxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxzQkFBc0IsR0FBRyxVQUFVLENBQUMsSUFBSSxDQUFDLENBQUE7SUFDbkUsQ0FBQztBQUNMLENBQUMsQ0FBQTtBQUVVLGdCQUFRLEdBQUcsVUFBQyxVQUFVO0lBQzdCLEVBQUUsQ0FBQyxDQUFDLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxVQUFVLENBQUMsQ0FBQSxDQUFDO1FBQ3pCLElBQUksUUFBUSxHQUF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aXQoMSk7XHJcbiAgICAgICAgICAgIH0gZWxzZSBpZihleGl0Q29kZSA9PSAwKXtcclxuICAgICAgICAgICAgICAgIGkgPSByZXRyeUFyZyArIDE7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICB9IGVsc2Uge1xyXG4gICAgICAgIHBsdWdpbnMuYmVhdXR5bG9nLmxvZyhcIlNoZWxsRXhlYyB3b3VsZCBiZTogXCIgKyBjb21tYW5kQXJnLmJsdWUpXHJcbiAgICB9XHJcbn1cclxuXHJcbmV4cG9ydCBsZXQgYmFzaEJhcmUgPSAoY29tbWFuZEFyZyxyZXRyeUFyZyA9IDMpID0+IHtcclxuICAgIGlmICghcHJvY2Vzcy5lbnYuTlBNVFNfVEVTVCl7XHJcbiAgICAgICAgZm9yKGxldCBpID0gMDsgaSA8PSByZXRyeUFyZzsgaSsrKXtcclxuICAgICAgICAgICAgbGV0IGV4aXRDb2RlID0gcGx1Z2lucy5zaGVsbGpzLmV4ZWMoY29tbWFuZEFyZykuY29kZTtcclxuICAgICAgICAgICAgaWYoZXhpdENvZGUgIT09IDAgJiYgaSA9PSByZXRyeUFyZyl7XHJcbiAgICAgICAgICAgICAgICBwcm9jZXNzLmV4aXQoMSk7XHJcbiAgICAgICAgICAgIH0gZWxzZSBpZihleGl0Q29kZSA9PSAwKXtcclxuICAgICAgICAgICAgICAgIGkgPSByZXRyeUFyZyArIDE7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICB9IGVsc2Uge1xyXG4gICAgICAgIHBsdWdpbnMuYmVhdXR5bG9nLmxvZyhcIlNoZWxsRXhlYyB3b3VsZCBiZTogXCIgKyBjb21tYW5kQXJnLmJsdWUpXHJcbiAgICB9XHJcbn0iXX0= diff --git a/ts/npmci.bash.ts b/ts/npmci.bash.ts index a6380d7..8751252 100644 --- a/ts/npmci.bash.ts +++ b/ts/npmci.bash.ts @@ -1,25 +1,33 @@ import "typings-global"; import * as plugins from "./npmci.plugins"; -export let bash = (commandArg) => { +export let bash = (commandArg:string,retryArg = 2) => { if(!process.env.NPMTS_TEST){ - let exitCode = plugins.shelljs.exec( - "bash -c \"source /usr/local/nvm/nvm.sh &&" + - commandArg + - "\"" - ).code; - if(exitCode !== 0){ - process.exit(1); + for (let i = 0; i <= retryArg; i++){ + let exitCode = plugins.shelljs.exec( + "bash -c \"source /usr/local/nvm/nvm.sh &&" + + commandArg + + "\"" + ).code; + if(exitCode !== 0 && i == retryArg){ + process.exit(1); + } else if(exitCode == 0){ + i = retryArg + 1; + } } } else { plugins.beautylog.log("ShellExec would be: " + commandArg.blue) } } -export let bashBare = (commandArg) => { +export let bashBare = (commandArg,retryArg = 3) => { if (!process.env.NPMTS_TEST){ - let exitCode = plugins.shelljs.exec(commandArg).code; - if(exitCode !== 0){ - process.exit(1); + for(let i = 0; i <= retryArg; i++){ + let exitCode = plugins.shelljs.exec(commandArg).code; + if(exitCode !== 0 && i == retryArg){ + process.exit(1); + } else if(exitCode == 0){ + i = retryArg + 1; + } } } else { plugins.beautylog.log("ShellExec would be: " + commandArg.blue)