Merge branch 'master' into 'master'

fix tool Installation and bash without error.

See merge request !1
This commit is contained in:
Phil Kunz 2016-12-14 22:03:00 +00:00
commit ee7e7e2551
2 changed files with 11 additions and 3 deletions

View File

@ -15,11 +15,18 @@ checkNvm()
/** /**
* bash() allows using bash with nvm in path * bash() allows using bash with nvm in path
* @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
*/ */
export let bash = (commandArg: string, retryArg: number = 2, bareArg: boolean = false): string => { export let bash = (commandArg: string, retryArg: number = 2, bareArg: boolean = false): string => {
let exitCode: number let exitCode: number
let stdOut: string let stdOut: string
let execResult let execResult
let failOnError: boolean = true;
if(retryArg === -1) {
failOnError = false
retryArg = 0
}
if (!process.env.NPMTS_TEST) { // NPMTS_TEST is used during testing if (!process.env.NPMTS_TEST) { // NPMTS_TEST is used during testing
for (let i = 0; i <= retryArg; i++) { for (let i = 0; i <= retryArg; i++) {
if (!bareArg) { if (!bareArg) {
@ -34,8 +41,10 @@ export let bash = (commandArg: string, retryArg: number = 2, bareArg: boolean =
// determine how bash reacts to error and success // determine how bash reacts to error and success
if (exitCode !== 0 && i === retryArg) { // something went wrong and retries are exhausted if (exitCode !== 0 && i === retryArg) { // something went wrong and retries are exhausted
process.exit(1) if (failOnError) {
} else if (exitCode === 0 || retryArg === -1) { // everything went fine, or no error wanted process.exit(1)
}
} else if (exitCode === 0) { // everything went fine, or no error wanted
i = retryArg + 1 // retry +1 breaks for loop, if everything works out ok retrials are not wanted i = retryArg + 1 // retry +1 breaks for loop, if everything works out ok retrials are not wanted
} else { } else {
plugins.beautylog.warn('Something went wrong! Exit Code: ' + exitCode.toString()) plugins.beautylog.warn('Something went wrong! Exit Code: ' + exitCode.toString())

View File

@ -30,7 +30,6 @@ export let install = (versionArg) => {
for (let npmTool of configArg.globalNpmTools) { for (let npmTool of configArg.globalNpmTools) {
plugins.beautylog.info(`Checking for global "${npmTool}"`) plugins.beautylog.info(`Checking for global "${npmTool}"`)
let whichOutput = bashNoError(`which ${npmTool}`) let whichOutput = bashNoError(`which ${npmTool}`)
console.log(whichOutput)
let toolAvailable: boolean = !(/not\sfound/.test(whichOutput)) let toolAvailable: boolean = !(/not\sfound/.test(whichOutput))
if (toolAvailable) { if (toolAvailable) {
plugins.beautylog.log(`Tool ${npmTool} is available`) plugins.beautylog.log(`Tool ${npmTool} is available`)