-
-
Notifications
You must be signed in to change notification settings - Fork 794
/
install.ts
29 lines (24 loc) · 826 Bytes
/
install.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { exec } from './core'
import { Context } from './types'
/**
* Execute `npm | yarn | pnpm install` command.
*/
export default async (ctx: Context): Promise<void> => {
if (ctx.config.install === false) return // off install
if (ctx.config.install == null) {
// not contains `package.json`
if (ctx.files.find(i => i.path === 'package.json') == null) return
// npm is used by default when it contains `package.json`
ctx.config.install = 'npm'
}
// Installing dependencies...
try {
const client = ctx.config.install
/* c8 ignore next */
const cmd = process.platform === 'win32' ? client + '.cmd' : client
await exec(cmd, ['install'], { cwd: ctx.dest, stdio: 'inherit' })
} catch (e) {
throw new Error('Install dependencies failed.')
}
// Install deps completed.
}