UNPKG

672 BJavaScriptView Raw
1const hasYarn = require('./hasYarn')
2const { shell } = require('execa')
3const fs = require('fs-extra')
4const { join } = require('path')
5const { __root, __nodeModules } = require('./paths')
6module.exports = async function(projectPath, isRemoveNM = true) {
7 if (typeof projectPath === 'boolean') {
8 isRemoveNM = projectPath
9 projectPath = null
10 }
11 projectPath = projectPath || __root
12 if (isRemoveNM && fs.pathExistsSync(__nodeModules)) {
13 await fs.remove(__nodeModules)
14 }
15 const hasYarnLock = fs.pathExistsSync(join(projectPath, 'yarn.lock'))
16 await shell(
17 `cd ${projectPath} && ${hasYarnLock && hasYarn() ? 'yarn' : 'npm i'}`
18 )
19}