Package Exports
- @brickjs-fe/commit-config
- @brickjs-fe/commit-config/cz-config.js
Readme
@brickjs-fe/commit-config
📖 介绍
BrickJs 提交规范配置包提供了一套完整的 Git 提交规范解决方案,基于 Conventional Commits 规范,集成了:
- Commitlint - 提交信息格式检查
- Commitizen - 交互式提交信息生成
- Husky - Git 钩子配置
- Lint-staged - 暂存文件检查配置
✨ 特性
- 🎯 严格的提交规范 - 基于 Conventional Commits 标准
- 🎨 友好的交互界面 - 使用 Emoji 和中文提示
- 🔧 开箱即用 - 预配置所有必要的工具
- 📝 自动化检查 - 集成 Git 钩子和暂存文件检查
- 🚀 易于扩展 - 可自定义规则和配置
🚀 一键安装,自动配置
超简单安装
只需要一行命令,所有配置自动完成:
# 使用 pnpm(推荐)
pnpm add -D @brickjs-fe/commit-config
# 使用 npm
npm install --save-dev @brickjs-fe/commit-config
# 使用 yarn
yarn add -D @brickjs-fe/commit-config就是这么简单! 🎉
安装完成后,包会自动:
- ✅ 智能创建配置文件(ESM 项目生成
.mjs,CommonJS 项目生成.js) - ✅ 在
package.json中添加 commitizen 配置 - ✅ 添加
pnpm commit脚本 - ✅ 如果检测到 husky,自动配置 Git 钩子
可选依赖
如果你想要完整的提交检查功能,可以额外安装:
# 基础依赖(commitlint 检查)
pnpm add -D @commitlint/cli @commitlint/config-conventional
# Git 钩子支持
pnpm add -D husky
# 暂存文件检查
pnpm add -D lint-staged
# 全局 commitizen(可选)
npm install -g commitizen手动配置(高级用户)
如果你需要自定义配置或者自动配置失败,可以手动设置:
1. Commitlint 配置
创建 commitlint.config.js 文件:
export default {
extends: ['@brickjs-fe/commit-config']
};2. Commitizen 配置
在 package.json 中添加:
{
"config": {
"commitizen": {
"path": "@brickjs-fe/commit-config/cz-config.js"
}
},
"scripts": {
"commit": "cz"
}
}3. Husky 配置(可选)
# 初始化 Husky
npx husky init
# 添加 commit-msg 钩子
echo 'npx --no -- commitlint --edit $1' > .husky/commit-msg📝 使用方法
交互式提交
安装完成后,使用以下命令进行交互式提交:
# 推荐方式(自动配置的脚本)
pnpm commit
# 或者直接使用 commitizen
npx cz
# 完整流程
git add .
pnpm commit提交类型说明
| 类型 | 描述 | Emoji |
|---|---|---|
feat |
新功能 | ✨ |
fix |
修复 Bug | 🐛 |
docs |
文档修改 | 📝 |
style |
代码格式调整(不影响功能) | 💄 |
refactor |
代码重构 | ♻️ |
perf |
性能优化 | ⚡️ |
test |
测试相关 | ✅ |
chore |
构建过程或辅助工具的变动 | 🔧 |
ci |
CI/CD 相关 | 🤖 |
build |
构建系统或外部依赖的变动 | 📦 |
revert |
回滚提交 | ⏪ |
release |
发布版本 | 🚀 |
提交信息格式
<type>(<scope>): <emoji> <subject>
<body>
<footer>示例:
feat(auth): ✨ 添加用户登录功能
实现了基于 JWT 的用户认证系统
支持用户名和邮箱登录
Closes #123🔧 高级配置
自定义 Commitlint 规则
import { getCommitlintConfig } from '@brickjs-fe/commit-config';
const config = getCommitlintConfig();
export default {
...config,
rules: {
...config.rules,
// 自定义规则
'header-max-length': [2, 'always', 120],
'scope-enum': [2, 'always', ['auth', 'core', 'ui']]
}
};自定义 Commitizen 配置
import { getCzConfig } from '@brickjs-fe/commit-config';
const config = getCzConfig();
export default {
...config,
scopes: ['auth', 'core', 'ui'], // 自定义作用域
types: {
...config.types,
// 添加自定义类型
wip: { description: '开发中', emoji: '🚧', value: 'wip' }
}
};自定义 Husky 钩子
import { getHuskyHooks } from '@brickjs-fe/commit-config';
const hooks = getHuskyHooks();
// 在 .husky/ 目录下创建对应的钩子文件
// 例如 .husky/pre-commit
console.log(hooks['pre-commit']); // npx lint-staged📁 项目结构
@brickjs-fe/commit-config/
├── index.js # 主入口文件
├── commitlint.config.js # Commitlint 配置
├── cz-config.js # Commitizen 配置
├── package.json # 包配置
├── README.md # 说明文档
└── LICENSE # 许可证🔍 API 文档
getCommitlintConfig()
获取 Commitlint 配置对象。
import { getCommitlintConfig } from '@brickjs-fe/commit-config';
const config = getCommitlintConfig();getCzConfig()
获取 Commitizen 配置对象。
import { getCzConfig } from '@brickjs-fe/commit-config';
const config = getCzConfig();getHuskyHooks()
获取推荐的 Husky 钩子配置。
import { getHuskyHooks } from '@brickjs-fe/commit-config';
const hooks = getHuskyHooks();
// {
// 'commit-msg': 'npx --no -- commitlint --edit $1',
// 'pre-commit': 'npx lint-staged',
// 'pre-push': 'npm run test'
// }getLintStagedConfig()
获取推荐的 lint-staged 配置。
import { getLintStagedConfig } from '@brickjs-fe/commit-config';
const config = getLintStagedConfig();🤝 贡献指南
- Fork 本仓库
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'feat: ✨ add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开 Pull Request
📄 许可证
本项目基于 MIT 许可证开源。