{"id":24772336,"url":"https://github.com/ziyi2/cz-example","last_synced_at":"2025-07-30T00:34:18.033Z","repository":{"id":98890125,"uuid":"183766918","full_name":"ziyi2/cz-example","owner":"ziyi2","description":"cz工具集示例","archived":false,"fork":false,"pushed_at":"2019-04-27T13:45:45.000Z","size":9117,"stargazers_count":27,"open_issues_count":0,"forks_count":13,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T22:33:21.690Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ziyi2.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-04-27T11:57:08.000Z","updated_at":"2022-09-08T09:08:45.000Z","dependencies_parsed_at":"2023-03-07T19:45:18.847Z","dependency_job_id":null,"html_url":"https://github.com/ziyi2/cz-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ziyi2/cz-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziyi2%2Fcz-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziyi2%2Fcz-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziyi2%2Fcz-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziyi2%2Fcz-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ziyi2","download_url":"https://codeload.github.com/ziyi2/cz-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziyi2%2Fcz-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267785848,"owners_count":24144122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-29T04:01:42.243Z","updated_at":"2025-07-30T00:34:18.025Z","avatar_url":"https://github.com/ziyi2.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cz-example\n\ncz工具集示例，包含以下工具类型：\n\n- 适配器：用于配置cz的提交说明\n- 校验：校验提交说明是否符合规范\n- 日志：根据提交说明的类型快速生成日志\n\n## Commitizen\n\n全局安装cz\n\n``` javascript\nnpm install -g commitizen\n```\n\n## 适配器\n\n### cz-conventional-changelog\n\n如果想使用符合Angular规范提交说明的cz适配器\n\n``` javascript\ncommitizen init cz-conventional-changelog --save --save-exact\n```\n\n\u003e 该命令执行`cz-conventional-changelog`依赖安装和在`pacakge.json`中配置`config.commitizen`适配器路径。\n\n执行提交说明命令`git cz`:\n\n![enter image description here](https://raw.githubusercontent.com/ziyi2/cz-example/master/images/cz_1.png)\n\n代码提交后，查看远程提交说明信息：\n\n![enter image description here](https://raw.githubusercontent.com/ziyi2/cz-example/master/images/cz_2.png)\n\n\n### cz-customizable\n\n如果想定制说明，可以使用该cz适配器\n\n``` javascript\nnpm install cz-customizable --save-dev\n```\n\n该适配器需要手动配置cz的适配器路径，在`pacakge.json`中\n\n``` javascript\n\"config\": {\n  \"commitizen\": {\n    \"path\": \"node_modules/cz-customizable\"\n  }\n}\n```\n\n新增`.cz-config`定制说明的配置文件（以下是一个汉化示例）：\n\n``` javascript\n'use strict';\n\nmodule.exports = {\n\n  types: [\n    {value: '特性',     name: '特性:    一个新的特性'},\n    {value: '修复',      name: '修复:    修复一个Bug'},\n    {value: '文档',     name: '文档:    变更的只有文档'},\n    {value: '格式',    name: '格式:    空格, 分号等格式修复'},\n    {value: '重构', name: '重构:    代码重构，注意和特性、修复区分开'},\n    {value: '性能',     name: '性能:    提升性能'},\n    {value: '测试',     name: '测试:    添加一个测试'},\n    {value: '工具',    name: '工具:    开发工具变动(构建、脚手架工具等)'},\n    {value: '回滚',   name: '回滚:    代码回退'}\n  ],\n\n  scopes: [\n    {name: '模块1'},\n    {name: '模块2'},\n    {name: '模块3'},\n    {name: '模块4'}\n  ],\n\n  // it needs to match the value for field type. Eg.: 'fix'\n  /*\n  scopeOverrides: {\n    fix: [\n      {name: 'merge'},\n      {name: 'style'},\n      {name: 'e2eTest'},\n      {name: 'unitTest'}\n    ]\n  },\n  */\n  // override the messages, defaults are as follows\n  messages: {\n    type: '选择一种你的提交类型:',\n    scope: '选择一个scope (可选):',\n    // used if allowCustomScopes is true\n    customScope: 'Denote the SCOPE of this change:',\n    subject: '短说明:\\n',\n    body: '长说明，使用\"|\"换行(可选)：\\n',\n    breaking: '非兼容性说明 (可选):\\n',\n    footer: '关联关闭的issue，例如：#31, #34(可选):\\n',\n    confirmCommit: '确定提交说明?'\n  },\n\n  allowCustomScopes: true,\n  allowBreakingChanges: ['特性', '修复'],\n\n  // limit subject length\n  subjectLimit: 100\n\n};\n```\n\n执行提交说明命令`git cz`:\n\n![enter image description here](https://raw.githubusercontent.com/ziyi2/cz-example/master/images/cz_3.png)\n\n![enter image description here](https://raw.githubusercontent.com/ziyi2/cz-example/master/images/cz_4.png)\n\n\n查看远程提交说明：\n\n![enter image description here](https://raw.githubusercontent.com/ziyi2/cz-example/master/images/cz_5.png)\n\n## 校验\n\n### commitlint\n\n校验提交说明是否符合规范\n\n安装校验工具\n\n``` javascript\nnpm install --save-dev @commitlint/cli\n```\n\n#### @commitlint/config-conventional\n\n安装符合Angular风格的校验规则\n\n``` javascript\nnpm install --save-dev @commitlint/config-conventional \n```\n\n新建`commitlint.config.js`文件并设置校验规则：\n\n``` javascript\nmodule.exports = {\n  extends: ['@commitlint/config-conventional']\n};\n```\n\n安装huksy（git钩子工具）\n\n``` javascript\nnpm install husky --save-dev\n```\n\n在package.json中配置`git commit`提交时的校验钩子：\n\n``` javascript\n\"husky\": {\n  \"hooks\": {\n    \"commit-msg\": \"commitlint -E HUSKY_GIT_PARAMS\"\n  }  \n}\n```\n\n需要注意，使用该校验规则不能对`.cz-config.js`进行不符合Angular规范的定制处理，例如之前的汉化，此时需要将`.cz-config.js`的文件按照官方示例文件[cz-config-EXAMPLE.js](https://github.com/leonardoanalista/cz-customizable/blob/master/cz-config-EXAMPLE.js)进行符合Angular风格的改动：\n\n``` javascript\n'use strict';\n\nmodule.exports = {\n\n  types: [\n    {value: 'feat',     name: 'feat:     A new feature'},\n    {value: 'fix',      name: 'fix:      A bug fix'},\n    {value: 'docs',     name: 'docs:     Documentation only changes'},\n    {value: 'style',    name: 'style:    Changes that do not affect the meaning of the code\\n            (white-space, formatting, missing semi-colons, etc)'},\n    {value: 'refactor', name: 'refactor: A code change that neither fixes a bug nor adds a feature'},\n    {value: 'perf',     name: 'perf:     A code change that improves performance'},\n    {value: 'test',     name: 'test:     Adding missing tests'},\n    {value: 'chore',    name: 'chore:    Changes to the build process or auxiliary tools\\n            and libraries such as documentation generation'},\n    {value: 'revert',   name: 'revert:   Revert to a commit'},\n    {value: 'WIP',      name: 'WIP:      Work in progress'}\n  ],\n\n  scopes: [\n    {name: 'accounts'},\n    {name: 'admin'},\n    {name: 'exampleScope'},\n    {name: 'changeMe'}\n  ],\n\n  // it needs to match the value for field type. Eg.: 'fix'\n  /*\n  scopeOverrides: {\n    fix: [\n      {name: 'merge'},\n      {name: 'style'},\n      {name: 'e2eTest'},\n      {name: 'unitTest'}\n    ]\n  },\n  */\n  // override the messages, defaults are as follows\n  messages: {\n    type: 'Select the type of change that you\\'re committing:',\n    scope: '\\nDenote the SCOPE of this change (optional):',\n    // used if allowCustomScopes is true\n    customScope: 'Denote the SCOPE of this change:',\n    subject: 'Write a SHORT, IMPERATIVE tense description of the change:\\n',\n    body: 'Provide a LONGER description of the change (optional). Use \"|\" to break new line:\\n',\n    breaking: 'List any BREAKING CHANGES (optional):\\n',\n    footer: 'List any ISSUES CLOSED by this change (optional). E.g.: #31, #34:\\n',\n    confirmCommit: 'Are you sure you want to proceed with the commit above?'\n  },\n\n  allowCustomScopes: true,\n  allowBreakingChanges: ['feat', 'fix'],\n\n  // limit subject length\n  subjectLimit: 100\n  \n};\n```\n\n\n执行错误的提交说明：\n\n![enter image description here](https://raw.githubusercontent.com/ziyi2/cz-example/master/images/cz_6.png)\n\n\n执行符合Angular规范的提交说明：\n\n![enter image description here](https://raw.githubusercontent.com/ziyi2/cz-example/master/images/cz_7.png)\n\n\n### validate-commit-msg\n\n也可以使用工具对cz提交说明进行校验，具体可查看[validate-commit-msg](https://github.com/Frikki/validate-commit-message)。\n\n### commitlint-config-cz\n\n如果是使用cz-customizable适配器做了破坏Angular风格的提交说明配置，那么不能使用@commitlint/config-conventional进行提交说明校验，可以使用[commitlint-config-cz](https://github.com/whizark/commitlint-config-cz)对定制化提交说明进行校验。\n\n## 日志\n\n安装生成日志工具\n\n``` javascript\nnpm install conventional-changelog-cli -D\n```\n\n配置生成日志的命令\n\n``` javascript\n\"version\": \"conventional-changelog -p angular -i CHANGELOG.md -s -r 0 \u0026\u0026 git add CHANGELOG.md\"\n```\n\n执行`npm run version`后可查看生产的日志[CHANGELOG.md](https://github.com/ziyi2/cz-example/blob/master/CHANGELOG.md)。\n\n\n\u003e 注意要使用正确的`Header`的`type`，否则生成的日志会不准确，这里只是一个示例，生成的日志不是很严格。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziyi2%2Fcz-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fziyi2%2Fcz-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziyi2%2Fcz-example/lists"}