commitool

1.0.0 • Public • Published

commit 信息规范工具

快速开始

到项目跟路径下,安装 npm 包(如果没有node环境,请提前安装node14以上的版本)

npm i -D commitool @commitlint/cli@15.0.0 @commitlint/config-conventional@15.0.0  commitizen@4.2.4  commitlint-config-cz@0.13.3

配置工具

修改项目根目录下的package.json,添加配置

  "config": {
    "commitizen": {
      "path": "./node-modules/commitool"
    }
  },

自定义规则

在项目根路径新建文件 .ctc.js,可自定义配置。 现有默认配置如下:

module.exports = {
  types: types || [
    {
      value: 'feat',
      name: '✨  feat: 新增功能'
    },
    {
      value: 'fix',
      name: '🐛 fix: bug修复'
    },
    {
      value: 'tests',
      name: '🚨 tests: 新增测试用例或是更新现有测试'
    },
    {
      value: 'refactor',
      name: '📦 refactor: 重构代码(既没有新增功能,也没有修复 bug)'
    },
    {
      value: 'style',
      name: '💎 style: 不影响程序逻辑的代码修改(修改空白字符,格式缩进,补全缺失的分号等,没有改变代码逻辑)'
    },
    {
      value: 'docs',
      name: '📚 docs: 文档更新'
    },
    {
      value: 'build',
      name: '🛠 build: 修改项目构建系统(例如 glup,webpack,rollup 的配置等)的提交'
    },
    {
      value: 'ci',
      name: '⚙️ ci: 修改项目继续集成流程(例如 Travis,Jenkins,GitLab CI,Circle等)的提交'
    },
    {
      value: 'merge',
      name: '🎏 merge: 分支合并 Merge branch'
    },
    {
      value: 'perf',
      name: '🚀 perf: 性能, 体验优化'
    },
    {
      value: 'revert',
      name: '⏪  revert: 回滚某个更早之前的提交'
    },
    {
      value: 'chore',
      name: '🦠 chore: 不属于以上类型的其他类型'
    },
  ],
  messages: {
    type: "type: 选择你本次提交的类型:",
    scope: 'scope: 表示此更改的范围(可选):', // 如果 allowCustomScopes 是true,会被使用
    customScope: 'scope: 表示此更改的范围:',
    subject: (max) => `subject: 为更改写一个简短的, 命令式的描述(最多 ${max} 个字):\n`,
    body: `body: 为更改提供一个长描述(可选). 可以使用 "|" 换行, \n必须包含--story=${getStoryId()} or --bug=tapdId or --other=其他信息\n`,
    breaking: 'breaking: 列出 BREAKING CHANGES (可选):\n',
    footer: 'footer: 列出此更改关闭的issue(可选),比如#31,#34',
    confirmCommit: '你确定要继续上面的提交吗?',
  },
  defaultValues: {
    body: `--story=${getStoryId()}`
  },
  validators: {
    body: (body, answers) => {
      const lintStoryid = /(--bug=\d{8,10}|--story=\d{8,10}|--other=|Merge)/.test(body);
      if (lintStoryid) {
        return true;
      } else {
        return 'body 中应该包含 --bug=tapdId or --story=tapdId or --other=其他信息 或 Merge关键字';
      }
    }
  }
}

types

用于配置类型的种类和名称,以及选择列表的提示。

   {
      value: 'build',  // 类型 key
      name: '🛠 build: 修改项目构建系统(例如 glup,webpack,rollup 的配置等)的提交'  // 选择提示信息
    }

messages

根据提示写提交信息,每一步需要写的内容的提示。

defaultValues

每一步默认提供的信息内容

validators

可以对每一步的输入内容做校验,如果不通过校验,无法继续提交。 目前仅支持 subject 和 body 的校验。

body: (body, answers) => {
  // body 提示内容
  // answers 输入内容
  
}

subject: (body, answers) => {
  // body 提示内容
  // answers 输入内容
}

其中,参数里, body 是提示的内容, answers 是输入的内容。

函数返回值分两种,

  1. 返回string类型,表明没有通过校验的提示信息
  2. 返回true,表示通过了校验

Readme

Keywords

none

Package Sidebar

Install

npm i commitool

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

132 kB

Total Files

8

Last publish

Collaborators

  • knightwu