forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspawn.js
More file actions
67 lines (55 loc) · 1.39 KB
/
spawn.js
File metadata and controls
67 lines (55 loc) · 1.39 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
55
56
57
58
59
60
61
62
63
64
65
66
67
const { log, warn, fatal } = require('./logger')
const crossSpawn = require('cross-spawn')
/*
Returns pid, takes onClose
*/
module.exports.spawn = function (cmd, params, opts, onClose) {
if (!cmd) {
fatal(`Command name was not available. Please run again.`)
}
const targetFolder = opts && opts.cwd
? ` in ${opts.cwd}`
: ''
log(`Running "${cmd} ${params.join(' ')}"${targetFolder}`)
log()
const runner = crossSpawn(
cmd,
params,
{ stdio: 'inherit', stdout: 'inherit', stderr: 'inherit', ...opts }
)
runner.on('close', code => {
log()
if (code) {
log(`Command "${cmd}" failed with exit code: ${code}`)
}
onClose && onClose(code)
})
if (opts.detach === true) {
runner.unref()
}
return runner.pid
}
/*
Returns nothing, takes onFail
*/
module.exports.spawnSync = function (cmd, params, opts, onFail) {
const targetFolder = opts && opts.cwd
? ` in ${opts.cwd}`
: ''
log(`[sync] Running "${cmd} ${params.join(' ')}"${targetFolder}`)
log()
const runner = crossSpawn.sync(
cmd,
params,
{ stdio: 'inherit', stdout: 'inherit', stderr: 'inherit', ...opts }
)
if (runner.status || runner.error) {
warn()
warn(`Command "${cmd}" failed with exit code: ${runner.status}`)
if (runner.status === null) {
warn(`Please globally install "${cmd}"`)
}
onFail && onFail()
process.exit(1)
}
}