前端配置git提交规范

18 阅读1分钟

juejin.cn/post/684490…

1、安装依赖

安装依赖
全局安装 npm i -g commitizen cz-customizable (需要sudo权限)
本地安装 npm i -D husky @commitlint/config-conventional @commitlint/cli

2、package添加配置:


  "config": {
      "commitizen": {
          "path": "cz-customizable"
      }
  },
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
      "pre-commit": "lint-staged && node ./precommit"
    }
  },
  "lint-staged": {
    "src/**/*.{js,jsx,ts,tsx}": "npm run lint"
  }

3、.cz-config.js文件

module.exports = {
  types: [
    {
      value: "feat",
      name: "feat:   添加新功能",
    },
    {
      value: "fix",
      name: "fix:   修复Bug",
    },
    {
      value: "chore",
      name:
        "chore:   不修改src或者test的其余修改,例如构建过程或辅助工具的变动",
    },
    {
      value: "perf",
      name: "perf:   性能优化",
    },
    {
      value: "refactor",
      name: "refactor:   代码重构",
    },
  ],
  messages: {
    type: "选择要提交的更改类型:",
    scope: "填写需求名称:",
    customScope: "选择更改影响的范围:",
    subject: "写一个简短、命令时态的语句来描述更改:\n",
    body: '详细描述更改原因 (可选,按回车跳过). 使用 "|" 来换行:\n',
    breaking: "列出 BREAKING CHANGES (可选,按回车跳过):\n",
    footer: "列出这次更改关闭的 ISSUES (可选,按回车跳过). 如: #31, #34:\n",
    confirmCommit: "确定提交上面的更改?",
  },
  skipQuestions: ["customScope", "footer"],
  footerPrefix: "close",
};

3、