vue,react,angular都在用的commit规范,了解一下?

截图来自vue的PR:

1.commit-message规范必要性

  1. 统一格式的提交记录,更清晰和易读

  2. 可以通过提交记录来了解本次提交的目的,更好的CR和重构

  3. 更容易了解变更,定位和发现问题

  4. 每个提交描述都是经过思考的,改善提交质量

  5. 直接生成ChangeLog

2.规范选型

常见的commit message规范有:atom,eslint和Angular等,其中Angular规范更为通用。

3.Angular的Commit Message规范简介

每条提交记录包含三个部分:header,body和footer

<header> <BLANK LINE> <body> <BLANK LINE> <footer>

Commit Message Header

<type>(<scope>): <short summary>
  │       │             │
  │       │             └─⫸ Summary in present tense. Not capitalized. No period at the end.
  │       │
  │       └─⫸ Commit Scope: animations|bazel|benchpress|common|compiler|compiler-cli|core|
  │                          elements|forms|http|language-service|localize|platform-browser|
  │                          platform-browser-dynamic|platform-server|router|service-worker|
  │                          upgrade|zone.js|packaging|changelog|dev-infra|docs-infra|migrations|
  │                          ngcc|ve
  │
  └─⫸ Commit Type: build|ci|docs|feat|fix|perf|refactor|test

其中type和summary是必要的,scope是可选的

Type 必须是以下的类型

  • feat: 新增页面或功能

  • fix: bug修复

  • build: 影响构建系统或外部依赖项的更改

  • ci: 对 CI 配置文件和脚本的更改

  • docs: 文档改动

  • perf: 性能提升改动

  • refactor: 不影响功能的代码重构(既不修复错误也不添加功能)

  • test: 添加或修改测试用例

Summary用来提供更改的简洁描述

4.规范实施

通过commitizen进行交互式提交,husky + commit-msg hook进行提交校验,cz-customizable来自定义交互提交流程和文案,standard-changelog来自动生成changelog

image-20210615173113038

1.使用commitizen工具,在commit时可以交互的方式选择type

安装commitizen

npm i -D commitizen

package.json中添加对应的npm script

"commit":"cz"

改动添加到暂存区后执行commit提交

npm run commit

2. 通过husky在git hooks中对不符合规范的提交进行拦截,拦截commitlint进行校验

安装husky , commitlint 和 符合angular提交规范的配置

npm i -D husky commitlint @commitlint/config-conventional

添加git hooks

npx husky install

package.json中添加prepare的npm hook, 在每次install自动执行(yarn v2+不支持prepare)

"prepare": "husky install"

执行添加commit-msg hook

如果使用husk v4.x版本(推荐升级到新版本),直接在package.json中或.huskyrc.json中新增commit-msg钩子即可

package.json

"husky": {     "hooks": {        "commit-msg": "commitlint --edit $1"      }  }

.huskyrc.huskyrc.json.huskyrc.jshusky.config.js

"hooks": {   "commit-msg": "commitlint --edit $1" }

如果使用husky v6+版本,需要添加对应的shell调用方式(husky v6对添加方式做了改动,所以无法通过添加配置到package.json中运行)

npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1'

添加commintlint配置(也可以放到package.json中指定)

echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js

package.json中添加commitlint配置

"commitlint": {      "extends": [         "@commitlint/config-conventional"      ]}

3. 扩展和自定义规范

commitizen提供的交互式默认是英文的,如果改成中文或者对交互流程进行改动,可以使用cz-customizable进行扩展和自定义

安装cz-customizable

npm i -D cz-customizable

package.json中添加配置

"config": {     "commitizen": {        "path": "node_modules/cz-customizable"     },     "cz-customizable": {        "config": ".cz-config.js"     } } 

.cz-config.js就是cz-customizable配置的具体文件了,可以参考CZ-Config-Example并进行改动, 可以把文案翻译成中文,自定义修改提示等。

也可以通过fork cz-customizable创建内封配置文件的npm包

npm i -D your-own-package

"config": {      "commitizen": {          "path": "node_modules/your-own-package"      } }

配置文件可以自定义交互内容,比如可以只保留type scope breakchange confirm

  • 选择提交类型

  • 简单描述本次改动

  • 是否有重大变更

  • 确定提交

配置文件中设置skipQuestions: [‘body’,‘customScope’,‘scope’,‘footer’],即可忽略其他选项

allowBreakingChanges: [‘feat’, ‘fix’], 仅在feat和fix时提示 breakchange

4.自动生成changelog

可以使用standard-changelog来自动生成changelog

npm i -D standard-changelog

配置npm script

"gen-changelog": "standard-changelog"

5.其他

通过npm script进行commit,如果eslint没有通过(在pre-commit 钩子中做了eslint检测),但是又想提交可以通过加’––'来向npm script传参

npm run commit -- --no-verify # or npm run commit -- -n

chaos-fe

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue, React, and Angular are all popular JavaScript frameworks used for building web applications. Vue is a relatively lightweight framework that is known for its simplicity and ease of use. It is often favored by developers who are new to JavaScript frameworks or who prefer a more minimalist approach to development. Vue also has a strong focus on performance and can be used for building both small and large-scale applications. React is developed and maintained by Facebook and is widely used for building complex user interfaces. It uses a virtual DOM and a one-way data flow model which enables it to efficiently manage state and handle large amounts of data. React can be used with other libraries and frameworks, making it highly flexible and customizable. Angular is a full-featured framework developed by Google. It is known for its powerful features and its ability to handle large and complex applications. Angular uses a two-way data binding approach and has a steep learning curve compared to Vue and React. However, it offers a wide range of features, including dependency injection, routing, and animations, making it a popular choice for enterprise-level applications. Ultimately, the choice between Vue, React, and Angular will depend on the specific needs and preferences of the developer or development team. Each framework has its own strengths and weaknesses, and the decision should be based on the project requirements, available resources, and the experience level of the developers involved.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一颗小行星!

恰饭ing

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值