mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-04-20 19:40:59 -05:00
43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
JavaScript
const util = require('util')
|
|
const cp = require('child_process')
|
|
const path = require('path')
|
|
const {
|
|
isWindows,
|
|
isLinux,
|
|
isMacintosh
|
|
} = require('@vue/cli-shared-utils')
|
|
|
|
const execFile = util.promisify(cp.execFile)
|
|
const spawn = util.promisify(cp.spawn)
|
|
|
|
exports.terminate = async function (childProcess, cwd) {
|
|
if (isWindows) {
|
|
try {
|
|
let options = {
|
|
stdio: ['pipe', 'pipe', 'ignore']
|
|
}
|
|
if (cwd) {
|
|
options.cwd = cwd
|
|
}
|
|
await execFile('taskkill', ['/T', '/F', '/PID', childProcess.pid.toString()], options)
|
|
} catch (err) {
|
|
return { success: false, error: err }
|
|
}
|
|
} else if (isLinux || isMacintosh) {
|
|
try {
|
|
let cmd = path.resolve(__dirname, './terminate.sh')
|
|
let result = await spawn(cmd, [childProcess.pid.toString()], {
|
|
cwd
|
|
})
|
|
if (result.error) {
|
|
return { success: false, error: result.error }
|
|
}
|
|
} catch (err) {
|
|
return { success: false, error: err }
|
|
}
|
|
} else {
|
|
childProcess.kill('SIGKILL')
|
|
}
|
|
return { success: true }
|
|
}
|