Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins): 新增confetti插件。 #10441

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions packages/plugins/src/confetti.ts
Original file line number Diff line number Diff line change
@@ -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();
}
});
};