@zjex/git-workflow 0.4.0 → 0.4.2
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.
- package/CHANGELOG.md +488 -12
- package/README.md +8 -10
- package/ROADMAP.md +1 -1
- package/dist/index.js +124 -22
- package/docs/.vitepress/config.ts +111 -100
- package/docs/guide/api.md +607 -0
- package/docs/guide/contributing.md +441 -0
- package/docs/guide/development.md +295 -0
- package/docs/guide/team-collaboration.md +538 -0
- package/docs/guide/testing.md +461 -0
- package/package.json +3 -3
- package/scripts/generate-changelog-manual.js +135 -0
- package/src/commands/stash.ts +176 -7
- package/tests/stash.test.ts +161 -89
- package/CODE_DOCUMENTATION.md +0 -169
- package/TESTING.md +0 -436
- package/TEST_COVERAGE_SUMMARY.md +0 -264
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
# 贡献指南
|
|
2
|
+
|
|
3
|
+
感谢你考虑为 git-workflow 做出贡献!本指南将帮助你了解如何参与项目开发。
|
|
4
|
+
|
|
5
|
+
## 行为准则
|
|
6
|
+
|
|
7
|
+
我们致力于为所有人提供友好、安全和包容的环境。参与本项目即表示你同意遵守以下准则:
|
|
8
|
+
|
|
9
|
+
- 使用友好和包容的语言
|
|
10
|
+
- 尊重不同的观点和经验
|
|
11
|
+
- 优雅地接受建设性批评
|
|
12
|
+
- 关注对社区最有利的事情
|
|
13
|
+
- 对其他社区成员表示同理心
|
|
14
|
+
|
|
15
|
+
## 如何贡献
|
|
16
|
+
|
|
17
|
+
### 报告 Bug
|
|
18
|
+
|
|
19
|
+
如果你发现了 bug,请:
|
|
20
|
+
|
|
21
|
+
1. 检查 [Issues](https://github.com/iamzjt-front-end/git-workflow/issues) 确认问题未被报告
|
|
22
|
+
2. 创建新 Issue,包含:
|
|
23
|
+
- 清晰的标题和描述
|
|
24
|
+
- 重现步骤
|
|
25
|
+
- 预期行为和实际行为
|
|
26
|
+
- 环境信息(OS、Node.js 版本等)
|
|
27
|
+
- 相关的错误信息或截图
|
|
28
|
+
|
|
29
|
+
**Bug 报告模板:**
|
|
30
|
+
|
|
31
|
+
```markdown
|
|
32
|
+
## 问题描述
|
|
33
|
+
|
|
34
|
+
简要描述遇到的问题
|
|
35
|
+
|
|
36
|
+
## 重现步骤
|
|
37
|
+
|
|
38
|
+
1. 运行命令 `gw xxx`
|
|
39
|
+
2. 选择选项 xxx
|
|
40
|
+
3. 看到错误 xxx
|
|
41
|
+
|
|
42
|
+
## 预期行为
|
|
43
|
+
|
|
44
|
+
应该显示 xxx
|
|
45
|
+
|
|
46
|
+
## 实际行为
|
|
47
|
+
|
|
48
|
+
显示了 xxx 错误
|
|
49
|
+
|
|
50
|
+
## 环境信息
|
|
51
|
+
|
|
52
|
+
- OS: macOS 14.0
|
|
53
|
+
- Node.js: v20.0.0
|
|
54
|
+
- git-workflow: v0.4.0
|
|
55
|
+
|
|
56
|
+
## 错误信息
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
错误堆栈或截图
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 提出新功能
|
|
66
|
+
|
|
67
|
+
如果你有新功能的想法:
|
|
68
|
+
|
|
69
|
+
1. 先创建 Issue 讨论功能的必要性和设计
|
|
70
|
+
2. 等待维护者反馈
|
|
71
|
+
3. 获得批准后再开始开发
|
|
72
|
+
|
|
73
|
+
**功能请求模板:**
|
|
74
|
+
|
|
75
|
+
```markdown
|
|
76
|
+
## 功能描述
|
|
77
|
+
|
|
78
|
+
简要描述想要的功能
|
|
79
|
+
|
|
80
|
+
## 使用场景
|
|
81
|
+
|
|
82
|
+
为什么需要这个功能?它解决什么问题?
|
|
83
|
+
|
|
84
|
+
## 建议的实现
|
|
85
|
+
|
|
86
|
+
如何实现这个功能?
|
|
87
|
+
|
|
88
|
+
## 替代方案
|
|
89
|
+
|
|
90
|
+
是否考虑过其他方案?
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 提交代码
|
|
94
|
+
|
|
95
|
+
#### 1. Fork 仓库
|
|
96
|
+
|
|
97
|
+
点击 GitHub 页面右上角的 "Fork" 按钮。
|
|
98
|
+
|
|
99
|
+
#### 2. 克隆你的 Fork
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
git clone https://github.com/YOUR_USERNAME/git-workflow.git
|
|
103
|
+
cd git-workflow
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### 3. 添加上游仓库
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
git remote add upstream https://github.com/iamzjt-front-end/git-workflow.git
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### 4. 创建分支
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# 使用 gw 创建规范分支
|
|
116
|
+
gw f
|
|
117
|
+
# 输入 Story ID(可选)和描述
|
|
118
|
+
|
|
119
|
+
# 或手动创建
|
|
120
|
+
git checkout -b feature/20260116-PROJ-123-your-feature
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### 5. 开发功能
|
|
124
|
+
|
|
125
|
+
- 编写代码
|
|
126
|
+
- 添加测试
|
|
127
|
+
- 更新文档
|
|
128
|
+
- 确保代码通过 lint 和测试
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# 运行测试
|
|
132
|
+
npm test
|
|
133
|
+
|
|
134
|
+
# 检查类型
|
|
135
|
+
npm run build
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### 6. 提交代码
|
|
139
|
+
|
|
140
|
+
使用规范的提交信息:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# 使用 gw 提交(推荐)
|
|
144
|
+
gw c
|
|
145
|
+
|
|
146
|
+
# 或手动提交
|
|
147
|
+
git add .
|
|
148
|
+
git commit -m "feat: add new feature"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
提交信息格式:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
<type>(<scope>): <subject>
|
|
155
|
+
|
|
156
|
+
<body>
|
|
157
|
+
|
|
158
|
+
<footer>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
类型(type):
|
|
162
|
+
|
|
163
|
+
- `feat`: 新功能
|
|
164
|
+
- `fix`: 修复 bug
|
|
165
|
+
- `docs`: 文档更新
|
|
166
|
+
- `style`: 代码格式(不影响功能)
|
|
167
|
+
- `refactor`: 重构
|
|
168
|
+
- `test`: 测试相关
|
|
169
|
+
- `chore`: 构建/工具相关
|
|
170
|
+
- `perf`: 性能优化
|
|
171
|
+
|
|
172
|
+
示例:
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
feat(commit): 添加 AI 提交消息生成功能
|
|
176
|
+
|
|
177
|
+
- 集成 OpenAI API
|
|
178
|
+
- 支持自定义提示词
|
|
179
|
+
- 添加错误处理
|
|
180
|
+
|
|
181
|
+
Closes #123
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### 7. 推送到你的 Fork
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
git push origin feature/20260116-PROJ-123-your-feature
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### 8. 创建 Pull Request
|
|
191
|
+
|
|
192
|
+
1. 访问你的 Fork 页面
|
|
193
|
+
2. 点击 "New Pull Request"
|
|
194
|
+
3. 填写 PR 描述:
|
|
195
|
+
- 说明改动内容
|
|
196
|
+
- 关联相关 Issue
|
|
197
|
+
- 添加截图(如果适用)
|
|
198
|
+
4. 等待 review
|
|
199
|
+
|
|
200
|
+
**PR 模板:**
|
|
201
|
+
|
|
202
|
+
```markdown
|
|
203
|
+
## 改动说明
|
|
204
|
+
|
|
205
|
+
简要描述这个 PR 做了什么
|
|
206
|
+
|
|
207
|
+
## 关联 Issue
|
|
208
|
+
|
|
209
|
+
Closes #123
|
|
210
|
+
|
|
211
|
+
## 改动类型
|
|
212
|
+
|
|
213
|
+
- [ ] Bug 修复
|
|
214
|
+
- [ ] 新功能
|
|
215
|
+
- [ ] 文档更新
|
|
216
|
+
- [ ] 代码重构
|
|
217
|
+
- [ ] 性能优化
|
|
218
|
+
- [ ] 测试相关
|
|
219
|
+
|
|
220
|
+
## 测试
|
|
221
|
+
|
|
222
|
+
- [ ] 添加了新的测试
|
|
223
|
+
- [ ] 所有测试通过
|
|
224
|
+
- [ ] 手动测试通过
|
|
225
|
+
|
|
226
|
+
## 截图(如果适用)
|
|
227
|
+
|
|
228
|
+
添加截图展示改动效果
|
|
229
|
+
|
|
230
|
+
## Checklist
|
|
231
|
+
|
|
232
|
+
- [ ] 代码遵循项目规范
|
|
233
|
+
- [ ] 添加了必要的测试
|
|
234
|
+
- [ ] 更新了相关文档
|
|
235
|
+
- [ ] 提交信息符合规范
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 开发规范
|
|
239
|
+
|
|
240
|
+
### 代码风格
|
|
241
|
+
|
|
242
|
+
- 使用 TypeScript 严格模式
|
|
243
|
+
- 遵循 ESLint 规则
|
|
244
|
+
- 使用 2 空格缩进
|
|
245
|
+
- 使用单引号
|
|
246
|
+
- 添加必要的注释
|
|
247
|
+
|
|
248
|
+
### 命名规范
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
// 文件名:kebab-case
|
|
252
|
+
// ai-service.ts, commit-format.ts
|
|
253
|
+
|
|
254
|
+
// 函数名:camelCase
|
|
255
|
+
function getBranchName() {}
|
|
256
|
+
async function generateCommitMessage() {}
|
|
257
|
+
|
|
258
|
+
// 类型/接口:PascalCase
|
|
259
|
+
interface CommitConfig {}
|
|
260
|
+
type BranchType = "feature" | "hotfix";
|
|
261
|
+
|
|
262
|
+
// 常量:UPPER_SNAKE_CASE
|
|
263
|
+
const DEFAULT_CONFIG = {};
|
|
264
|
+
const MAX_RETRIES = 3;
|
|
265
|
+
|
|
266
|
+
// 私有函数:以 _ 开头
|
|
267
|
+
function _internalHelper() {}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### 函数设计
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
// ✅ 好的函数设计
|
|
274
|
+
/**
|
|
275
|
+
* 生成规范的分支名
|
|
276
|
+
* @param type - 分支类型
|
|
277
|
+
* @param storyId - Story ID(可选)
|
|
278
|
+
* @param description - 分支描述
|
|
279
|
+
* @returns 格式化的分支名
|
|
280
|
+
*/
|
|
281
|
+
function generateBranchName(
|
|
282
|
+
type: BranchType,
|
|
283
|
+
storyId: string,
|
|
284
|
+
description: string
|
|
285
|
+
): string {
|
|
286
|
+
// 实现
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// ❌ 不好的函数设计
|
|
290
|
+
function doStuff(a: any, b: any): any {
|
|
291
|
+
// 实现
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### 错误处理
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
// ✅ 好的错误处理
|
|
299
|
+
try {
|
|
300
|
+
const result = await apiCall();
|
|
301
|
+
return result;
|
|
302
|
+
} catch (error) {
|
|
303
|
+
if (error instanceof NetworkError) {
|
|
304
|
+
console.error("网络错误:", error.message);
|
|
305
|
+
} else {
|
|
306
|
+
console.error("未知错误:", error);
|
|
307
|
+
}
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// ❌ 不好的错误处理
|
|
312
|
+
try {
|
|
313
|
+
const result = await apiCall();
|
|
314
|
+
return result;
|
|
315
|
+
} catch (error) {
|
|
316
|
+
// 忽略错误
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### 测试要求
|
|
321
|
+
|
|
322
|
+
每个新功能都必须包含测试:
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
describe("新功能", () => {
|
|
326
|
+
it("应该正确处理正常情况", () => {
|
|
327
|
+
// 测试正常流程
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("应该处理边界情况", () => {
|
|
331
|
+
// 测试边界条件
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("应该处理错误情况", () => {
|
|
335
|
+
// 测试错误处理
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### 文档要求
|
|
341
|
+
|
|
342
|
+
- 为新功能添加文档
|
|
343
|
+
- 更新 README(如果需要)
|
|
344
|
+
- 添加代码注释
|
|
345
|
+
- 更新 CHANGELOG
|
|
346
|
+
|
|
347
|
+
## Review 流程
|
|
348
|
+
|
|
349
|
+
### 提交 PR 后
|
|
350
|
+
|
|
351
|
+
1. 自动运行 CI 测试
|
|
352
|
+
2. 维护者 review 代码
|
|
353
|
+
3. 根据反馈修改代码
|
|
354
|
+
4. 再次 review
|
|
355
|
+
5. 合并到 main 分支
|
|
356
|
+
|
|
357
|
+
### Review 标准
|
|
358
|
+
|
|
359
|
+
代码会从以下方面进行 review:
|
|
360
|
+
|
|
361
|
+
- ✅ 功能是否正确实现
|
|
362
|
+
- ✅ 代码质量和可读性
|
|
363
|
+
- ✅ 测试覆盖率
|
|
364
|
+
- ✅ 文档完整性
|
|
365
|
+
- ✅ 性能影响
|
|
366
|
+
- ✅ 安全性考虑
|
|
367
|
+
|
|
368
|
+
### 常见 Review 意见
|
|
369
|
+
|
|
370
|
+
**代码质量:**
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
// ❌ 需要改进
|
|
374
|
+
function process(data: any) {
|
|
375
|
+
const result = data.map((x) => x * 2);
|
|
376
|
+
return result;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ✅ 改进后
|
|
380
|
+
/**
|
|
381
|
+
* 处理数据,将每个值翻倍
|
|
382
|
+
*/
|
|
383
|
+
function processData(numbers: number[]): number[] {
|
|
384
|
+
return numbers.map((num) => num * 2);
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
**错误处理:**
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
// ❌ 需要改进
|
|
392
|
+
async function fetchData() {
|
|
393
|
+
const response = await fetch(url);
|
|
394
|
+
return response.json();
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// ✅ 改进后
|
|
398
|
+
async function fetchData(): Promise<Data> {
|
|
399
|
+
try {
|
|
400
|
+
const response = await fetch(url);
|
|
401
|
+
if (!response.ok) {
|
|
402
|
+
throw new Error(`HTTP ${response.status}`);
|
|
403
|
+
}
|
|
404
|
+
return await response.json();
|
|
405
|
+
} catch (error) {
|
|
406
|
+
console.error("获取数据失败:", error);
|
|
407
|
+
throw error;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## 发布流程
|
|
413
|
+
|
|
414
|
+
发布由维护者执行:
|
|
415
|
+
|
|
416
|
+
1. 更新版本号
|
|
417
|
+
2. 更新 CHANGELOG
|
|
418
|
+
3. 创建 tag
|
|
419
|
+
4. 发布到 npm
|
|
420
|
+
5. 发布 GitHub Release
|
|
421
|
+
|
|
422
|
+
## 获取帮助
|
|
423
|
+
|
|
424
|
+
如果你在贡献过程中遇到问题:
|
|
425
|
+
|
|
426
|
+
- 📖 查看 [开发指南](./development.md)
|
|
427
|
+
- 🧪 查看 [测试指南](./testing.md)
|
|
428
|
+
- 💬 在 Issue 中提问
|
|
429
|
+
- 💡 参与 [Discussions](https://github.com/iamzjt-front-end/git-workflow/discussions)
|
|
430
|
+
|
|
431
|
+
## 贡献者
|
|
432
|
+
|
|
433
|
+
感谢所有贡献者!
|
|
434
|
+
|
|
435
|
+
<a href="https://github.com/iamzjt-front-end/git-workflow/graphs/contributors">
|
|
436
|
+
<img src="https://contrib.rocks/image?repo=iamzjt-front-end/git-workflow" />
|
|
437
|
+
</a>
|
|
438
|
+
|
|
439
|
+
## 许可证
|
|
440
|
+
|
|
441
|
+
通过贡献代码,你同意你的贡献将在 [MIT License](https://github.com/iamzjt-front-end/git-workflow/blob/main/LICENSE) 下发布。
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# 开发指南
|
|
2
|
+
|
|
3
|
+
本指南将帮助你快速搭建 git-workflow 的本地开发环境。
|
|
4
|
+
|
|
5
|
+
## 环境要求
|
|
6
|
+
|
|
7
|
+
- **Node.js**: >= 18.0.0
|
|
8
|
+
- **npm**: >= 9.0.0(或使用 pnpm/yarn)
|
|
9
|
+
- **Git**: >= 2.0.0
|
|
10
|
+
|
|
11
|
+
## 快速开始
|
|
12
|
+
|
|
13
|
+
### 1. 克隆仓库
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/iamzjt-front-end/git-workflow.git
|
|
17
|
+
cd git-workflow
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### 2. 安装依赖
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 3. 开发模式
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm run dev
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
这会启动 TypeScript 的 watch 模式,自动编译代码变更。
|
|
33
|
+
|
|
34
|
+
### 4. 本地测试
|
|
35
|
+
|
|
36
|
+
在开发模式下,你可以直接运行编译后的代码:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# 使用 node 运行
|
|
40
|
+
node dist/index.js <command>
|
|
41
|
+
|
|
42
|
+
# 或者使用可执行权限
|
|
43
|
+
./dist/index.js <command>
|
|
44
|
+
|
|
45
|
+
# 示例
|
|
46
|
+
node dist/index.js --version
|
|
47
|
+
node dist/index.js f
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 5. 运行测试
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# 运行所有测试
|
|
54
|
+
npm test
|
|
55
|
+
|
|
56
|
+
# 运行特定测试文件
|
|
57
|
+
npm test -- tests/commit.test.ts
|
|
58
|
+
|
|
59
|
+
# 监听模式(开发时使用)
|
|
60
|
+
npm run test:watch
|
|
61
|
+
|
|
62
|
+
# 查看测试覆盖率
|
|
63
|
+
npm run test:coverage
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 6. 构建
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm run build
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
构建产物会输出到 `dist/` 目录。
|
|
73
|
+
|
|
74
|
+
## 项目结构
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
git-workflow/
|
|
78
|
+
├── src/ # 源代码
|
|
79
|
+
│ ├── commands/ # 命令实现
|
|
80
|
+
│ │ ├── branch.ts # 分支管理
|
|
81
|
+
│ │ ├── commit.ts # 提交管理
|
|
82
|
+
│ │ ├── tag.ts # 标签管理
|
|
83
|
+
│ │ ├── stash.ts # Stash 管理
|
|
84
|
+
│ │ ├── release.ts # 发布管理
|
|
85
|
+
│ │ ├── log.ts # 日志查看
|
|
86
|
+
│ │ ├── update.ts # 更新检查
|
|
87
|
+
│ │ └── init.ts # 初始化配置
|
|
88
|
+
│ ├── ai-service.ts # AI 服务
|
|
89
|
+
│ ├── config.ts # 配置管理
|
|
90
|
+
│ ├── utils.ts # 工具函数
|
|
91
|
+
│ ├── update-notifier.ts # 更新通知
|
|
92
|
+
│ └── index.ts # 入口文件
|
|
93
|
+
├── tests/ # 测试文件
|
|
94
|
+
├── docs/ # VitePress 文档
|
|
95
|
+
├── scripts/ # 构建和发布脚本
|
|
96
|
+
└── dist/ # 构建输出(git ignored)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 开发工作流
|
|
100
|
+
|
|
101
|
+
### 创建新功能
|
|
102
|
+
|
|
103
|
+
1. 从 main 分支创建 feature 分支:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
gw f
|
|
107
|
+
# 或手动创建
|
|
108
|
+
git checkout -b feature/YYYYMMDD-STORY-description
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
2. 开发功能并编写测试
|
|
112
|
+
|
|
113
|
+
3. 运行测试确保通过:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
npm test
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
4. 提交代码:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
gw c
|
|
123
|
+
# 或手动提交
|
|
124
|
+
git add .
|
|
125
|
+
git commit -m "feat: add new feature"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 调试技巧
|
|
129
|
+
|
|
130
|
+
#### 1. 使用 console.log
|
|
131
|
+
|
|
132
|
+
在代码中添加 `console.log` 进行调试:
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
console.log("Debug:", variable);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### 2. 使用 Node.js 调试器
|
|
139
|
+
|
|
140
|
+
在 VS Code 中创建 `.vscode/launch.json`:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"version": "0.2.0",
|
|
145
|
+
"configurations": [
|
|
146
|
+
{
|
|
147
|
+
"type": "node",
|
|
148
|
+
"request": "launch",
|
|
149
|
+
"name": "Debug Current Test",
|
|
150
|
+
"program": "${workspaceFolder}/node_modules/vitest/vitest.mjs",
|
|
151
|
+
"args": ["run", "${file}"],
|
|
152
|
+
"console": "integratedTerminal",
|
|
153
|
+
"internalConsoleOptions": "neverOpen"
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### 3. 测试特定场景
|
|
160
|
+
|
|
161
|
+
创建临时测试文件快速验证:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
// test-temp.ts
|
|
165
|
+
import { someFunction } from "./src/utils.js";
|
|
166
|
+
|
|
167
|
+
console.log(someFunction("test"));
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
运行:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
npx tsx test-temp.ts
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## 代码规范
|
|
177
|
+
|
|
178
|
+
### TypeScript
|
|
179
|
+
|
|
180
|
+
- 使用严格模式(`strict: true`)
|
|
181
|
+
- 为所有函数添加类型注解
|
|
182
|
+
- 避免使用 `any`,使用 `unknown` 代替
|
|
183
|
+
- 使用接口定义数据结构
|
|
184
|
+
|
|
185
|
+
### 命名规范
|
|
186
|
+
|
|
187
|
+
- **文件名**: kebab-case(如 `ai-service.ts`)
|
|
188
|
+
- **函数名**: camelCase(如 `getBranchName`)
|
|
189
|
+
- **类型/接口**: PascalCase(如 `CommitConfig`)
|
|
190
|
+
- **常量**: UPPER_SNAKE_CASE(如 `DEFAULT_CONFIG`)
|
|
191
|
+
|
|
192
|
+
### 提交信息
|
|
193
|
+
|
|
194
|
+
遵循 [Conventional Commits](https://www.conventionalcommits.org/) 规范:
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
<type>(<scope>): <subject>
|
|
198
|
+
|
|
199
|
+
<body>
|
|
200
|
+
|
|
201
|
+
<footer>
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
类型:
|
|
205
|
+
|
|
206
|
+
- `feat`: 新功能
|
|
207
|
+
- `fix`: 修复 bug
|
|
208
|
+
- `docs`: 文档更新
|
|
209
|
+
- `style`: 代码格式(不影响功能)
|
|
210
|
+
- `refactor`: 重构
|
|
211
|
+
- `test`: 测试相关
|
|
212
|
+
- `chore`: 构建/工具相关
|
|
213
|
+
|
|
214
|
+
## 常见问题
|
|
215
|
+
|
|
216
|
+
### Q: 如何添加新命令?
|
|
217
|
+
|
|
218
|
+
1. 在 `src/commands/` 创建新文件
|
|
219
|
+
2. 实现命令逻辑
|
|
220
|
+
3. 在 `src/index.ts` 注册命令
|
|
221
|
+
4. 添加测试文件
|
|
222
|
+
5. 更新文档
|
|
223
|
+
|
|
224
|
+
### Q: 如何添加新的 AI 提供商?
|
|
225
|
+
|
|
226
|
+
1. 在 `src/ai-service.ts` 的 `generateCommitMessage` 函数中添加新的 case
|
|
227
|
+
2. 实现 API 调用逻辑
|
|
228
|
+
3. 更新配置类型定义
|
|
229
|
+
4. 添加测试
|
|
230
|
+
5. 更新 AI 配置文档
|
|
231
|
+
|
|
232
|
+
### Q: 如何调试 Git 命令?
|
|
233
|
+
|
|
234
|
+
使用 `execOutput` 函数查看 Git 命令输出:
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
import { execOutput } from "./utils.js";
|
|
238
|
+
|
|
239
|
+
const output = execOutput("git status --porcelain");
|
|
240
|
+
console.log("Git output:", output);
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Q: 测试失败怎么办?
|
|
244
|
+
|
|
245
|
+
1. 检查错误信息
|
|
246
|
+
2. 运行单个测试文件定位问题
|
|
247
|
+
3. 使用 `console.log` 调试
|
|
248
|
+
4. 检查 mock 是否正确设置
|
|
249
|
+
|
|
250
|
+
## 发布流程
|
|
251
|
+
|
|
252
|
+
发布由维护者执行:
|
|
253
|
+
|
|
254
|
+
1. 更新版本号:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
npm run version
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
2. 更新 CHANGELOG
|
|
261
|
+
|
|
262
|
+
3. 提交并推送:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
git add .
|
|
266
|
+
git commit -m "chore: release v1.x.x"
|
|
267
|
+
git push
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
4. 创建 tag:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
gw t
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
5. 发布到 npm:
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
npm publish
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## 相关资源
|
|
283
|
+
|
|
284
|
+
- [TypeScript 文档](https://www.typescriptlang.org/docs/)
|
|
285
|
+
- [Vitest 文档](https://vitest.dev/)
|
|
286
|
+
- [Inquirer.js 文档](https://github.com/SBoudrias/Inquirer.js)
|
|
287
|
+
- [Commander.js 文档](https://github.com/tj/commander.js)
|
|
288
|
+
- [Conventional Commits](https://www.conventionalcommits.org/)
|
|
289
|
+
|
|
290
|
+
## 获取帮助
|
|
291
|
+
|
|
292
|
+
- 查看 [CODE_DOCUMENTATION.md](https://github.com/iamzjt-front-end/git-workflow/blob/main/CODE_DOCUMENTATION.md) 了解代码架构
|
|
293
|
+
- 查看 [TESTING.md](https://github.com/iamzjt-front-end/git-workflow/blob/main/TESTING.md) 了解测试策略
|
|
294
|
+
- 提交 [Issue](https://github.com/iamzjt-front-end/git-workflow/issues) 报告问题
|
|
295
|
+
- 加入讨论 [Discussions](https://github.com/iamzjt-front-end/git-workflow/discussions)
|