#!/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(`>>>command(${count}):\n${command} \n<<