npmci/ts/npmci.install.ts

46 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

2016-11-24 22:21:40 +00:00
import * as plugins from './npmci.plugins'
import * as configModule from './npmci.config'
2016-12-10 21:43:14 +00:00
import { bash, bashNoError } from './npmci.bash'
2016-11-15 20:57:18 +00:00
import { nvmAvailable } from './npmci.bash'
2016-05-29 20:54:59 +00:00
export let install = (versionArg) => {
2017-02-19 13:46:05 +00: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') {
version = '6'
} else {
version = versionArg
};
if (nvmAvailable) {
bash(`nvm install ${version} && nvm alias default ${version}`)
plugins.beautylog.success(`Node version ${version} successfully installed!`)
} else {
plugins.beautylog.warn('Nvm not in path so staying at installed node version!')
};
bash('node -v')
bash('npm -v')
// lets look for further config
configModule.getConfig()
.then(configArg => {
plugins.beautylog.log('Now checking for needed global npm tools...')
for (let npmTool of configArg.globalNpmTools) {
plugins.beautylog.info(`Checking for global "${npmTool}"`)
let whichOutput = bashNoError(`which ${npmTool}`)
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`)
bash(`npm install ${npmTool} -q -g`)
}
}
plugins.beautylog.success('all global npm tools specified in npmextra.json are now available!')
done.resolve()
})
return done.promise
2016-11-24 22:21:40 +00:00
}