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(preset-umi): add precommit generator #9784

Merged
merged 5 commits into from
Nov 17, 2022

Conversation

wyy0512
Copy link
Contributor

@wyy0512 wyy0512 commented Nov 16, 2022

添加微生成器-precommit


View rendered docs/docs/guides/generator.md

@vercel
Copy link

vercel bot commented Nov 16, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
umi ⬜️ Ignored (Inspect) Nov 17, 2022 at 5:37AM (UTC)

@codecov
Copy link

codecov bot commented Nov 16, 2022

Codecov Report

Base: 28.44% // Head: 28.37% // Decreases project coverage by -0.07% ⚠️

Coverage data is based on head (665dc64) compared to base (c7e06c1).
Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9784      +/-   ##
==========================================
- Coverage   28.44%   28.37%   -0.08%     
==========================================
  Files         428      429       +1     
  Lines       12073    12103      +30     
  Branches     2884     2890       +6     
==========================================
  Hits         3434     3434              
- Misses       8082     8108      +26     
- Partials      557      561       +4     
Impacted Files Coverage Δ
...es/preset-umi/src/commands/generators/precommit.ts 0.00% <0.00%> (ø)
packages/preset-umi/src/index.ts 0.00% <ø> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.


// 添加 .lintstagedrc
writeFileSync(
join(api.cwd, '.lintstagedrc'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

写文件的时候,判断一下有没有,有的话没必要覆写。

"prettier --cache --write"
],
"*.ts?(x)": [
"umi lint --fix --eslint-only",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是 Max 项目,这里应该是 max lint

}

writeFileSync(
join(api.cwd, '.husky/commit-msg'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要验证一下写出来的文件有没有执行权限,或者这里给他赋予一下,在 macos / linux ,人为写出来的 shell 文件可能没有执行权限。


```bash
$umi g precommit
info - @local
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一行可以不要


### Precommit 配置生成器

为项目生成 [precommit](https://typicode.github.io/husky) 配置,命令执行后,`umi` 会生成推荐的 precommit 配置和安装相应的依赖。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

描述个人认为太简单了,可以再详细一点描下做了什么事,主要是:

  1. 添加 husky 和 Git commit message 格式校验行为

  2. 在每次 Git commit 前会将 Git 暂存区的代码默认格式化

注:如果是初始化出来的 max 项目,通常不需要该生成器,因为已经配置好 husky

@@ -90,6 +90,11 @@
"url": "https://umijs.org/docs/guides/generator#prettier-%E9%85%8D%E7%BD%AE%E7%94%9F%E6%88%90%E5%99%A8",
"majorVersion": 4
},
{
"text": "如果你需要使用 Precommit, %%frameworkCliName%% g precommit 就可以一键完成配置",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

个人认为描述再精确一点:

如果你要增加 Git 提交消息校验和自动代码格式化,可以......

会更好

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢大佬的 CR ,已修改

@sorrycc sorrycc merged commit 470dd5e into umijs:master Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants