-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathnpm.js
More file actions
54 lines (51 loc) · 1.43 KB
/
npm.js
File metadata and controls
54 lines (51 loc) · 1.43 KB
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
51
52
53
54
import chalk from 'chalk'
import { exec } from 'child_process'
import path from 'path'
export async function install ({
logger,
cwd,
args = []
} = {}) {
cwd = path.resolve(process.cwd(), cwd)
await new Promise((resolve, reject) => {
if (!args.length) logger?.log(chalk.cyan('installing node dependencies'))
exec([(process.platform === 'win32' ? 'npm.cmd' : 'npm'), '--unsafe-perm', 'install', ...args].join(' '), {
cwd
}, (err, stdout, stderr) => {
if (!err) return resolve()
reject(stderr)
})
})
}
export async function update ({
logger,
cwd,
args = []
} = {}) {
cwd = path.resolve(process.cwd(), cwd)
await new Promise((resolve, reject) => {
if (!args.length) logger?.log(chalk.cyan('installing node dependencies'))
exec([(process.platform === 'win32' ? 'npm.cmd' : 'npm'), '--unsafe-perm', 'update', ...args].join(' '), {
cwd
}, (err, stdout, stderr) => {
if (!err) return resolve()
reject(stderr)
})
})
}
export async function uninstall ({
logger,
cwd,
args = []
} = {}) {
cwd = path.resolve(process.cwd(), cwd)
await new Promise((resolve, reject) => {
if (!args.length) logger?.log(chalk.cyan('installing node dependencies'))
exec([(process.platform === 'win32' ? 'npm.cmd' : 'npm'), '--unsafe-perm', 'uninstall', ...args].join(' '), {
cwd
}, (err, stdout, stderr) => {
if (!err) return resolve()
reject(stderr)
})
})
}