UNPKG

@brickjs-fe/commit-config

Version:

BrickJs 提交规范配置包 - 包含 Commitlint、Commitizen 和 Husky 配置

139 lines (134 loc) 4.6 kB
/* * @Author : brickFE * @Email : brickfe@163.com * @Date : 2025-09-16 12:00:00 * @Description : BrickJs Commitizen 配置 - 交互式提交信息生成 */ /** * Commitizen 配置 - 交互式提交信息生成 * 提供友好的命令行界面来生成符合 Conventional Commits 规范的提交信息 */ const czConfig = { disableEmoji: false, format: '{type}: {emoji} {subject}', list: [ 'feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'chore', 'ci', 'build', 'revert', 'release' ], maxMessageLength: 100, minMessageLength: 10, questions: ['type', 'scope', 'subject', 'body', 'breaking', 'issues'], scopes: [], types: { feat: { description: '新功能', emoji: '✨', value: 'feat' }, fix: { description: '修复 Bug', emoji: '🐛', value: 'fix' }, docs: { description: '文档修改', emoji: '📝', value: 'docs' }, style: { description: '代码格式(不影响逻辑)', emoji: '💄', value: 'style' }, refactor: { description: '代码重构', emoji: '♻️', value: 'refactor' }, perf: { description: '性能优化', emoji: '⚡️', value: 'perf' }, test: { description: '测试相关', emoji: '✅', value: 'test' }, chore: { description: '构建/工具变动', emoji: '🔧', value: 'chore' }, ci: { description: 'CI 配置', emoji: '🤖', value: 'ci' }, build: { description: '构建系统', emoji: '📦', value: 'build' }, revert: { description: '回滚提交', emoji: '⏪', value: 'revert' }, release: { description: '发布版本', emoji: '🚀', value: 'release' } }, // 自定义 prompter 方法 prompter: function (cz, commit) { cz.prompt([ { type: 'list', name: 'type', message: '选择提交类型:', choices: [ { name: '✨ feat: 新功能', value: 'feat' }, { name: '🐛 fix: 修复 Bug', value: 'fix' }, { name: '📝 docs: 文档修改', value: 'docs' }, { name: '💄 style: 代码格式(不影响逻辑)', value: 'style' }, { name: '♻️ refactor: 代码重构', value: 'refactor' }, { name: '⚡️ perf: 性能优化', value: 'perf' }, { name: '✅ test: 测试相关', value: 'test' }, { name: '🔧 chore: 构建/工具变动', value: 'chore' }, { name: '🤖 ci: CI 配置', value: 'ci' }, { name: '📦 build: 构建系统', value: 'build' }, { name: '⏪ revert: 回滚提交', value: 'revert' }, { name: '🚀 release: 发布版本', value: 'release' } ] }, { type: 'input', name: 'scope', message: '变更的作用域 (可选):', validate: function (value) { return !value || /^[a-z-]+$/.test(value) ? true : '作用域只能包含小写字母和连字符' } }, { type: 'input', name: 'subject', message: '简短描述变更内容:', validate: function (value) { return value.length >= 3 ? true : '描述至少需要10个字符' } }, { type: 'input', name: 'body', message: '详细描述变更内容 (可选):' }, { type: 'confirm', name: 'isBreaking', message: '是否包含破坏性变更?', default: false }, { type: 'input', name: 'breaking', message: '描述破坏性变更:', when: function (answers) { return answers.isBreaking } }, { type: 'input', name: 'issues', message: '关联的 issue (如 #123):' } ]).then(function (answers) { const emojiMap = { feat: '✨', fix: '🐛', docs: '📝', style: '💄', refactor: '♻️', perf: '⚡️', test: '✅', chore: '🔧', ci: '🤖', build: '📦', revert: '⏪', release: '🚀' } let scope = answers.scope ? `(${answers.scope})` : '' let breaking = answers.isBreaking ? '!' : '' let subject = `${emojiMap[answers.type]} ${answers.subject}` let body = answers.body ? `\n\n${answers.body}` : '' let breakingNote = answers.breaking ? `\n\nBREAKING CHANGE: ${answers.breaking}` : '' let issues = answers.issues ? `\n\n${answers.issues}` : '' const commitMessage = `${answers.type}${scope}${breaking}: ${subject}${body}${breakingNote}${issues}` commit(commitMessage) }) } } export default czConfig