代码洁癖中commitizen
前一篇文章有说为了防止开发者乱写git commit的说明,我们用到了commitlint(代码洁癖之commitlint)
但这样下来导致了一个严重的问题,开发者每次都按照这种规范来写的话费时又费力,为了解决这个问题,就要用到commitizen帮助我们自动生成git commit的说明
1.全局安装commitizen
npm i -g commitizen
2.在项目中安装commitizen
npm i commitizen -S
3.修改packge.json,添加如下代码
...
"config": {
"commitizen": {
"path": "node_modules/cz-customizable"
}
}
4.创建.cz-config.js,制定规范
module.exports = {
// 可选类型
types: [
{ value: 'feat', name: 'feat: 新功能' },
{ value: 'fix', name: 'fix: 修复' },
{ value: 'docs', name: 'docs: 文档变更' },
{ value: 'style', name: 'style: 代码格式(不影响代码运行的变动)' },
{ value: 'refactor', name: 'refactor: 重构(既不是增加feature,也不是修复bug)' },
{ value: 'perf', name: 'perf: 性能优化' },
{ value: 'test', name: 'test: 增加测试' },
{ value: 'chore', name: 'chore: 构建过程或辅助工具的变动' },
{ value: 'revert', name: 'revert: 回退' },
{ value: 'build', name: 'build: 打包' },
],
// 步骤
messages: {
type: '请选择提交的类型',
customScope: '请输入修改的范围(可选)',
subject: '请简要描述提交(必填)',
body: '请输入详细描述(可选)',
footer: '请输入要关闭的issue(可选)',
confirmCommit: '确认要使用以上信息提交?(y/n)',
},
// 跳过步骤
skipQuestions: ['body', 'footer'],
// 默认长度为72
subjectLimit: 72,
};
5.至此commitizen的配置已经完成,从此提交代码需要执行git cz
- git add .
- git cz
- 按照提示选择或输入相应描述即可自动生成commit说明并提交
后记
有关约定式提交的规范可参考链接约定式提交