1 | const hasYarn = require('./hasYarn')
|
2 | const { shell } = require('execa')
|
3 | const fs = require('fs-extra')
|
4 | const { join } = require('path')
|
5 | const { __root, __nodeModules } = require('./paths')
|
6 | module.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 | }
|