配置 git 提交时对代码进行校验
满足以上要求,代码才能正常提交到 git
生成符合 Angular 规范的 git 提交信息,校验 git 的提交信息是否符合 Angular 规范
SoybeanJS 的命令行工具
pnpm i -D @soybeanjs/cli
此处主要使用 git-commit git-commit-verify
更多使用方式参考 https://github.com/soybeanjs/cli/blob/main/README.md
安装 lint-staged:
pnpm i lint-staged -D
在 package.json 中添加:
{
"lint-staged": {
"*": "eslint --fix"
}
}
安装 simple-git-hooks:
pnpm i simple-git-hooks -D
在 package.json 中添加git钩子:
{
"simple-git-hooks": {
"commit-msg": "pnpm soy git-commit-verify",
"pre-commit": "pnpm typecheck && pnpm lint-staged"
}
}
在 package.json 中添加脚本:
{
"scripts": {
// vue
"typecheck": "vue-tsc --noEmit --skipLibCheck",
// Nuxt
"typecheck": "nuxi typecheck",
"commit": "soy git-commit",
"commit:zh": "soy git-commit -l=zh-cn",
"prepare": "simple-git-hooks"
}
}
tip 提示 变更
simple-git-hooks配置或取消simple-git-hooks时,先更改package.json中的simple-git-hooks对应的配置,然后运行pnpm run prepare使其生效。