cz-customizable 规范代码提交信息

参考文章
 

安装依赖

        cz-customizable 安装

 yarn add cz-customizable --save-dev

        commitizen 安装

 yarn add commitizen --save-dev

package.json 文件配置

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

配置文件

  新增配置文件,放在 src目录同级 (根目录下创建)

        .cz-config.js

module.exports = {
  types: [
    {
      value: 'feat',
      name: '✨  feat:      新功能'
    },
    {
      value: 'fix',
      name: '🐛  fix:       Bug修复'
    },
    {
      value: 'docs',
      name: '📝  docs:      文档新增/变更'
    },
    {
      value: 'style',
      name: '🎨  style:     代码风格调整'
    },
    {
      value: 'refactor',
      name: '🔨  refactor:  代码重构'
    },
    {
      value: 'perf',
      name: '⚡️  perf:      性能提升'
    },
    {
      value: 'test',
      name: '🧪  test:      测试用例添加/更正'
    },
    {
      value: 'revert',
      name: '⏪  revert:    代码回滚'
    },
    {
      value: 'build',
      name: '📦  build:     构建编译过程变更'
    },
    {
      value: 'chore',
      name: '🚀  chore:     日常任务维护'
    },
    {
      value: 'ci',
      name: '👷  ci:        自动化集成流程'
    }
  ],

  usePreparedCommit: false, // to re-use commit from ./.git/COMMIT_EDITMSG
  allowTicketNumber: false,
  isTicketNumberRequired: false,
  ticketNumberPrefix: 'TICKET-',
  ticketNumberRegExp: '\\d{1,5}',

  // 覆盖消息,默认如下
  messages: {
    type: '请选择提交类型 (必填)',
    scope: '请选择文件修改范围 (可选)',

    // 如果allowCustomScopes为true则使用 (官方存在bug, 暂未修复)
    customScope: '请输入文件修改范围 (可选)',
    subject: '请简要描述提交 (必填)',
    body: '请输入详细描述 (可选)',
    breaking: '列出任何重大变更 (可选)',
    footer: '请输入要关闭的issue (可选)',
    confirmCommit: '确定提交此说明吗?'
  },

  allowCustomScopes: true,
  allowBreakingChanges: ['feat', 'fix'],
  skipQuestions: ['scope', 'body', 'footer'], // 跳过您想要的任何问题
  subjectLimit: 72 // 限制主题长度
}

         .commitlintrc.js

const typeEnum = require('./.cz-config')
console.log(
  '\x1B[0;37;44m INFO \x1B[0m',
  '\x1B[0;;34m ' +
    `读取了: ${__filename.slice(__dirname.length + 1)}` +
    ' \x1B[0m'
)

module.exports = {
  extends: ['@commitlint/config-conventional'],
  // https://github.com/conventional-changelog/commitlint/blob/master/docs/reference-rules.md
  rules: {
    'type-enum': [2, 'always', typeEnum.types.map((i) => i.value)],
    'scope-empty': [0, 'never']
  }
}

        

 使用

git add .

npm run commit

...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值