| 
									
										
										
										
											2016-05-30 03:40:07 +02:00
										 |  |  | import "typings-global"; | 
					
						
							|  |  |  | import * as plugins from "./npmci.plugins"; | 
					
						
							| 
									
										
										
										
											2016-06-07 03:57:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-02 16:20:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  | let nvmSourceString: string = ""; | 
					
						
							|  |  |  | export let nvmAvailable: boolean = false; | 
					
						
							| 
									
										
										
										
											2016-08-02 16:20:32 +02:00
										 |  |  | let checkNvm = () => { | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  |     if (plugins.shelljs.exec(`bash -c "source /usr/local/nvm/nvm.sh"`,{silent:true}).code === 0) { | 
					
						
							| 
									
										
										
										
											2016-08-02 16:20:32 +02:00
										 |  |  |         nvmSourceString = `source /usr/local/nvm/nvm.sh && ` | 
					
						
							|  |  |  |         nvmAvailable = true; | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  |     } else if (plugins.shelljs.exec(`bash -c "source ~/.nvm/nvm.sh"`,{silent:true}).code === 0) { | 
					
						
							|  |  |  |         nvmSourceString = `source ~/.nvm/nvm.sh && ` | 
					
						
							|  |  |  |         nvmAvailable = true; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2016-08-02 16:20:32 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | checkNvm(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  | export let bash = (commandArg: string, retryArg = 2, bareArg = false) => { | 
					
						
							|  |  |  |     let exitCode: number; | 
					
						
							|  |  |  |     let stdOut: string; | 
					
						
							| 
									
										
										
										
											2016-06-07 03:57:43 +02:00
										 |  |  |     let execResult; | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  |     if (!process.env.NPMTS_TEST) { // NPMTS_TEST is used during testing
 | 
					
						
							|  |  |  |         for (let i = 0; i <= retryArg; i++) { | 
					
						
							|  |  |  |             if (!bareArg) { | 
					
						
							| 
									
										
										
										
											2016-06-07 03:57:43 +02:00
										 |  |  |                 execResult = plugins.shelljs.exec( | 
					
						
							| 
									
										
										
										
											2016-08-02 16:20:32 +02:00
										 |  |  |                     `bash -c "${nvmSourceString} ${commandArg}"` | 
					
						
							| 
									
										
										
										
											2016-06-07 04:55:08 +02:00
										 |  |  |                 ); | 
					
						
							| 
									
										
										
										
											2016-06-07 03:57:43 +02:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2016-06-07 05:36:37 +02:00
										 |  |  |                 execResult = plugins.shelljs.exec(commandArg); | 
					
						
							| 
									
										
										
										
											2016-06-07 03:57:43 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |             exitCode = execResult.code; | 
					
						
							|  |  |  |             stdOut = execResult.stdout; | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  |             if (exitCode !== 0 && i == retryArg) { | 
					
						
							| 
									
										
										
										
											2016-06-05 20:51:13 +02:00
										 |  |  |                 process.exit(1); | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  |             } else if (exitCode == 0) { | 
					
						
							| 
									
										
										
										
											2016-06-05 21:11:30 +02:00
										 |  |  |                 i = retryArg + 1; // if everything works out ok retrials are not wanted
 | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2016-06-06 23:57:23 +02:00
										 |  |  |                 plugins.beautylog.warn("Something went wrong! Exit Code: " + exitCode.toString()); | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  |                 plugins.beautylog.info("Retry " + (i + 1).toString() + " of " + retryArg.toString()); | 
					
						
							| 
									
										
										
										
											2016-06-05 20:51:13 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-06-05 14:55:08 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2016-09-04 13:42:22 +02:00
										 |  |  |         plugins.beautylog.log("ShellExec would be: " + commandArg) | 
					
						
							| 
									
										
										
										
											2016-05-30 03:43:15 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-07 03:57:43 +02:00
										 |  |  |     return stdOut; | 
					
						
							| 
									
										
										
										
											2016-06-05 14:33:59 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  | export let bashBare = (commandArg, retryArg = 2) => { | 
					
						
							|  |  |  |     return bash(commandArg, retryArg, true); | 
					
						
							| 
									
										
										
										
											2016-05-30 03:40:07 +02:00
										 |  |  | } |