开箱即用的代码提交规范

开篇

在团队中代码提交(git commit)会有各类各样的风格,甚至有些人根本没有 commit 规范的概念,因此在咱们回头去查找在哪一个版本出现问题的时候,就会很是尴尬😅,很难快速定位到问题。为了项目的规范化,代码提交规范就显得尤其重要!下面是我作的代码提交规范插件 vue-cli-plugin-commitlint(对 conventional-changelog-angular 进行了修改/封装)。开箱即用!前端

vue-cli-plugin-commitlint 介绍

vue-cli-plugin-commitlint 是根据 vue 插件的形式写的,能够执行 vue add commitlint 直接使用,若是不是 vue 的项目也能够根据下面的配置自行配置。vue

结合 commitizen commitlint conventional-changelog-cli husky conventional-changelog-angular,进行封装,一键安装,开箱即用的代码提交规范。node

功能

  1. 自动检测 commit 是否规范,不规范不容许提交
  2. 自动提示 commit 填写格式。不怕忘记规范怎么写
  3. 集成 git add . && git commit 不须要在执行两个命令
  4. 自动生成 changelog

配置

  1. 若是您是 vue-cli3 的项目能够直接使用便可
vue add commitlint
复制代码
  1. 若是您不是 vue-cli3 的项目
npm i vue-cli-plugin-commitlint commitizen commitlint conventional-changelog-cli husky -D
复制代码
  • 在 package.json 中添加
{
  "scripts": {
    "log": "conventional-changelog --config ./node_modules/vue-cli-plugin-commitlint/lib/log -i CHANGELOG.md -s -r 0",
    "cz": "npm run log && git add . && git cz"
  },
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/vue-cli-plugin-commitlint/lib/cz"
    }
  }
}
复制代码

增长 commitlint.config.js 文件git

module.exports = {
  extends: ['./node_modules/vue-cli-plugin-commitlint/lib/lint']
};
复制代码

使用

npm run cz  # git add . && git commit -m 'feat:(xxx): xxx'
npm run log # 生成 CHANGELOG
复制代码
  1. 代码提交 npm run cz

  1. 选择一个类型会自动询问github

    1. (非必填)本次提交的改变所影响的范围
    2. (必填)写一个简短的变化描述
    3. (非必填)提供更详细的变动描述
    4. (非必填)是否存在不兼容变动?
    5. (非必填)这次变动是否影响某些打开的 issue

changelog 演示

规则

规范名 描述
docs 仅仅修改了文档,好比 README, CHANGELOG, CONTRIBUTE 等等
chore 改变构建流程、或者增长依赖库、工具等
feat 新增 feature
fix 修复 bug
merge 合并分支
perf 优化相关,好比提高性能、体验
refactor 代码重构,没有加新功能或者修复 bug
revert 回滚到上一个版本
style 仅仅修改了空格、格式缩进、都好等等,不改变代码逻辑
test 测试用例,包括单元测试、集成测试等

总结

目前我有好几个项目都在使用这套规范,用起来简直不要太爽!vue-cli

项目地址:github.com/luoxue-vict…npm

欢迎来 pr、starjson

最后有两件小事

  1. 有想入群的学习前端进阶的加我微信 luoxue2479 回复加群便可
  2. 有写错的地方和更好的建议能够在下面 留言,一块儿讨论
相关文章
相关标签/搜索