cz-customizable 项目使用教程
cz-customizable项目地址:https://gitcode.com/gh_mirrors/czc/cz-customizable
1. 项目的目录结构及介绍
cz-customizable 项目的目录结构如下:
cz-customizable/
├── LICENSE
├── README.md
├── index.js
├── package.json
├── cz-config-EXAMPLE.js
└── test/
├── cz-config-test.js
└── index.test.js
- LICENSE: 项目的许可证文件。
- README.md: 项目的主要说明文档。
- index.js: 项目的主入口文件。
- package.json: 项目的依赖和配置文件。
- cz-config-EXAMPLE.js: 自定义提交信息的配置示例文件。
- test/: 项目的测试目录,包含测试文件。
2. 项目的启动文件介绍
项目的启动文件是 index.js
,它主要负责加载和应用自定义的提交信息配置。以下是 index.js
的主要内容:
const path = require('path');
const fs = require('fs');
const configLoader = require('commitizen').configLoader;
const customUtils = require('./customUtils');
module.exports = {
prompter: function (cz, commit) {
const config = configLoader.load();
const czConfig = config.path ? path.join(config.path, config.config) : path.resolve(process.cwd(), '.cz-config.js');
if (!fs.existsSync(czConfig)) {
customUtils.errorMessage();
process.exit(1);
}
const options = {
config: czConfig
};
require('cz-customizable').prompter(cz, commit, options);
}
};
该文件主要功能是加载自定义配置文件 .cz-config.js
,并调用 cz-customizable
的 prompter 方法来生成提交信息。
3. 项目的配置文件介绍
项目的配置文件是 cz-config-EXAMPLE.js
,它定义了自定义提交信息的格式和选项。以下是 cz-config-EXAMPLE.js
的主要内容:
module.exports = {
types: [
{ value: 'feat', name: 'feat: A new feature' },
{ value: 'fix', name: 'fix: A bug fix' },
{ value: 'docs', name: 'docs: Documentation only changes' },
{ value: 'style', name: 'style: Changes that do not affect the meaning of the code' },
{ value: 'refactor', name: 'refactor: A code change that neither fixes a bug nor adds a feature' },
{ value: 'perf', name: 'perf: A code change that improves performance' },
{ value: 'test', name: 'test: Adding missing tests' },
{ value: 'chore', name: 'chore: Changes to the build process or auxiliary tools and libraries such as documentation generation' },
{ value: 'revert', name: 'revert: Revert to a commit' },
{ value: 'WIP', name: 'WIP: Work in progress' }
],
scopes: [
{ name: 'accounts' },
{ name: 'admin' },
{ name: 'exampleScope' },
{ name: 'changeMe' }
],
allowCustomScopes: true,
allowBreakingChanges: ['feat', 'fix'],
skipQuestions: ['body', 'footer'],
subjectLimit: 100,
breaklineChar: '|',
footerPrefix: 'ISSUES CLOSED:',
askForBreakingChangeFirst: true
};
该配置文件定义了提交信息的类型、范围、是否允许自定义范围、是否允许破坏性变更等选项。通过修改该文件,可以自定义提交信息的格式和内容。
cz-customizable项目地址:https://gitcode.com/gh_mirrors/czc/cz-customizable