update usage of yarn

This commit is contained in:
2017-03-11 14:07:36 +01:00
parent 8075281499
commit 129d22b537
7 changed files with 79 additions and 22 deletions

View File

@ -1,11 +1,13 @@
import * as plugins from './npmci.plugins'
import * as paths from './npmci.paths'
import * as smartq from 'smartq'
/**
* wether nvm is available or not
*/
export let nvmAvailable = smartq.defer<boolean>()
export let yarnAvailable = smartq.defer<boolean>()
/**
* the smartshell instance for npmci
*/
@ -14,7 +16,11 @@ let npmciSmartshell = new plugins.smartshell.Smartshell({
sourceFilePaths: []
})
let checkNvm = async () => {
/**
* check for tools.
*/
let checkToolsAvailable = async () => {
// check for nvm
if (
(await plugins.smartshell.execSilent(`bash -c "source /usr/local/nvm/nvm.sh"`)).exitCode === 0
) {
@ -28,8 +34,17 @@ let checkNvm = async () => {
} else {
nvmAvailable.resolve(false)
};
// check for yarn
await plugins.smartshell.which('yarn').then(
() => {
plugins.smartshell.exec(`yarn config set cache-folder ${plugins.path.join(paths.cwd,'.yarn')}`)
yarnAvailable.resolve(true)
},
() => { yarnAvailable.resolve(false) }
)
}
checkNvm()
checkToolsAvailable()

View File

@ -1,7 +1,10 @@
import * as plugins from './npmci.plugins'
import * as configModule from './npmci.config'
import { bash, bashNoError } from './npmci.bash'
import { nvmAvailable } from './npmci.bash'
import {
bash,
bashNoError,
nvmAvailable,
yarnAvailable } from './npmci.bash'
/**
* Install a specific version of node
@ -28,7 +31,7 @@ export let install = async (versionArg) => {
await bash('node -v')
await bash('npm -v')
// lets look for further config
configModule.getConfig()
await configModule.getConfig()
.then(async configArg => {
plugins.beautylog.log('Now checking for needed global npm tools...')
for (let npmTool of configArg.globalNpmTools) {
@ -39,7 +42,11 @@ export let install = async (versionArg) => {
plugins.beautylog.log(`Tool ${npmTool} is available`)
} else {
plugins.beautylog.info(`globally installing ${npmTool} from npm`)
await bash(`npm install ${npmTool} -q -g`)
if (await yarnAvailable) {
await bash(`yarn global add ${npmTool}`)
} else {
await bash(`npm install ${npmTool} -q -g`)
}
}
}
plugins.beautylog.success('all global npm tools specified in npmextra.json are now available!')