UNPKG

@em-cli/shared

Version:

脚手架工具方法包

67 lines (54 loc) 1.35 kB
import shelljs from 'shelljs'; import logger from "./logger"; class ShellsManager { success = []; error = []; shells = []; constructor(op) { this.op = op; } processSingleShell(shell) { return new Promise((resolve, reject) => { const { code } = shelljs.exec(shell, { cwd: this.op.projectDir }); if (code !== 0) { resolve({ type: 'error', shell: shell }); } else { resolve({ type: 'success' }); } }); } addShells(shells) { this.shells = [...new Set(this.shells.concat(shells))]; } async runShells() { if (this.shells.length === 0) { return; } logger.pending('begin to run shells'); for (const shell of this.shells) { const res = await this.processSingleShell(shell); const type = res.type; if (type === 'error') { this.error.push(res); } else { this.success.push(res); } } // 输出日志 const errorLogs = this.error.map(it => { return it.shell; }); logger.success(`🙆‍♂️ success run ${this.success.length} shells.`); logger.error(`🙅 error run ${this.error.length} shells.`); errorLogs.length && logger.array(errorLogs, '❌ try exec yourself.'); } } export default ShellsManager;