配置Git提交时的规范检查,这里主要用到的几个工具有

全局配置

pnpm add commitizen cz-conventional-changelog -g
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc

注意, 全局模式下, 需要 ~/.czrc 配置文件, 为 commitizen 指定 Adapter.

自定义规则(全局)

pnpm add cz-customizable -g

修改 .czrc 或 package.json 中的 config 为:

{ "path": "cz-customizable" }

同时在~/ 或项目目录下创建 .cz-config.js 文件, 维护你想要的格式

'use strict';
 
module.exports = {
 
types: [
 
{
 
	value: 'WIP',
 
	name : '💪 WIP: Work in progress'
 
},
 
{
 
	value: 'feat',
 
	name : '✨ feat: A new feature'
 
},
 
{
 
	value: 'fix',
 
	name : '🐞 fix: A bug fix'
 
},
 
{
 
	value: 'refactor',
 
	name : '🛠 refactor: A code change that neither fixes a bug nor adds a feature'
 
},
 
{
 
	value: 'docs',
 
	name : '📚 docs: Documentation only changes'
 
},
 
{
 
	value: 'test',
 
	name : '🏁 test: Add missing tests or correcting existing tests'
 
},
 
{
 
	value: 'chore',
 
	name : '🗯 chore: Changes that don\'t modify src or test files. Such as updating build tasks, package manager'
 
},
 
{
 
	value: 'style',
 
	name : '💅 style: Code Style, Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)'
 
},
 
{
 
	value: 'revert',
 
	name : '⏪ revert: Revert to a commit'
 
}
 
],
 
scopes: [],
 
allowCustomScopes: true,
 
allowBreakingChanges: ["feat", "fix"]
 
};

项目配置

项目中安装 commitizencz-customizable 注意安装到 devDependencies 下,然后在 package.json 中添加配置

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

同时在项目根目录添加.cz-config.js, 配置内容与上面一样