前言:

咱们前端团队就几个人(部署还是走的自动化构建的),以前提交代码呢,就是 git add ., git commit -m ,git push origin 'name'.一套打完间接下机走人。 直到有一天测试环境代码跑不动,查看构建信息才发现有位小伙伴提交代码的时候并没合并就提交下来了(我也示意神奇)

为了避免这样的事件再次发生呢,就去网上扒拉了一些git提交工具文章,筹备应用commitizencz-conventional-changelogcz-customizable这三个工具整合到我的项目中。

1、首先装置插件

yarn add commitizen -D cz-conventional-changelog -D cz-customizable -D

2、配置package(在根目录package.json外面增加)

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

3、配置标准(应用Angular提交的标准)

在根目录创立.cz-config.js
//.cz-config.jsmodule.exports = {  types: [    {      value: "init",      name: "✨  init:     我的项目初始化",    },    {      value: "feat",      name: "✨  feat:     新增性能",    },    {      value: "fix",      name: "✨  fix:      bug修复",    },    {      value: "refactor",      name: "✨  refactor: 代码重构(不包含 bug 修复、性能新增)",    },    {      value: "docs",      name: "✨  docs:     文档更新",    },    {      value: "test",      name: "✨  test:     增加、批改测试用例",    },    {      value: "chore",      name: "✨  chore:    对构建过程或辅助工具和库的更改(不影响源文件、测试用例)",    },    {      value: "style",      name: "✨  style:    代码格局(不影响性能,例如空格、分号等格局修改)",    },  ],  scopes: [    ["pages", "页面相干"],    ["api", "接口相干"],    ["utils", "公共办法相干"],    ["components", "组件相干"],    ["hooks", "hook 相干"],    ["ui", "对ui 的调整"],    ["styles", "款式相干"],    ["plugins", "plugins批改"],    ["store", "store批改"],    ["deps", "我的项目依赖"],    ["auth", "对 auth 批改"],    ["README", "README批改"],    ["other", "其余批改"],    ["custom", "以上都不是?我要自定义"],  ].map(([value, description]) => {    return {      value,      name: `${value.padEnd(30)} (${description})`,    };  }),  messages: {    type: "确保本次提交遵循标准!\n抉择你要提交的类型:",    customScope: "请输出自定义的 scope:",    subject: "填写本次提交形容* ( 一句话概括 ):\n",    body: '填写更加具体的变更形容 ( 不填能够间接回车,话多应用 "|" 换行 ):\n',    breaking:      '列举非兼容性重大的变更 ( 不填能够间接回车,话多应用 "|" 换行 ):\n',    footer:      '列举出所有变更的 ISSUES CLOSED 例如: #31, #34 ( 不填能够间接回车,话多应用 "|" 换行 ):\n',    confirmCommit:      '确认提交?( 这步完了 须要在控制台输出 "git push origin <你须要提交近程分支名>" )',  },  allowCustomScopes: true,  allowBreakingChanges: ["feat", "fix"],};

最初在package.json外面增加执行脚本命令

"commit": "git add . && git-cz"

如果你还想在提交代码前检测一下代码(vue)

"commit": "vue-cli-service lint --fix --ext .js,.vue,.ts && git add . && git-cz"

最初间接输出命令: yarn commit

看到下图就证实胜利了