@zjex/git-workflow 0.2.24 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/.github/workflows/deploy-docs.yml +68 -0
  2. package/.github/workflows/test.yml +24 -4
  3. package/.husky/pre-commit +14 -0
  4. package/README.md +72 -1066
  5. package/dist/index.js +103 -13
  6. package/docs/.vitepress/cache/deps/_metadata.json +52 -0
  7. package/docs/.vitepress/cache/deps/chunk-2CLQ7TTZ.js +9719 -0
  8. package/docs/.vitepress/cache/deps/chunk-2CLQ7TTZ.js.map +7 -0
  9. package/docs/.vitepress/cache/deps/chunk-LE5NDSFD.js +12824 -0
  10. package/docs/.vitepress/cache/deps/chunk-LE5NDSFD.js.map +7 -0
  11. package/docs/.vitepress/cache/deps/package.json +3 -0
  12. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4505 -0
  13. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
  14. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +583 -0
  15. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
  16. package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js +1352 -0
  17. package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
  18. package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js +1665 -0
  19. package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js.map +7 -0
  20. package/docs/.vitepress/cache/deps/vitepress___minisearch.js +1813 -0
  21. package/docs/.vitepress/cache/deps/vitepress___minisearch.js.map +7 -0
  22. package/docs/.vitepress/cache/deps/vue.js +347 -0
  23. package/docs/.vitepress/cache/deps/vue.js.map +7 -0
  24. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-2CLQ7TTZ.js +9719 -0
  25. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-2CLQ7TTZ.js.map +7 -0
  26. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-LE5NDSFD.js +12824 -0
  27. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-LE5NDSFD.js.map +7 -0
  28. package/docs/.vitepress/cache/deps_temp_44e2fb0f/package.json +3 -0
  29. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vue_devtools-api.js +4505 -0
  30. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vue_devtools-api.js.map +7 -0
  31. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_core.js +583 -0
  32. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_core.js.map +7 -0
  33. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_integrations_useFocusTrap.js +1352 -0
  34. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
  35. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___mark__js_src_vanilla__js.js +1665 -0
  36. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___mark__js_src_vanilla__js.js.map +7 -0
  37. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___minisearch.js +1813 -0
  38. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___minisearch.js.map +7 -0
  39. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vue.js +347 -0
  40. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vue.js.map +7 -0
  41. package/docs/.vitepress/config.ts +167 -0
  42. package/docs/.vitepress/theme/custom.css +39 -0
  43. package/docs/.vitepress/theme/index.ts +4 -0
  44. package/docs/README.md +82 -0
  45. package/docs/commands/branch.md +468 -0
  46. package/docs/commands/commit.md +554 -0
  47. package/docs/commands/config.md +346 -0
  48. package/docs/commands/index.md +312 -0
  49. package/docs/commands/interactive.md +384 -0
  50. package/docs/commands/release.md +300 -0
  51. package/docs/commands/stash.md +309 -0
  52. package/docs/commands/tag.md +278 -0
  53. package/docs/commands/update.md +347 -0
  54. package/docs/config/ai-config.md +160 -0
  55. package/docs/config/branch-config.md +133 -0
  56. package/docs/config/commit-config.md +185 -0
  57. package/docs/config/config-file.md +776 -0
  58. package/docs/config/examples.md +279 -0
  59. package/docs/config/index.md +478 -0
  60. package/docs/guide/ai-commit.md +576 -0
  61. package/docs/guide/basic-usage.md +522 -0
  62. package/docs/guide/best-practices.md +426 -0
  63. package/docs/guide/branch-management.md +712 -0
  64. package/docs/guide/getting-started.md +294 -0
  65. package/docs/guide/index.md +168 -0
  66. package/docs/guide/installation.md +449 -0
  67. package/docs/guide/release-management.md +744 -0
  68. package/docs/guide/stash-management.md +608 -0
  69. package/docs/guide/tag-management.md +614 -0
  70. package/docs/index.md +205 -0
  71. package/docs/public/favicon.svg +21 -0
  72. package/docs/public/hero-logo.svg +43 -0
  73. package/docs/public/logo.svg +20 -0
  74. package/package.json +11 -2
  75. package/scripts/publish.js +55 -8
  76. package/scripts/publish.sh +20 -2
  77. package/scripts/release.sh +20 -2
  78. package/scripts/update-test-count.js +55 -0
  79. package/src/ai-service.ts +101 -15
  80. package/src/commands/init.ts +18 -0
  81. package/src/config.ts +1 -0
  82. package/tests/ai-service.test.ts +237 -2
  83. package/tests/help.test.ts +134 -0
  84. package/tests/init.test.ts +582 -0
  85. package/tests/release.test.ts +333 -0
  86. package/tests/setup.ts +21 -0
  87. package/tests/stash.test.ts +376 -0
  88. package/tests/update.test.ts +402 -0
  89. package/vitest.config.ts +3 -0
  90. package/zjex-logo.svg +22 -0
  91. package/zjex-optimized.svg +34 -0
  92. package/zjex.svg +1 -0
@@ -0,0 +1,478 @@
1
+ # 配置概览
2
+
3
+ Git Workflow 提供了灵活的配置系统,支持全局配置和项目配置,让你可以根据不同的需求自定义工具行为。
4
+
5
+ ## 🎯 配置理念
6
+
7
+ ### 约定优于配置
8
+
9
+ Git Workflow 遵循"约定优于配置"的原则:
10
+
11
+ - **零配置开箱即用** - 无需任何配置即可开始使用
12
+ - **合理的默认值** - 提供适合大多数场景的默认配置
13
+ - **渐进式配置** - 可以根据需要逐步添加配置项
14
+
15
+ ### 灵活的配置层级
16
+
17
+ 支持多层级配置,满足不同场景需求:
18
+
19
+ 1. **内置默认配置** - 工具内置的基础配置
20
+ 2. **全局配置** - 对所有项目生效的个人配置
21
+ 3. **项目配置** - 仅对当前项目生效的团队配置
22
+
23
+ **配置优先级:** 项目配置 > 全局配置 > 默认配置
24
+
25
+ ## 📁 配置文件位置
26
+
27
+ ### 全局配置
28
+
29
+ ```
30
+ ~/.gwrc.json
31
+ ```
32
+
33
+ **特点:**
34
+ - 对所有项目生效
35
+ - 适合个人偏好设置
36
+ - 一次配置,处处使用
37
+
38
+ **适用场景:**
39
+ - AI commit 配置(API key、提供商等)
40
+ - 个人习惯配置(emoji、自动暂存等)
41
+ - 通用的分支命名规范
42
+
43
+ ### 项目配置
44
+
45
+ 支持多种文件名,按优先级查找:
46
+
47
+ ```
48
+ .gwrc.json # 推荐,JSON 格式
49
+ .gwrc # 简化文件名
50
+ gw.config.json # 明确的配置文件名
51
+ ```
52
+
53
+ **特点:**
54
+ - 仅对当前项目生效
55
+ - 可以提交到版本控制
56
+ - 团队成员共享配置
57
+
58
+ **适用场景:**
59
+ - 团队统一的分支规范
60
+ - 项目特定的 ID 要求
61
+ - 特殊的分支前缀
62
+
63
+ ### 查找顺序
64
+
65
+ Git Workflow 按以下顺序查找配置文件:
66
+
67
+ 1. **当前目录** - `./gwrc.json`
68
+ 2. **Git 仓库根目录** - `<git-root>/.gwrc.json`
69
+ 3. **用户主目录** - `~/.gwrc.json`
70
+ 4. **内置默认配置**
71
+
72
+ ## 🚀 快速开始
73
+
74
+ ### 创建全局配置(推荐)
75
+
76
+ ```bash
77
+ gw init
78
+ ```
79
+
80
+ 选择配置范围:
81
+
82
+ ```
83
+ ⚙️ 初始化 git-workflow 配置
84
+
85
+ ? 选择配置范围:
86
+ ❯ 全局配置(所有项目生效) # 推荐!配置一次,所有项目都能用
87
+ 项目配置(仅当前项目) # 为特定项目自定义配置
88
+ ```
89
+
90
+ 选择 **全局配置**,按提示完成配置:
91
+
92
+ ```
93
+ ✔ 选择配置范围: 全局配置(所有项目生效)
94
+
95
+ ? Feature 分支前缀: feature
96
+ ? Hotfix 分支前缀: hotfix
97
+ ? 是否强制要求填写 ID: 否
98
+ ? Feature 分支 ID 标签: Story ID
99
+ ? Hotfix 分支 ID 标签: Issue ID
100
+ ? 提交时是否自动暂存所有更改: 是
101
+ ? 是否使用 emoji: 是
102
+
103
+ ? 是否启用 AI commit 功能: 是
104
+ ? 选择 AI 提供商: GitHub Models(免费,推荐)
105
+ ? 输入你的 GitHub Token: ghp_xxxxxxxxxxxx
106
+ ? 选择语言: 中文
107
+
108
+ ✔ 全局配置已保存到: ~/.gwrc.json
109
+ ```
110
+
111
+ ### 创建项目配置
112
+
113
+ 在项目根目录运行:
114
+
115
+ ```bash
116
+ cd your-project
117
+ gw init
118
+ ```
119
+
120
+ 选择 **项目配置**,配置团队规范:
121
+
122
+ ```
123
+ ✔ 选择配置范围: 项目配置(仅当前项目)
124
+
125
+ ? 是否强制要求填写 ID: 是
126
+ ? Feature 分支 ID 标签: Jira ID
127
+ ? Hotfix 分支 ID 标签: Bug ID
128
+ ? 创建分支后是否自动推送到远程: 是
129
+ ? 默认基础分支: develop
130
+
131
+ ✔ 项目配置已保存到: .gwrc.json
132
+ ```
133
+
134
+ ## 📋 配置项详解
135
+
136
+ ### 完整配置示例
137
+
138
+ ```json
139
+ {
140
+ "baseBranch": "develop",
141
+ "featurePrefix": "feature",
142
+ "hotfixPrefix": "hotfix",
143
+ "requireId": true,
144
+ "featureIdLabel": "Jira ID",
145
+ "hotfixIdLabel": "Bug ID",
146
+ "defaultTagPrefix": "v",
147
+ "autoPush": true,
148
+ "autoStage": true,
149
+ "useEmoji": true,
150
+ "commitEmojis": {
151
+ "feat": "✨",
152
+ "fix": "🐛",
153
+ "docs": "📝"
154
+ },
155
+ "aiCommit": {
156
+ "enabled": true,
157
+ "provider": "github",
158
+ "apiKey": "ghp_xxxxxxxxxxxx",
159
+ "model": "gpt-4o-mini",
160
+ "language": "zh-CN",
161
+ "maxTokens": 200,
162
+ "detailedDescription": true
163
+ }
164
+ }
165
+ ```
166
+
167
+ ### 基础配置
168
+
169
+ | 配置项 | 类型 | 默认值 | 说明 |
170
+ | ---------------- | --------- | ----------- | ---------------------------------------- |
171
+ | `baseBranch` | `string` | 自动检测 | 默认基础分支,不设置则自动检测 main/master |
172
+ | `featurePrefix` | `string` | `"feature"` | feature 分支前缀 |
173
+ | `hotfixPrefix` | `string` | `"hotfix"` | hotfix 分支前缀 |
174
+
175
+ ### 分支配置
176
+
177
+ | 配置项 | 类型 | 默认值 | 说明 |
178
+ | ------------------ | --------- | ------------ | ------------------------------------------------------------------------------- |
179
+ | `requireId` | `boolean` | `false` | 是否强制要求填写 ID。开启后创建分支时必须填写 ID,不能跳过 |
180
+ | `featureIdLabel` | `string` | `"Story ID"` | feature 分支 ID 提示文字 |
181
+ | `hotfixIdLabel` | `string` | `"Issue ID"` | hotfix 分支 ID 提示文字 |
182
+ | `autoPush` | `boolean` | - | 创建分支后是否自动推送到远程。`true` 自动推送,`false` 不推送,不设置则每次询问 |
183
+
184
+ ### 版本配置
185
+
186
+ | 配置项 | 类型 | 默认值 | 说明 |
187
+ | ------------------ | -------- | ------ | --------------------------------- |
188
+ | `defaultTagPrefix` | `string` | - | 默认 tag 前缀,设置后跳过选择步骤 |
189
+
190
+ ### 提交配置
191
+
192
+ | 配置项 | 类型 | 默认值 | 说明 |
193
+ | -------------- | --------- | ------ | ----------------------------- |
194
+ | `autoStage` | `boolean` | `true` | commit 时是否自动暂存所有更改 |
195
+ | `useEmoji` | `boolean` | `true` | commit 时是否使用 emoji |
196
+ | `commitEmojis` | `object` | - | 自定义各类型 commit 的 emoji |
197
+
198
+ ### AI 配置
199
+
200
+ | 配置项 | 类型 | 默认值 | 说明 |
201
+ | ----------------------------- | --------- | ---------- | ---------------------------------------------------- |
202
+ | `aiCommit.enabled` | `boolean` | `true` | 是否启用 AI commit 功能 |
203
+ | `aiCommit.provider` | `string` | `"github"` | AI 提供商:`github` / `openai` / `claude` / `ollama` |
204
+ | `aiCommit.apiKey` | `string` | - | API key,留空使用内置 key |
205
+ | `aiCommit.model` | `string` | 根据提供商 | 模型名称 |
206
+ | `aiCommit.language` | `string` | `"zh-CN"` | 生成语言:`zh-CN` / `en-US` |
207
+ | `aiCommit.maxTokens` | `number` | `200` | 最大 token 数 |
208
+ | `aiCommit.detailedDescription` | `boolean` | `true` | 是否生成详细的修改点描述 |
209
+
210
+ ## 🎨 配置场景
211
+
212
+ ### 场景一:个人开发者
213
+
214
+ **需求:**
215
+ - 启用 AI commit
216
+ - 使用 emoji
217
+ - 自动暂存文件
218
+ - 不强制要求 ID
219
+
220
+ **配置:**
221
+
222
+ ```json
223
+ {
224
+ "autoStage": true,
225
+ "useEmoji": true,
226
+ "requireId": false,
227
+ "aiCommit": {
228
+ "enabled": true,
229
+ "provider": "github",
230
+ "language": "zh-CN"
231
+ }
232
+ }
233
+ ```
234
+
235
+ ### 场景二:团队协作
236
+
237
+ **需求:**
238
+ - 统一分支命名规范
239
+ - 强制关联 Issue/Story
240
+ - 自动推送到远程
241
+ - 基于 develop 分支开发
242
+
243
+ **配置:**
244
+
245
+ ```json
246
+ {
247
+ "baseBranch": "develop",
248
+ "requireId": true,
249
+ "featureIdLabel": "Jira ID",
250
+ "hotfixIdLabel": "Bug ID",
251
+ "autoPush": true
252
+ }
253
+ ```
254
+
255
+ ### 场景三:企业级项目
256
+
257
+ **需求:**
258
+ - 严格的分支规范
259
+ - 禁用 emoji(CI/CD 兼容性)
260
+ - 自定义分支前缀
261
+ - 手动选择暂存文件
262
+
263
+ **配置:**
264
+
265
+ ```json
266
+ {
267
+ "featurePrefix": "feat",
268
+ "hotfixPrefix": "fix",
269
+ "requireId": true,
270
+ "featureIdLabel": "需求编号",
271
+ "hotfixIdLabel": "缺陷编号",
272
+ "useEmoji": false,
273
+ "autoStage": false,
274
+ "aiCommit": {
275
+ "enabled": false
276
+ }
277
+ }
278
+ ```
279
+
280
+ ### 场景四:开源项目
281
+
282
+ **需求:**
283
+ - 英文提交信息
284
+ - 使用 emoji
285
+ - 不强制 ID
286
+ - 基于 main 分支
287
+
288
+ **配置:**
289
+
290
+ ```json
291
+ {
292
+ "baseBranch": "main",
293
+ "requireId": false,
294
+ "useEmoji": true,
295
+ "aiCommit": {
296
+ "enabled": true,
297
+ "language": "en-US"
298
+ }
299
+ }
300
+ ```
301
+
302
+ ## 🔧 配置管理
303
+
304
+ ### 查看当前配置
305
+
306
+ ```bash
307
+ # 查看生效的配置
308
+ gw config show
309
+
310
+ # 查看配置文件位置
311
+ gw config path
312
+ ```
313
+
314
+ ### 编辑配置
315
+
316
+ ```bash
317
+ # 编辑全局配置
318
+ gw config edit --global
319
+
320
+ # 编辑项目配置
321
+ gw config edit --local
322
+ ```
323
+
324
+ ### 重置配置
325
+
326
+ ```bash
327
+ # 重置为默认配置
328
+ gw config reset
329
+
330
+ # 删除配置文件
331
+ gw config clean
332
+ ```
333
+
334
+ ### 验证配置
335
+
336
+ ```bash
337
+ # 验证配置文件语法
338
+ gw config validate
339
+
340
+ # 测试配置效果
341
+ gw config test
342
+ ```
343
+
344
+ ## 📚 配置最佳实践
345
+
346
+ ### 1. 分层配置策略
347
+
348
+ **全局配置(个人偏好):**
349
+ ```json
350
+ {
351
+ "aiCommit": {
352
+ "enabled": true,
353
+ "provider": "github",
354
+ "apiKey": "your-token"
355
+ },
356
+ "useEmoji": true,
357
+ "autoStage": true
358
+ }
359
+ ```
360
+
361
+ **项目配置(团队规范):**
362
+ ```json
363
+ {
364
+ "requireId": true,
365
+ "featureIdLabel": "Jira ID",
366
+ "autoPush": true,
367
+ "baseBranch": "develop"
368
+ }
369
+ ```
370
+
371
+ ### 2. 版本控制
372
+
373
+ **提交项目配置:**
374
+ ```bash
375
+ git add .gwrc.json
376
+ git commit -m "chore: add git-workflow config"
377
+ ```
378
+
379
+ **忽略敏感信息:**
380
+ ```gitignore
381
+ # .gitignore
382
+ .gwrc.local.json # 本地覆盖配置
383
+ ```
384
+
385
+ ### 3. 团队协作
386
+
387
+ **文档化配置:**
388
+ ```markdown
389
+ # 项目配置说明
390
+
391
+ 本项目使用 git-workflow 进行版本管理,配置如下:
392
+
393
+ - 分支前缀:feature/、hotfix/
394
+ - 必须填写 Jira ID
395
+ - 基于 develop 分支开发
396
+ - 自动推送到远程
397
+
398
+ ## 安装和配置
399
+
400
+ 1. 安装工具:`npm install -g @zjex/git-workflow`
401
+ 2. 配置已包含在项目中,无需额外配置
402
+ 3. 开始使用:`gw f` 创建功能分支
403
+ ```
404
+
405
+ ### 4. 配置迁移
406
+
407
+ **从旧版本迁移:**
408
+ ```bash
409
+ # 备份旧配置
410
+ cp ~/.gwrc.json ~/.gwrc.json.backup
411
+
412
+ # 重新初始化
413
+ gw init --migrate
414
+ ```
415
+
416
+ **跨项目复制配置:**
417
+ ```bash
418
+ # 复制配置到新项目
419
+ cp project-a/.gwrc.json project-b/.gwrc.json
420
+ ```
421
+
422
+ ## 🔍 故障排除
423
+
424
+ ### 配置文件语法错误
425
+
426
+ ```bash
427
+ ❌ 配置文件语法错误: Unexpected token } in JSON
428
+ ```
429
+
430
+ **解决方案:**
431
+ 1. 使用 JSON 验证工具检查语法
432
+ 2. 重新运行 `gw init` 生成新配置
433
+ 3. 参考文档中的配置示例
434
+
435
+ ### 配置项不生效
436
+
437
+ ```bash
438
+ ❌ 配置项 'unknownOption' 不被识别
439
+ ```
440
+
441
+ **解决方案:**
442
+ 1. 检查配置项名称是否正确
443
+ 2. 查看文档确认支持的配置项
444
+ 3. 更新到最新版本
445
+
446
+ ### 权限问题
447
+
448
+ ```bash
449
+ ❌ 无法写入配置文件: Permission denied
450
+ ```
451
+
452
+ **解决方案:**
453
+ 1. 检查文件权限:`ls -la ~/.gwrc.json`
454
+ 2. 修改权限:`chmod 644 ~/.gwrc.json`
455
+ 3. 使用 sudo(不推荐)
456
+
457
+ ### 配置冲突
458
+
459
+ ```bash
460
+ ⚠️ 项目配置与全局配置存在冲突
461
+ ```
462
+
463
+ **解决方案:**
464
+ 1. 项目配置优先级更高,会覆盖全局配置
465
+ 2. 检查配置合并结果:`gw config show`
466
+ 3. 根据需要调整配置
467
+
468
+ ## 📖 深入学习
469
+
470
+ - [**配置文件详解**](/config/config-file) - 了解所有配置项的详细说明
471
+ - [**AI 配置**](/config/ai-config) - 深入配置 AI commit 功能
472
+ - [**分支配置**](/config/branch-config) - 自定义分支管理行为
473
+ - [**提交配置**](/config/commit-config) - 配置提交相关功能
474
+ - [**配置示例**](/config/examples) - 查看更多实际配置案例
475
+
476
+ ---
477
+
478
+ 通过合理的配置,Git Workflow 可以完美适应你的工作流程。从简单的个人项目到复杂的企业级应用,都能找到合适的配置方案。