From 0e489da3870ca73c40d5a024f5787169a3be32d8 Mon Sep 17 00:00:00 2001 From: CodiceFabbrica Date: Tue, 17 Mar 2026 17:36:55 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20:memo:=20=E9=85=8D=E7=BD=AEgit=E8=A7=84?= =?UTF-8?q?=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/settings.local.json | 4 +- .czrc | 2 +- .gitee/PULL_REQUEST_TEMPLATE.md | 95 +++++++ .github/PULL_REQUEST_TEMPLATE.md | 95 +++++++ README.md | 23 +- commitlint.config.cjs | 72 ++++- docs/COMMIT_GUIDE.md | 234 ++++++++++++++++ docs/CONTRIBUTING.md | 220 +++++++++++++++ package.json | 4 +- packages/common/package-lock.json | 4 +- packages/common/package.json | 2 +- packages/uni-app/package-lock.json | 4 +- packages/vue2/package-lock.json | 4 +- packages/vue3/package-lock.json | 4 +- packages/vue3/package.json | 2 +- pnpm-lock.yaml | 430 ++++++----------------------- 16 files changed, 829 insertions(+), 370 deletions(-) create mode 100644 .gitee/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 docs/COMMIT_GUIDE.md create mode 100644 docs/CONTRIBUTING.md diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 37050ee..5d8e8ef 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -19,7 +19,9 @@ "Bash(npm view @typescript-eslint/parser@latest peerDependencies)", "Bash(npm view @typescript-eslint/parser@latest version)", "Bash(pnpm list typescript)", - "Bash(pnpm list @typescript-eslint/parser @typescript-eslint/eslint-plugin typescript-eslint)" + "Bash(pnpm list @typescript-eslint/parser @typescript-eslint/eslint-plugin typescript-eslint)", + "Bash(npm view @commitlint/cz-commitlint@latest peerDependencies)", + "Bash(npm view inquirer@9 version)" ] } } diff --git a/.czrc b/.czrc index 11f0406..1d3f7ee 100644 --- a/.czrc +++ b/.czrc @@ -1,3 +1,3 @@ { - "path": "@commitlint/cz-commitlint" + "path": "node_modules/cz-git" } diff --git a/.gitee/PULL_REQUEST_TEMPLATE.md b/.gitee/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ba23086 --- /dev/null +++ b/.gitee/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,95 @@ +## PR 类型 + +请勾选此 PR 的类型: + +- [ ] 🐛 Bug 修复 +- [ ] ✨ 新功能 +- [ ] 📚 文档更新 +- [ ] 🚀 性能优化 +- [ ] 📦 代码重构 +- [ ] 🚨 测试相关 +- [ ] 🛠 构建/工具相关 +- [ ] ♻️ 其他 + +## 相关 Issue + +关联的 Issue: #(issue 编号) + +## 变更说明 + +请简要描述此 PR 的变更内容: + + + +## 变更详情 + +### 主要改动 + + + +### 影响范围 + +- [ ] @r-utils/common +- [ ] @r-utils/vue3 +- [ ] @r-utils/vue2 +- [ ] @r-utils/uni-app +- [ ] 构建配置 +- [ ] 文档 +- [ ] 其他: ___________ + +## 测试 + +### 测试用例 + +- [ ] 已添加/更新单元测试 +- [ ] 所有测试通过 (`pnpm test`) +- [ ] 已手动测试 + +### 测试说明 + + + +## 检查清单 + +请确认以下事项: + +- [ ] 代码遵循项目的代码规范 +- [ ] 已运行 `pnpm lint` 且无错误 +- [ ] 已运行 `pnpm format` 格式化代码 +- [ ] 提交信息符合 Conventional Commits 规范 +- [ ] 已更新相关文档(如有必要) +- [ ] 已添加/更新测试用例(如有必要) +- [ ] 所有测试通过 +- [ ] 不包含破坏性变更(或已在下方说明) + +## 破坏性变更 + +- [ ] 此 PR 包含破坏性变更 + +如果包含破坏性变更,请详细说明: + + + +## 截图/录屏 + + + +## 其他信息 + + + +--- + +**注意事项:** +- 请确保 PR 标题简洁明了,遵循 Conventional Commits 规范 +- 如果 PR 解决了某个 Issue,请在描述中使用 `fix #123` 或 `close #123` 关联 +- 大型 PR 建议先创建 Issue 讨论方案 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ba23086 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,95 @@ +## PR 类型 + +请勾选此 PR 的类型: + +- [ ] 🐛 Bug 修复 +- [ ] ✨ 新功能 +- [ ] 📚 文档更新 +- [ ] 🚀 性能优化 +- [ ] 📦 代码重构 +- [ ] 🚨 测试相关 +- [ ] 🛠 构建/工具相关 +- [ ] ♻️ 其他 + +## 相关 Issue + +关联的 Issue: #(issue 编号) + +## 变更说明 + +请简要描述此 PR 的变更内容: + + + +## 变更详情 + +### 主要改动 + + + +### 影响范围 + +- [ ] @r-utils/common +- [ ] @r-utils/vue3 +- [ ] @r-utils/vue2 +- [ ] @r-utils/uni-app +- [ ] 构建配置 +- [ ] 文档 +- [ ] 其他: ___________ + +## 测试 + +### 测试用例 + +- [ ] 已添加/更新单元测试 +- [ ] 所有测试通过 (`pnpm test`) +- [ ] 已手动测试 + +### 测试说明 + + + +## 检查清单 + +请确认以下事项: + +- [ ] 代码遵循项目的代码规范 +- [ ] 已运行 `pnpm lint` 且无错误 +- [ ] 已运行 `pnpm format` 格式化代码 +- [ ] 提交信息符合 Conventional Commits 规范 +- [ ] 已更新相关文档(如有必要) +- [ ] 已添加/更新测试用例(如有必要) +- [ ] 所有测试通过 +- [ ] 不包含破坏性变更(或已在下方说明) + +## 破坏性变更 + +- [ ] 此 PR 包含破坏性变更 + +如果包含破坏性变更,请详细说明: + + + +## 截图/录屏 + + + +## 其他信息 + + + +--- + +**注意事项:** +- 请确保 PR 标题简洁明了,遵循 Conventional Commits 规范 +- 如果 PR 解决了某个 Issue,请在描述中使用 `fix #123` 或 `close #123` 关联 +- 大型 PR 建议先创建 Issue 讨论方案 diff --git a/README.md b/README.md index 64d2f0a..203515a 100644 --- a/README.md +++ b/README.md @@ -122,12 +122,20 @@ pnpm format ### Git 提交 +项目使用 [Conventional Commits](https://www.conventionalcommits.org/) 规范,通过 `commitizen` + `cz-git` 提供交互式提交体验。 + ```bash -# 使用 commitizen(遵循 conventional commits) +# 使用交互式提交(推荐) pnpm commit ``` -提交时 husky 会自动运行 lint-staged 和 jest 测试。 +提交时 husky 会自动运行: + +- `lint-staged` - 代码检查和格式化 +- `jest` - 单元测试 +- `commitlint` - 提交信息格式校验 + +详细说明请参考 [提交规范指南](./docs/COMMIT_GUIDE.md)。 ## 发布 @@ -210,7 +218,14 @@ r-util-js/ ## 参与贡献 +欢迎贡献代码!请先阅读: + +- [贡献指南](./docs/CONTRIBUTING.md) - 了解开发流程和规范 +- [提交规范指南](./docs/COMMIT_GUIDE.md) - 了解 Git 提交规范 + +基本流程: + 1. Fork 本仓库 -2. 新建 `feat/xxx` 分支 -3. 提交代码 +2. 新建分支 `feat/xxx` 或 `fix/xxx` +3. 提交代码(使用 `pnpm commit`) 4. 新建 Pull Request diff --git a/commitlint.config.cjs b/commitlint.config.cjs index 365fbbe..1df523a 100644 --- a/commitlint.config.cjs +++ b/commitlint.config.cjs @@ -14,16 +14,68 @@ module.exports = { extends: ["@commitlint/config-conventional"], - // rules: { - // "type-enum": [ - // 2, - // "always", - // ["feat", "fix", "docs", "style", "refactor", "test", "chore", "revert"], - // ], - // "subject-full-stop": [0, "never"], - // "subject-case": [0, "never"], - // }, + rules: { + // 限制提交类型 + "type-enum": [ + 2, + "always", + [ + "feat", + "fix", + "docs", + "style", + "refactor", + "perf", + "test", + "build", + "ci", + "chore", + "revert", + ], + ], + // scope 可选,但如果提供必须是以下之一 + "scope-enum": [ + 2, + "always", + ["common", "vue3", "vue2", "uni-app", "deps", "release"], + ], + // subject 不能为空 + "subject-empty": [2, "never"], + // subject 不能以句号结尾 + "subject-full-stop": [2, "never", "."], + // subject 不限制大小写 + "subject-case": [0], + // type 必须小写 + "type-case": [2, "always", "lower-case"], + // scope 必须小写 + "scope-case": [2, "always", "lower-case"], + // subject 最小长度 + "subject-min-length": [2, "always", 4], + // subject 最大长度 + "subject-max-length": [2, "always", 100], + // header 最大长度(type + scope + subject) + "header-max-length": [2, "always", 120], + // body 每行最大长度 + "body-max-line-length": [2, "always", 200], + // footer 每行最大长度 + "footer-max-line-length": [2, "always", 200], + }, prompt: { + useEmoji: true, + emojiAlign: "center", + allowCustomIssuePrefix: false, + allowEmptyIssuePrefix: false, + // 定义 scope 选项 + scopes: [ + { value: "common", name: "common: @r-utils/common 包" }, + { value: "vue3", name: "vue3: @r-utils/vue3 包" }, + { value: "vue2", name: "vue2: @r-utils/vue2 包" }, + { value: "uni-app", name: "uni-app: @r-utils/uni-app 包" }, + { value: "deps", name: "deps: 依赖更新" }, + { value: "release", name: "release: 版本发布" }, + ], + allowCustomScopes: false, + allowEmptyScopes: true, messages: { skip: "跳过", max: "最多 %d 个字符", @@ -96,7 +148,7 @@ module.exports = { }, }, scope: { - description: "更改的范围(scope)(例:组件 或 文件名)", + description: "更改的范围(scope)(例:common、vue3、uni-app)", }, subject: { description: "主题(subject)", diff --git a/docs/COMMIT_GUIDE.md b/docs/COMMIT_GUIDE.md new file mode 100644 index 0000000..fae182b --- /dev/null +++ b/docs/COMMIT_GUIDE.md @@ -0,0 +1,234 @@ +# Git 提交规范指南 + +本项目使用 [Conventional Commits](https://www.conventionalcommits.org/) 规范,通过 `commitizen` + `cz-git` 提供交互式提交体验。 + +## 快速开始 + +### 使用交互式提交(推荐) + +```bash +# 1. 暂存你的更改 +git add . + +# 2. 使用交互式提交 +pnpm commit +``` + +交互式提交会引导你完成: +1. 选择提交类型(feat/fix/docs 等) +2. 选择影响范围(common/vue3/uni-app 等,可跳过) +3. 输入简短描述(必填,4-100 字符) +4. 输入详细描述(可选) +5. 是否有破坏性变更(可选) +6. 关联 Issue(可选) + +### 手动提交 + +如果你熟悉规范,也可以手动提交: + +```bash +git commit -m "feat(common): 添加 debounce 防抖函数" +``` + +## 提交信息格式 + +``` +(): + + + +