1
0
mirror of https://github.com/142vip/408CSFamily.git synced 2026-02-03 10:33:47 +08:00
Files
408CSFamily/scripts/.exec

47 lines
1.1 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* 脚本执行器执行shell命令
*/
const {join} = require('path')
const cwd = join(__dirname, '..')
process.env.PATH = `${join(cwd, 'node_modules', '.bin')}:${process.env.PATH}`
const {exec, exit} = require('shelljs');
/**
* 监听进程
* - 退出进程
*/
process.on('exit', () => {
exit()
})
/**
* 执行shell指令
*/
exports.execShell = async commands => {
let runCommands = []
if (typeof commands === 'string') {
runCommands.push(commands)
}
// 批量执行
if (Array.isArray(commands)) {
runCommands = commands
}
for (let index = 0; index < runCommands.length; index++) {
const command = runCommands[index]
const count = index + 1
console.log(`step${count}:\n${command} \nstep${count}(start): === `)
// await syncExec(command)
const execResult = await exec(command)
// 打印输出结果
console.log(execResult.stdout);
console.log(`step${count}(ending): === \n`)
// 指令异常不执行后续指令非0退出
if (execResult.code !== 0) {
exit(1)
break;
}
}
}