运用commitlint范例git提交

在我们最先一个项目的时刻一般会用eslint去范例js代码。我们还能够用一些命令行东西去范例我们的git提交信息以及在每次git操纵过程当中实行一些测试,最快能够根据git提交信息天生CHANGELOG文件

commitlint: git 提交信息范例与考证
husky: 使ghook更轻易
standard-version: 自动天生CHANGELOG 并宣布版本

装置

npm install --save-dev @commitlint/{config-conventional,cli}
npm i --save-dev standard-version
npm install husky --save-dev

设置

commitlint
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
// commitlint.config.js
 module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
  'type-enum': [2, 'always', [
     "feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"
   ]],
  'scope-empty': [2, 'never'],
  'subject-full-stop': [0, 'never'], 
  'subject-case': [0, 'never']
  }}; 

Standard-version 和 husky

// package.json
 "scripts": {
  "lint": "eslint .",
  "commitmsg": "commitlint -e $GIT_PARAMS",
  "release": "standard-version",
  "validate": "npm prune",
  "pre-commit": "npm run lint",
  "pre-push": "npm run validate",
  "npmi": "npm i",
  "post-merge": "npm run npmi",
  "post-rewrite": "npm run npmi"
 }

运用

详细参考响应官网
    原文作者:Neil
    原文地址: https://segmentfault.com/a/1190000015691105
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞