npmci/ts/npmci.install.ts

55 lines
1.8 KiB
TypeScript
Raw Normal View History

2016-11-24 22:21:40 +00:00
import * as plugins from './npmci.plugins'
import * as configModule from './npmci.config'
2017-03-11 13:07:36 +00:00
import {
bash,
bashNoError,
nvmAvailable,
yarnAvailable } from './npmci.bash'
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-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-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-03-11 13:07:36 +00:00
await configModule.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
}