2017-08-27 13:24:17 +00:00
|
|
|
import * as plugins from '../npmci.plugins'
|
|
|
|
import * as npmciConfig from '../npmci.config'
|
2017-03-11 13:07:36 +00:00
|
|
|
import {
|
|
|
|
bash,
|
|
|
|
bashNoError,
|
|
|
|
nvmAvailable,
|
2017-08-27 13:24:17 +00:00
|
|
|
yarnAvailable
|
|
|
|
} from '../npmci.bash'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* handle cli input
|
|
|
|
* @param argvArg
|
|
|
|
*/
|
|
|
|
export let handleCli = async (argvArg) => {
|
|
|
|
if (argvArg._.length >= 3) {
|
|
|
|
let action: string = argvArg._[1]
|
|
|
|
switch (action) {
|
|
|
|
case 'install':
|
|
|
|
await install(argvArg._[2])
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
plugins.beautylog.error(`>>npmci node ...<< action >>${action}<< not supported`)
|
2017-08-28 11:25:22 +00:00
|
|
|
process.exit(1)
|
2017-08-27 13:24:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
plugins.beautylog.error(`>>npmci node ...<< cli arguments invalid... Please read the documentation.`)
|
2017-08-28 11:25:22 +00:00
|
|
|
process.exit(1)
|
2017-08-27 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-03-08 13:50:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Install a specific version of node
|
|
|
|
* @param versionArg
|
|
|
|
*/
|
|
|
|
export let install = async (versionArg) => {
|
2017-02-19 13:46:05 +00:00
|
|
|
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') {
|
|
|
|
version = '6'
|
|
|
|
} else {
|
|
|
|
version = versionArg
|
2017-08-27 13:24:17 +00:00
|
|
|
}
|
2017-03-11 00:10:37 +00:00
|
|
|
if (await nvmAvailable.promise) {
|
2017-03-08 13:50:41 +00:00
|
|
|
await bash(`nvm install ${version} && nvm alias default ${version}`)
|
2017-02-19 13:46:05 +00:00
|
|
|
plugins.beautylog.success(`Node version ${version} successfully installed!`)
|
|
|
|
} else {
|
|
|
|
plugins.beautylog.warn('Nvm not in path so staying at installed node version!')
|
2017-08-27 13:24:17 +00:00
|
|
|
}
|
2017-03-08 13:50:41 +00:00
|
|
|
await bash('node -v')
|
|
|
|
await bash('npm -v')
|
2017-02-19 13:46:05 +00:00
|
|
|
// lets look for further config
|
2017-08-27 13:24:17 +00:00
|
|
|
await npmciConfig.getConfig()
|
2017-03-08 13:50:41 +00:00
|
|
|
.then(async configArg => {
|
2017-02-19 13:46:05 +00:00
|
|
|
plugins.beautylog.log('Now checking for needed global npm tools...')
|
|
|
|
for (let npmTool of configArg.globalNpmTools) {
|
|
|
|
plugins.beautylog.info(`Checking for global "${npmTool}"`)
|
2017-03-08 13:50:41 +00:00
|
|
|
let whichOutput: string = await bashNoError(`which ${npmTool}`)
|
2017-02-19 13:46:05 +00:00
|
|
|
let toolAvailable: boolean = !((/not\sfound/.test(whichOutput)) || whichOutput === '')
|
|
|
|
if (toolAvailable) {
|
|
|
|
plugins.beautylog.log(`Tool ${npmTool} is available`)
|
|
|
|
} else {
|
|
|
|
plugins.beautylog.info(`globally installing ${npmTool} from npm`)
|
2017-03-11 14:17:24 +00:00
|
|
|
if (await yarnAvailable.promise) {
|
2017-03-11 13:07:36 +00:00
|
|
|
await bash(`yarn global add ${npmTool}`)
|
|
|
|
} else {
|
|
|
|
await bash(`npm install ${npmTool} -q -g`)
|
|
|
|
}
|
2017-02-19 13:46:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
plugins.beautylog.success('all global npm tools specified in npmextra.json are now available!')
|
|
|
|
})
|
2016-11-24 22:21:40 +00:00
|
|
|
}
|