From ebb66f8880fcbbd748facc9554763a503639214d Mon Sep 17 00:00:00 2001 From: biaov Date: Wed, 11 Oct 2023 18:11:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commander/actions.ts | 42 +++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/commander/actions.ts b/src/commander/actions.ts index 3e55cdf..7f23ce6 100644 --- a/src/commander/actions.ts +++ b/src/commander/actions.ts @@ -15,6 +15,18 @@ import { gitCmds, buildCmds } from './cmds' const { iconError, iconSuccess, success, info, error, warning } = log +/** + * 执行命令 + */ +const execCommand = (cmd: string) => { + info(`开始执行 ${chalk.cyanBright(cmd)} 命令`) + const spinner = ora({ text: '正在执行命令中...', color: 'yellow' }) + spinner.start() + execSync(cmd, { cwd: process.cwd() }) + spinner.succeed(`${chalk.green(cmd)} 命令执行成功`) + info() +} + /** * 简化 git 提交命令 */ @@ -22,17 +34,7 @@ export const simplifyGit = async (desc = '更新代码') => { info() info(`${chalk.yellow('>>')} 开始依次执行命令...`) info() - /** - * 执行命令 - */ - gitCmds(desc).forEach(cmd => { - info(`开始执行 ${chalk.cyanBright(cmd)} 命令`) - const spinner = ora({ text: '正在执行命令中...', color: 'yellow' }) - spinner.start() - execSync(cmd, { cwd: process.cwd() }) - spinner.succeed(`${chalk.green(cmd)} 命令执行成功`) - info() - }) + gitCmds(desc).forEach(execCommand) success('全部命令执行完成') info() } @@ -44,19 +46,7 @@ export const simplifyBuild = async (cmd: string, desc = '打包') => { info() info(`${chalk.yellow('>>')} 开始依次执行命令...`) info() - - /** - * 执行命令 - */ - buildCmds(cmd, desc).map(cmd => { - info(`开始执行 ${chalk.cyanBright(cmd)} 命令`) - const spinner = ora({ text: '正在执行命令中...', color: 'yellow' }) - spinner.start() - execSync(cmd, { cwd: process.cwd() }) - spinner.succeed(`${chalk.green(cmd)} 命令执行成功`) - info() - }) - + buildCmds(cmd, desc).map(execCommand) success('全部命令执行完成') info() } @@ -65,7 +55,11 @@ export const simplifyBuild = async (cmd: string, desc = '打包') => { * 定义顶级命令的 action */ export const handleArguments = (cmd: string, env?: string) => { + /** + * 处理 build[:环境] 命令 + */ if (cmd.includes('build')) return simplifyBuild(cmd, env) + /** * 输出错误 */