From 8ab7ed702a25c0b3fdb1ff1f038c6ec373d70df6 Mon Sep 17 00:00:00 2001 From: "yuyuehui.yyh" Date: Tue, 7 Feb 2023 12:55:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(plugins):=20=E6=96=B0=E5=A2=9Econfetti?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/plugins/src/confetti.ts | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 packages/plugins/src/confetti.ts diff --git a/packages/plugins/src/confetti.ts b/packages/plugins/src/confetti.ts new file mode 100644 index 000000000000..deb208e95045 --- /dev/null +++ b/packages/plugins/src/confetti.ts @@ -0,0 +1,53 @@ +import { IApi } from 'umi'; +import { crossSpawn, logger } from 'umi/plugin-utils'; + +// 运行 confetti 的代码 +const handleConfetti = () => { + // 问题: 运行时如果 raycast 是退出状态, 会自动打开 raycast 并在 mac 上显示。 + const confettiShell = ` + open raycast://confetti; + exit; + `; + + const confetti = crossSpawn(confettiShell, [], { + stdio: 'pipe', + shell: true, + }); + + confetti.on('error', (err) => { + const errStr = '[confetti] ' + err; + logger.error(errStr); + }); + + confetti.stderr && + confetti.stderr.on('data', () => { + // 只有一行 shell ,报错可认为是 Raycast 没有正确访问 + const err = `[confetti] 未安装 Raycast , 请安装后尝试 https://www.raycast.com`; + logger.error(err); + }); +}; + +export default (api: IApi) => { + api.describe({ + key: 'confetti', + config: { + schema(joi) { + return joi.object(); + }, + }, + enableBy: api.EnableBy.config, + }); + + api.onBuildComplete(({ err }) => { + if (!err) { + handleConfetti(); + } + }); + + api.onDevCompileDone(({ isFirstCompile }) => { + if (isFirstCompile) { + // 首次构建运行 + handleConfetti(); + } + }); +};