| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | import * as plugins from './npmci.plugins' | 
					
						
							|  |  |  | import * as configModule from './npmci.config' | 
					
						
							|  |  |  | import { bash } from './npmci.bash' | 
					
						
							| 
									
										
										
										
											2016-11-15 21:57:18 +01:00
										 |  |  | import { nvmAvailable } from './npmci.bash' | 
					
						
							| 
									
										
										
										
											2016-05-29 22:54:59 +02:00
										 |  |  | export let install = (versionArg) => { | 
					
						
							| 
									
										
										
										
											2016-11-15 21:57:18 +01:00
										 |  |  |     let done = plugins.q.defer() | 
					
						
							|  |  |  |     plugins.beautylog.log(`now installing node version ${versionArg}`) | 
					
						
							|  |  |  |     let version: string | 
					
						
							|  |  |  |     if (versionArg === 'stable') { | 
					
						
							|  |  |  |         version = 'stable' | 
					
						
							|  |  |  |     } else if (versionArg === 'lts') { | 
					
						
							|  |  |  |         version = '6' | 
					
						
							|  |  |  |     } else if (versionArg === 'legacy') { | 
					
						
							| 
									
										
										
										
											2016-11-15 22:47:21 +01:00
										 |  |  |         version = '6' | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2016-11-15 21:57:18 +01:00
										 |  |  |         version = versionArg | 
					
						
							| 
									
										
										
										
											2016-05-30 02:28:47 +02:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  |     if (nvmAvailable) { | 
					
						
							|  |  |  |         bash(`nvm install ${version} && nvm alias default ${version}`) | 
					
						
							| 
									
										
										
										
											2016-11-15 21:57:18 +01:00
										 |  |  |         plugins.beautylog.success(`Node version ${version} successfully installed!`) | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2016-11-15 21:57:18 +01:00
										 |  |  |         plugins.beautylog.warn('Nvm not in path so staying at installed node version!') | 
					
						
							| 
									
										
										
										
											2016-08-02 23:11:42 +02:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2016-11-15 21:57:18 +01:00
										 |  |  |     bash('node -v') | 
					
						
							|  |  |  |     bash('npm -v') | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // lets look for further config
 | 
					
						
							|  |  |  |     configModule.getConfig() | 
					
						
							| 
									
										
										
										
											2016-12-10 22:28:27 +01:00
										 |  |  |         .then(configArg => { | 
					
						
							|  |  |  |             for (let npmTool of configArg.globalNpmTools) { | 
					
						
							|  |  |  |                 plugins.beautylog.info(`Checking for global "${npmTool}"`) | 
					
						
							| 
									
										
										
										
											2016-11-25 22:34:28 +01:00
										 |  |  |                 let whichOutput = bash(`which ${npmTool}`) | 
					
						
							|  |  |  |                 let toolAvailable: boolean = !(/not found/.test(whichOutput)) | 
					
						
							|  |  |  |                 if (toolAvailable) { | 
					
						
							|  |  |  |                     plugins.beautylog.log(`Tool ${npmTool} is available`) | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     plugins.beautylog.info(`globally installing ${npmTool} from npm`) | 
					
						
							| 
									
										
										
										
											2016-11-25 22:44:49 +01:00
										 |  |  |                     bash(`npm install ${npmTool} -q -g`) | 
					
						
							| 
									
										
										
										
											2016-11-25 22:34:28 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             done.resolve() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2016-11-15 21:57:18 +01:00
										 |  |  |     return done.promise | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | } |