-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-dependencies.ts
50 lines (37 loc) · 1.23 KB
/
install-dependencies.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { execSync } from 'node:child_process'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { log } from './log'
import type { Config } from './types'
export const installDependencies = (config: Config, destination: string) => {
if (config.noInstall) {
return
}
const packageJsonPath = join(destination, 'package.json')
let packageContents: { dependencies?: { [key: string]: string }; devDependencies?: { [key: string]: string } } = {}
try {
if (existsSync(packageJsonPath)) {
packageContents = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
}
} catch (_) {
// Ignored
}
// Install only required if there are dependencies.
const { dependencies, devDependencies } = packageContents
if (!(dependencies || devDependencies)) {
return
}
let hasContents = false
if (typeof dependencies === 'object' && Object.keys(dependencies).length > 0) {
hasContents = true
}
if (typeof devDependencies === 'object' && Object.keys(devDependencies).length > 0) {
hasContents = true
}
if (!hasContents) {
return
}
log('installing dependencies')
execSync('bun install', { stdio: 'inherit', cwd: destination })
log('dependencies installed')
}