@zjex/git-workflow 0.0.1
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 +22 -0
- package/README.md +377 -0
- package/dist/index.js +60 -0
- package/package.json +51 -0
- package/src/commands/branch.ts +227 -0
- package/src/commands/help.ts +49 -0
- package/src/commands/init.ts +103 -0
- package/src/commands/release.ts +118 -0
- package/src/commands/stash.ts +290 -0
- package/src/commands/tag.ts +277 -0
- package/src/config.ts +88 -0
- package/src/index.ts +88 -0
- package/src/utils.ts +82 -0
- package/tsconfig.json +20 -0
- package/tsup.config.ts +18 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## ...main
|
|
4
|
+
|
|
5
|
+
### 🚀 Enhancements
|
|
6
|
+
|
|
7
|
+
- Initialize git-workflow CLI project with core functionality (9d65fde)
|
|
8
|
+
- **cli:** Migrate to CAC CLI framework with improved command structure (58de329)
|
|
9
|
+
|
|
10
|
+
### 📖 Documentation
|
|
11
|
+
|
|
12
|
+
- Update ID label terminology to English standards (1b0882d)
|
|
13
|
+
- Enhance README with comprehensive guide and visual improvements (8ec8afb)
|
|
14
|
+
|
|
15
|
+
### 🏡 Chore
|
|
16
|
+
|
|
17
|
+
- **build:** Replace tsc with tsup for optimized bundling (6e847f5)
|
|
18
|
+
- Add automated changelog generation and git hooks (ea94d88)
|
|
19
|
+
|
|
20
|
+
### ❤️ Contributors
|
|
21
|
+
|
|
22
|
+
- 朱锦涛 <zhujintao@qmai.cn>
|
package/README.md
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
# @zjex/git-workflow
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://img.shields.io/npm/v/@zjex/git-workflow.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="npm version">
|
|
5
|
+
<img src="https://img.shields.io/npm/dm/@zjex/git-workflow.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="npm downloads">
|
|
6
|
+
<img src="https://img.shields.io/npm/l/@zjex/git-workflow.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="license">
|
|
7
|
+
<img src="https://img.shields.io/badge/node-%3E%3D18-28CF8D?style=flat&colorA=18181B" alt="node version">
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
🚀 极简的 Git 工作流 CLI 工具,让分支管理和版本发布变得轻松愉快
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="#特性">特性</a> •
|
|
16
|
+
<a href="#快速开始">快速开始</a> •
|
|
17
|
+
<a href="#命令详解">命令详解</a> •
|
|
18
|
+
<a href="#配置文件">配置文件</a> •
|
|
19
|
+
<a href="#最佳实践">最佳实践</a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 为什么选择 @zjex/git-workflow?
|
|
25
|
+
|
|
26
|
+
在日常开发中,你是否经常遇到这些问题:
|
|
27
|
+
|
|
28
|
+
- 🤔 每次创建分支都要手动输入一长串命名规范?
|
|
29
|
+
- 😫 发布版本时总是忘记当前版本号是多少?
|
|
30
|
+
- 🔄 删除分支时需要分别处理本地和远程?
|
|
31
|
+
- 📝 团队成员的分支命名风格五花八门?
|
|
32
|
+
|
|
33
|
+
**git-workflow** 就是为解决这些痛点而生的。它提供了一套简洁的命令,让你专注于编码,而不是 Git 操作。
|
|
34
|
+
|
|
35
|
+
## 特性
|
|
36
|
+
|
|
37
|
+
- ⚡️ **极速上手** - 零配置开箱即用,一个命令搞定分支创建
|
|
38
|
+
- 🎯 **规范命名** - 自动生成带日期的规范分支名,告别命名混乱
|
|
39
|
+
- 🏷️ **智能版本** - 自动识别当前版本,交互式选择下一版本(支持 semver + 预发布)
|
|
40
|
+
- 🗑️ **批量清理** - 一键删除本地+远程分支,按最近使用排序
|
|
41
|
+
- ⚙️ **灵活配置** - 支持项目级配置文件,不同项目不同规范
|
|
42
|
+
- 🎨 **优雅交互** - 友好的命令行界面,支持键盘快捷操作
|
|
43
|
+
- 📦 **轻量依赖** - 打包体积仅 12KB,安装快速无负担
|
|
44
|
+
|
|
45
|
+
## 快速开始
|
|
46
|
+
|
|
47
|
+
### 安装
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# npm
|
|
51
|
+
npm install -g @zjex/git-workflow
|
|
52
|
+
|
|
53
|
+
# pnpm
|
|
54
|
+
pnpm add -g @zjex/git-workflow
|
|
55
|
+
|
|
56
|
+
# yarn
|
|
57
|
+
yarn global add @zjex/git-workflow
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 30 秒上手
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# 创建 feature 分支
|
|
64
|
+
gw f
|
|
65
|
+
# ? 请输入 Story ID (可跳过): PROJ-123
|
|
66
|
+
# ? 请输入描述: add-user-login
|
|
67
|
+
# ✔ 分支创建成功: feature/20260107-PROJ-123-add-user-login
|
|
68
|
+
|
|
69
|
+
# 创建 tag
|
|
70
|
+
gw t
|
|
71
|
+
# ? 选择 tag 前缀: v (最新: v1.2.0)
|
|
72
|
+
# ? 选择版本类型: patch → v1.2.1
|
|
73
|
+
# ✔ Tag 创建成功: v1.2.1
|
|
74
|
+
# ✔ Tag 已推送: v1.2.1
|
|
75
|
+
|
|
76
|
+
# 删除分支
|
|
77
|
+
gw d
|
|
78
|
+
# ? 选择要删除的分支: feature/20260105-old-feature (本地+远程)
|
|
79
|
+
# ✔ 本地分支已删除
|
|
80
|
+
# ✔ 远程分支已删除
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 命令详解
|
|
84
|
+
|
|
85
|
+
### 分支命令
|
|
86
|
+
|
|
87
|
+
| 命令 | 别名 | 说明 |
|
|
88
|
+
| ------------------------------ | ----------------- | ----------------- |
|
|
89
|
+
| `gw feature [--base <branch>]` | `gw feat`, `gw f` | 创建 feature 分支 |
|
|
90
|
+
| `gw hotfix [--base <branch>]` | `gw fix`, `gw h` | 创建 hotfix 分支 |
|
|
91
|
+
| `gw delete [branch]` | `gw del`, `gw d` | 删除本地/远程分支 |
|
|
92
|
+
|
|
93
|
+
#### 创建分支
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# 基于 main/master 创建(自动检测)
|
|
97
|
+
gw f
|
|
98
|
+
|
|
99
|
+
# 基于指定分支创建
|
|
100
|
+
gw f --base develop
|
|
101
|
+
gw fix --base release/1.0
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
分支命名格式:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
feature/YYYYMMDD-<ID>-<描述>
|
|
108
|
+
hotfix/YYYYMMDD-<ID>-<描述>
|
|
109
|
+
|
|
110
|
+
# ID 可跳过
|
|
111
|
+
feature/YYYYMMDD-<描述>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### 删除分支
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# 交互式选择(按最近使用排序)
|
|
118
|
+
gw d
|
|
119
|
+
|
|
120
|
+
# 直接删除指定分支
|
|
121
|
+
gw d feature/20260101-old-feature
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
删除时会自动检测远程分支是否存在,并询问是否一并删除。
|
|
125
|
+
|
|
126
|
+
### Tag 命令
|
|
127
|
+
|
|
128
|
+
| 命令 | 别名 | 说明 |
|
|
129
|
+
| ------------------ | ------- | ------------------------ |
|
|
130
|
+
| `gw tags [prefix]` | `gw ts` | 列出 tag(可按前缀过滤) |
|
|
131
|
+
| `gw tag [prefix]` | `gw t` | 交互式创建 tag |
|
|
132
|
+
|
|
133
|
+
#### 列出 Tag
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# 列出所有 tag
|
|
137
|
+
gw ts
|
|
138
|
+
|
|
139
|
+
# 按前缀过滤
|
|
140
|
+
gw ts v
|
|
141
|
+
gw ts release-
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### 创建 Tag
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# 交互式选择前缀和版本
|
|
148
|
+
gw t
|
|
149
|
+
|
|
150
|
+
# 指定前缀
|
|
151
|
+
gw t v
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
支持的版本类型:
|
|
155
|
+
|
|
156
|
+
| 当前版本 | 可选操作 |
|
|
157
|
+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
158
|
+
| `v1.2.3` | patch → `v1.2.4`<br>minor → `v1.3.0`<br>major → `v2.0.0`<br>alpha → `v1.2.4-alpha.1`<br>beta → `v1.2.4-beta.1`<br>rc → `v1.2.4-rc.1` |
|
|
159
|
+
| `v1.2.4-beta.1` | pre → `v1.2.4-beta.2`<br>release → `v1.2.4`<br>patch/minor/major... |
|
|
160
|
+
|
|
161
|
+
### 版本命令
|
|
162
|
+
|
|
163
|
+
| 命令 | 别名 | 说明 |
|
|
164
|
+
| ------------ | ------ | ----------------------------------- |
|
|
165
|
+
| `gw release` | `gw r` | 交互式选择版本号并更新 package.json |
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
gw r
|
|
169
|
+
# 当前版本: 0.0.1
|
|
170
|
+
# ? 选择新版本:
|
|
171
|
+
# patch → 0.0.2
|
|
172
|
+
# minor → 0.1.0
|
|
173
|
+
# major → 1.0.0
|
|
174
|
+
# alpha → 0.0.2-alpha.1
|
|
175
|
+
# beta → 0.0.2-beta.1
|
|
176
|
+
# rc → 0.0.2-rc.1
|
|
177
|
+
# ✓ 版本号已更新: 0.0.1 → 0.0.2
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 配置命令
|
|
181
|
+
|
|
182
|
+
| 命令 | 说明 |
|
|
183
|
+
| --------- | ------------------------------- |
|
|
184
|
+
| `gw init` | 交互式初始化配置文件 .gwrc.json |
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
gw init
|
|
188
|
+
# 配置 git-workflow,直接回车使用默认值
|
|
189
|
+
# ? 默认基础分支 (留空自动检测 main/master):
|
|
190
|
+
# ? Feature 分支前缀: feature
|
|
191
|
+
# ? Hotfix 分支前缀: hotfix
|
|
192
|
+
# ? 是否要求必填 ID? No
|
|
193
|
+
# ? 默认 Tag 前缀 (留空则每次选择): v
|
|
194
|
+
# ? 创建分支后是否自动推送? 每次询问
|
|
195
|
+
# ✓ 配置已保存到 .gwrc.json
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Stash 命令
|
|
199
|
+
|
|
200
|
+
| 命令 | 别名 | 说明 |
|
|
201
|
+
| ---------- | --------------- | ---------------- |
|
|
202
|
+
| `gw stash` | `gw s`, `gw st` | 交互式管理 stash |
|
|
203
|
+
|
|
204
|
+
原生 `git stash list` 输出难以阅读,`gw stash` 提供清晰的交互式界面:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
gw st
|
|
208
|
+
# 共 3 个 stash:
|
|
209
|
+
#
|
|
210
|
+
# ? 选择 stash:
|
|
211
|
+
# [0] main fix login bug (3 文件) 2 hours ago
|
|
212
|
+
# [1] develop add new feature (5 文件) 1 day ago
|
|
213
|
+
# [2] main WIP (1 文件) 3 days ago
|
|
214
|
+
# + 创建新 stash
|
|
215
|
+
# 取消
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
选择后显示详情并提供操作:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# Stash #0
|
|
222
|
+
# 分支: main
|
|
223
|
+
# 消息: fix login bug
|
|
224
|
+
# 时间: 2 hours ago
|
|
225
|
+
# 文件 (3):
|
|
226
|
+
# • src/auth.ts
|
|
227
|
+
# • src/login.ts
|
|
228
|
+
# • tests/auth.test.ts
|
|
229
|
+
# ────────────────────────────────────────
|
|
230
|
+
# ? 操作:
|
|
231
|
+
# 应用 (保留 stash)
|
|
232
|
+
# 弹出 (应用并删除)
|
|
233
|
+
# 创建分支 <- 复用 feature/hotfix 命名规范
|
|
234
|
+
# 查看差异 <- 查看后返回菜单
|
|
235
|
+
# 删除
|
|
236
|
+
# 返回列表
|
|
237
|
+
# 取消
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
创建 stash 时,如果检测到未跟踪的新文件,会询问是否一并 stash。
|
|
241
|
+
|
|
242
|
+
## 配置文件
|
|
243
|
+
|
|
244
|
+
在项目根目录创建配置文件,可自定义工具行为。不同项目可以有不同配置,满足多样化需求。
|
|
245
|
+
|
|
246
|
+
**支持的文件名:** `.gwrc.json` / `.gwrc` / `gw.config.json`
|
|
247
|
+
|
|
248
|
+
**查找顺序:** 当前目录 → Git 仓库根目录
|
|
249
|
+
|
|
250
|
+
### 完整配置示例
|
|
251
|
+
|
|
252
|
+
```json
|
|
253
|
+
{
|
|
254
|
+
"baseBranch": "develop",
|
|
255
|
+
"featurePrefix": "feature",
|
|
256
|
+
"hotfixPrefix": "hotfix",
|
|
257
|
+
"requireId": true,
|
|
258
|
+
"featureIdLabel": "Story ID",
|
|
259
|
+
"hotfixIdLabel": "Issue ID",
|
|
260
|
+
"defaultTagPrefix": "v",
|
|
261
|
+
"autoPush": true
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### 配置项说明
|
|
266
|
+
|
|
267
|
+
| 配置项 | 类型 | 默认值 | 说明 |
|
|
268
|
+
| ------------------ | --------- | ------------ | ------------------------------------------ |
|
|
269
|
+
| `baseBranch` | `string` | 自动检测 | 默认基础分支,不设置则自动检测 main/master |
|
|
270
|
+
| `featurePrefix` | `string` | `"feature"` | feature 分支前缀 |
|
|
271
|
+
| `hotfixPrefix` | `string` | `"hotfix"` | hotfix 分支前缀 |
|
|
272
|
+
| `requireId` | `boolean` | `false` | 是否要求必填 ID |
|
|
273
|
+
| `featureIdLabel` | `string` | `"Story ID"` | feature 分支 ID 提示文字 |
|
|
274
|
+
| `hotfixIdLabel` | `string` | `"Issue ID"` | hotfix 分支 ID 提示文字 |
|
|
275
|
+
| `defaultTagPrefix` | `string` | - | 默认 tag 前缀,设置后跳过选择步骤 |
|
|
276
|
+
| `autoPush` | `boolean` | - | 创建分支后是否自动推送,不设置则询问 |
|
|
277
|
+
|
|
278
|
+
### 常见配置场景
|
|
279
|
+
|
|
280
|
+
<details>
|
|
281
|
+
<summary><b>场景一:强制要求关联 Issue</b></summary>
|
|
282
|
+
|
|
283
|
+
```json
|
|
284
|
+
{
|
|
285
|
+
"requireId": true,
|
|
286
|
+
"featureIdLabel": "Jira ID",
|
|
287
|
+
"hotfixIdLabel": "Bug ID"
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
</details>
|
|
292
|
+
|
|
293
|
+
<details>
|
|
294
|
+
<summary><b>场景二:基于 develop 分支开发</b></summary>
|
|
295
|
+
|
|
296
|
+
```json
|
|
297
|
+
{
|
|
298
|
+
"baseBranch": "develop",
|
|
299
|
+
"autoPush": true
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
</details>
|
|
304
|
+
|
|
305
|
+
<details>
|
|
306
|
+
<summary><b>场景三:自定义分支前缀</b></summary>
|
|
307
|
+
|
|
308
|
+
```json
|
|
309
|
+
{
|
|
310
|
+
"featurePrefix": "feat",
|
|
311
|
+
"hotfixPrefix": "fix"
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
</details>
|
|
316
|
+
|
|
317
|
+
## 最佳实践
|
|
318
|
+
|
|
319
|
+
### 团队协作
|
|
320
|
+
|
|
321
|
+
1. **统一配置** - 将 `.gwrc.json` 提交到仓库,确保团队使用相同的分支规范
|
|
322
|
+
2. **强制 ID** - 开启 `requireId`,确保每个分支都能追溯到需求/Issue
|
|
323
|
+
3. **自动推送** - 开启 `autoPush`,减少遗忘推送的情况
|
|
324
|
+
|
|
325
|
+
### 版本发布
|
|
326
|
+
|
|
327
|
+
1. **预发布测试** - 使用 alpha/beta/rc 版本进行测试
|
|
328
|
+
2. **语义化版本** - 遵循 semver 规范,bug 修复用 patch,新功能用 minor,破坏性变更用 major
|
|
329
|
+
|
|
330
|
+
### 分支清理
|
|
331
|
+
|
|
332
|
+
定期使用 `gw d` 清理已合并的分支,保持仓库整洁。
|
|
333
|
+
|
|
334
|
+
## 与其他工具对比
|
|
335
|
+
|
|
336
|
+
| 特性 | git-workflow | git-flow | 手动操作 |
|
|
337
|
+
| ------------ | ------------- | ----------- | --------- |
|
|
338
|
+
| 学习成本 | ⭐ 极低 | ⭐⭐⭐ 较高 | ⭐⭐ 中等 |
|
|
339
|
+
| 分支命名规范 | ✅ 自动生成 | ❌ 需手动 | ❌ 需手动 |
|
|
340
|
+
| 版本号管理 | ✅ 智能递增 | ❌ 需手动 | ❌ 需手动 |
|
|
341
|
+
| 交互式操作 | ✅ 支持 | ❌ 不支持 | ❌ 不支持 |
|
|
342
|
+
| 配置灵活性 | ✅ 项目级配置 | ⚠️ 有限 | - |
|
|
343
|
+
| 远程分支同步 | ✅ 自动处理 | ⚠️ 部分 | ❌ 需手动 |
|
|
344
|
+
|
|
345
|
+
## 开发
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
# 克隆仓库
|
|
349
|
+
git clone https://github.com/iamzjt-front-end/git-workflow.git
|
|
350
|
+
cd git-workflow
|
|
351
|
+
|
|
352
|
+
# 安装依赖
|
|
353
|
+
npm install
|
|
354
|
+
|
|
355
|
+
# 开发模式
|
|
356
|
+
npm run dev
|
|
357
|
+
|
|
358
|
+
# 构建
|
|
359
|
+
npm run build
|
|
360
|
+
|
|
361
|
+
# 本地测试
|
|
362
|
+
npm link
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## 贡献
|
|
366
|
+
|
|
367
|
+
欢迎提交 Issue 和 Pull Request!
|
|
368
|
+
|
|
369
|
+
## License
|
|
370
|
+
|
|
371
|
+
[MIT](./LICENSE) License © 2026
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
<p align="center">
|
|
376
|
+
如果这个工具对你有帮助,请给个 ⭐️ 支持一下!
|
|
377
|
+
</p>
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node --no-warnings
|
|
2
|
+
import{cac as Ne}from"cac";import{execSync as M}from"child_process";var o={red:e=>`\x1B[31m${e}\x1B[0m`,green:e=>`\x1B[32m${e}\x1B[0m`,yellow:e=>`\x1B[33m${e}\x1B[0m`,dim:e=>`\x1B[2m${e}\x1B[0m`},T=new Date().toISOString().slice(0,10).replace(/-/g,""),c={helpMode:"always",style:{keysHelpTip:e=>`\x1B[2m${e.map(([n,t])=>`${n} ${t}`).join(" \u2022 ")} \u2022 Ctrl+C quit\x1B[0m`}};function I(e,a=!1){try{return M(e,{encoding:"utf-8",stdio:a?"pipe":"inherit"})}catch(n){if(a)return"";throw n}}function h(e){try{return M(e,{encoding:"utf-8"}).trim()}catch{return""}}function P(){try{M("git rev-parse --is-inside-work-tree",{stdio:"pipe"})}catch{console.log(o.red("\u9519\u8BEF: \u5F53\u524D\u76EE\u5F55\u4E0D\u662F git \u4ED3\u5E93")),process.exit(1)}}function z(){let e=h("git branch -r").split(`
|
|
3
|
+
`).map(a=>a.trim());return e.includes("origin/main")?"origin/main":e.includes("origin/master")?"origin/master":"origin/main"}function d(){console.log(o.dim("\u2500".repeat(40)))}import{execSync as R}from"child_process";import{select as E,input as Z}from"@inquirer/prompts";import C from"ora";import{existsSync as K,readFileSync as me}from"fs";import{join as he}from"path";var A={featurePrefix:"feature",hotfixPrefix:"hotfix",requireId:!1,featureIdLabel:"Story ID",hotfixIdLabel:"Issue ID"};function pe(){return h("git rev-parse --show-toplevel")}function $e(){let e=[".gwrc.json",".gwrc","gw.config.json"];for(let a of e)if(K(a))return a;try{let a=pe();if(a)for(let n of e){let t=he(a,n);if(K(t))return t}}catch{}return null}function de(){let e=$e();if(!e)return A;try{let a=me(e,"utf-8"),n=JSON.parse(a);return{...A,...n}}catch{return console.warn(`\u914D\u7F6E\u6587\u4EF6\u89E3\u6790\u5931\u8D25: ${e}`),A}}var H=null;function N(){return H||(H=de()),H}async function W(e){let a=N(),n=e==="feature"?a.featureIdLabel:a.hotfixIdLabel,t=e==="feature"?a.featurePrefix:a.hotfixPrefix,r=a.requireId?`\u8BF7\u8F93\u5165${n}:`:`\u8BF7\u8F93\u5165${n} (\u53EF\u8DF3\u8FC7):`,l=await Z({message:r,theme:c});if(a.requireId&&!l)return console.log(o.red(`${n}\u4E0D\u80FD\u4E3A\u7A7A`)),null;let i=await Z({message:"\u8BF7\u8F93\u5165\u63CF\u8FF0:",theme:c});return i?l?`${t}/${T}-${l}-${i}`:`${t}/${T}-${i}`:(console.log(o.red("\u63CF\u8FF0\u4E0D\u80FD\u4E3A\u7A7A")),null)}async function J(e,a){let n=N(),t=await W(e);if(!t)return;d();let r;a?r=`origin/${a}`:n.baseBranch?r=`origin/${n.baseBranch}`:r=z();let l=C(`\u6B63\u5728\u4ECE ${r} \u521B\u5EFA\u5206\u652F...`).start();try{I(`git fetch origin ${r.replace("origin/","")}`,!0),I(`git checkout -b "${t}" ${r}`),l.succeed(`\u5206\u652F\u521B\u5EFA\u6210\u529F: ${t}`),d();let i;if(n.autoPush!==void 0?(i=n.autoPush,i&&console.log(o.dim("(\u81EA\u52A8\u63A8\u9001\u5DF2\u542F\u7528)"))):i=await E({message:"\u662F\u5426\u63A8\u9001\u5230\u8FDC\u7A0B?",choices:[{name:"\u662F",value:!0},{name:"\u5426",value:!1}],theme:c}),i){let g=C("\u6B63\u5728\u63A8\u9001\u5230\u8FDC\u7A0B...").start();try{R(`git push -u origin "${t}"`,{stdio:"pipe"}),g.succeed(`\u5DF2\u63A8\u9001\u5230\u8FDC\u7A0B: origin/${t}`)}catch{g.warn("\u8FDC\u7A0B\u63A8\u9001\u5931\u8D25\uFF0C\u53EF\u7A0D\u540E\u624B\u52A8\u6267\u884C: git push -u origin "+t)}}}catch{l.fail("\u5206\u652F\u521B\u5EFA\u5931\u8D25")}}async function Q(e){let a=C("\u6B63\u5728\u83B7\u53D6\u5206\u652F\u4FE1\u606F...").start();I("git fetch --all --prune",!0),a.succeed("\u5206\u652F\u4FE1\u606F\u5DF2\u66F4\u65B0"),d();let n=h("git branch --show-current"),t=e;if(!t){let g=h("git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)'").split(`
|
|
4
|
+
`).filter(u=>u&&u!==n);if(g.length===0){console.log(o.yellow("\u6CA1\u6709\u53EF\u5220\u9664\u7684\u672C\u5730\u5206\u652F"));return}let s=g.map(u=>({name:h(`git branch -r | grep "origin/${u}$"`)?`${u} (\u672C\u5730+\u8FDC\u7A0B)`:`${u} (\u4EC5\u672C\u5730)`,value:u}));if(s.push({name:"\u53D6\u6D88",value:"__cancel__"}),t=await E({message:"\u9009\u62E9\u8981\u5220\u9664\u7684\u5206\u652F (\u6309\u6700\u8FD1\u4F7F\u7528\u6392\u5E8F):",choices:s,theme:c}),t==="__cancel__"){console.log(o.yellow("\u5DF2\u53D6\u6D88"));return}}if(t===n){console.log(o.red("\u4E0D\u80FD\u5220\u9664\u5F53\u524D\u6240\u5728\u5206\u652F"));return}let r=h(`git branch --list "${t}"`),l=h(`git branch -r | grep "origin/${t}$"`);if(!r){if(l){if(console.log(o.yellow(`\u672C\u5730\u5206\u652F\u4E0D\u5B58\u5728\uFF0C\u4F46\u8FDC\u7A0B\u5206\u652F\u5B58\u5728: origin/${t}`)),await E({message:`\u662F\u5426\u5220\u9664\u8FDC\u7A0B\u5206\u652F origin/${t}?`,choices:[{name:"\u662F",value:!0},{name:"\u5426",value:!1}],theme:c})){let s=C(`\u6B63\u5728\u5220\u9664\u8FDC\u7A0B\u5206\u652F: origin/${t}`).start();try{R(`git push origin --delete "${t}"`,{stdio:"pipe"}),s.succeed(`\u8FDC\u7A0B\u5206\u652F\u5DF2\u5220\u9664: origin/${t}`)}catch{s.fail("\u8FDC\u7A0B\u5206\u652F\u5220\u9664\u5931\u8D25")}}}else console.log(o.red(`\u5206\u652F\u4E0D\u5B58\u5728: ${t}`));return}let i=C(`\u6B63\u5728\u5220\u9664\u672C\u5730\u5206\u652F: ${t}`).start();try{R(`git branch -D "${t}"`,{stdio:"pipe"}),i.succeed(`\u672C\u5730\u5206\u652F\u5DF2\u5220\u9664: ${t}`)}catch{i.fail("\u672C\u5730\u5206\u652F\u5220\u9664\u5931\u8D25");return}if(l&&(d(),await E({message:`\u662F\u5426\u540C\u65F6\u5220\u9664\u8FDC\u7A0B\u5206\u652F origin/${t}?`,choices:[{name:"\u662F",value:!0},{name:"\u5426",value:!1}],theme:c}))){let s=C(`\u6B63\u5728\u5220\u9664\u8FDC\u7A0B\u5206\u652F: origin/${t}`).start();try{R(`git push origin --delete "${t}"`,{stdio:"pipe"}),s.succeed(`\u8FDC\u7A0B\u5206\u652F\u5DF2\u5220\u9664: origin/${t}`)}catch{s.fail("\u8FDC\u7A0B\u5206\u652F\u5220\u9664\u5931\u8D25")}}}import{execSync as X}from"child_process";import{select as U,input as ee}from"@inquirer/prompts";import L from"ora";async function ae(e){let a=L("\u6B63\u5728\u83B7\u53D6 tags...").start();I("git fetch --tags",!0),a.stop();let n=e?`${e}*`:"",t=h(`git tag -l ${n} --sort=-v:refname`).split(`
|
|
5
|
+
`).filter(Boolean);if(t.length===0){console.log(o.yellow(e?`\u6CA1\u6709 '${e}' \u5F00\u5934\u7684 tag`:"\u6CA1\u6709 tag"));return}console.log(o.green(e?`\u4EE5 '${e}' \u5F00\u5934\u7684 tags:`:"\u6240\u6709 tags:")),t.slice(0,20).forEach(r=>console.log(` ${r}`)),t.length>20&&console.log(o.yellow(`
|
|
6
|
+
\u5171 ${t.length} \u4E2A\uFF0C\u4EC5\u663E\u793A\u524D 20 \u4E2A`))}async function ne(e){let a=N(),n=L("\u6B63\u5728\u83B7\u53D6 tags...").start();I("git fetch --tags",!0),n.stop(),d();let t=e;if(!t&&a.defaultTagPrefix&&(t=a.defaultTagPrefix,console.log(o.dim(`(\u4F7F\u7528\u914D\u7F6E\u7684\u9ED8\u8BA4\u524D\u7F00: ${t})`))),!t){let $=h("git tag -l").split(`
|
|
7
|
+
`).filter(Boolean),v=[...new Set($.map(x=>x.replace(/[0-9].*/,"")).filter(Boolean))];if(v.length===0){if(t=await ee({message:"\u5F53\u524D\u4ED3\u5E93\u6CA1\u6709 tag\uFF0C\u8BF7\u8F93\u5165\u65B0\u524D\u7F00 (\u5982 v):",theme:c}),!t){console.log(o.yellow("\u5DF2\u53D6\u6D88"));return}}else{let x=v.map(p=>{let f=h(`git tag -l "${p}*" --sort=-v:refname | head -1`),_=f?h(`git log -1 --format=%ct "${f}" 2>/dev/null`):"0";return{prefix:p,latest:f,date:parseInt(_)||0}});x.sort((p,f)=>f.date-p.date);let m=x.map(({prefix:p,latest:f})=>({name:`${p} (\u6700\u65B0: ${f})`,value:p}));if(m.push({name:"\u8F93\u5165\u65B0\u524D\u7F00...",value:"__new__"}),t=await U({message:"\u9009\u62E9 tag \u524D\u7F00:",choices:m,theme:c}),t==="__new__"&&(t=await ee({message:"\u8BF7\u8F93\u5165\u65B0\u524D\u7F00:",theme:c}),!t)){console.log(o.yellow("\u5DF2\u53D6\u6D88"));return}}}let r=h(`git tag -l "${t}*" --sort=-v:refname | head -1`);if(!r){let $=`${t}1.0.0`;console.log(o.yellow(`\u672A\u627E\u5230 '${t}' \u5F00\u5934\u7684 tag\uFF0C\u5C06\u521B\u5EFA ${$}`)),await U({message:`\u786E\u8BA4\u521B\u5EFA ${$}?`,choices:[{name:"\u662F",value:!0},{name:"\u5426",value:!1}],theme:c})&&te($);return}console.log(o.yellow(`\u5F53\u524D\u6700\u65B0 tag: ${r}`)),d();let l=r.slice(t.length),i=l.match(/^(\d+)\.(\d+)\.(\d+)-([a-zA-Z]+)\.(\d+)$/),g=l.match(/^(\d+)\.(\d+)\.(\d+)$/),s=l.match(/^(\d+)\.(\d+)$/),u=l.match(/^(\d+)$/),w=[];if(i){let[,$,v,x,m,p]=i,f=Number($),_=Number(v),q=Number(x),Y=Number(p),O=`${f}.${_}.${q}`;w=[{name:`pre \u2192 ${t}${O}-${m}.${Y+1}`,value:`${t}${O}-${m}.${Y+1}`},{name:`release\u2192 ${t}${O}`,value:`${t}${O}`},{name:`patch \u2192 ${t}${f}.${_}.${q+1}`,value:`${t}${f}.${_}.${q+1}`},{name:`minor \u2192 ${t}${f}.${_+1}.0`,value:`${t}${f}.${_+1}.0`},{name:`major \u2192 ${t}${f+1}.0.0`,value:`${t}${f+1}.0.0`}]}else if(g){let[,$,v,x]=g,m=Number($),p=Number(v),f=Number(x);w=[{name:`patch \u2192 ${t}${m}.${p}.${f+1}`,value:`${t}${m}.${p}.${f+1}`},{name:`minor \u2192 ${t}${m}.${p+1}.0`,value:`${t}${m}.${p+1}.0`},{name:`major \u2192 ${t}${m+1}.0.0`,value:`${t}${m+1}.0.0`},{name:`alpha \u2192 ${t}${m}.${p}.${f+1}-alpha.1`,value:`${t}${m}.${p}.${f+1}-alpha.1`},{name:`beta \u2192 ${t}${m}.${p}.${f+1}-beta.1`,value:`${t}${m}.${p}.${f+1}-beta.1`},{name:`rc \u2192 ${t}${m}.${p}.${f+1}-rc.1`,value:`${t}${m}.${p}.${f+1}-rc.1`}]}else if(s){let[,$,v]=s,x=Number($),m=Number(v);w=[{name:`minor \u2192 ${t}${x}.${m+1}`,value:`${t}${x}.${m+1}`},{name:`major \u2192 ${t}${x+1}.0`,value:`${t}${x+1}.0`}]}else if(u){let $=Number(u[1]);w=[{name:`next \u2192 ${t}${$+1}`,value:`${t}${$+1}`}]}else{console.log(o.red(`\u65E0\u6CD5\u89E3\u6790\u7248\u672C\u53F7: ${l}`));return}w.push({name:"\u53D6\u6D88",value:"__cancel__"});let k=await U({message:"\u9009\u62E9\u7248\u672C\u7C7B\u578B:",choices:w,theme:c});if(k==="__cancel__"){console.log(o.yellow("\u5DF2\u53D6\u6D88"));return}te(k)}function te(e){d();let a=L(`\u6B63\u5728\u521B\u5EFA tag: ${e}`).start();try{X(`git tag -a "${e}" -m "Release ${e}"`,{stdio:"pipe"}),a.succeed(`Tag \u521B\u5EFA\u6210\u529F: ${e}`)}catch{a.fail("tag \u521B\u5EFA\u5931\u8D25");return}let n=L("\u6B63\u5728\u63A8\u9001\u5230\u8FDC\u7A0B...").start();try{X(`git push origin "${e}"`,{stdio:"pipe"}),n.succeed(`Tag \u5DF2\u63A8\u9001: ${e}`)}catch{n.warn(`\u8FDC\u7A0B\u63A8\u9001\u5931\u8D25\uFF0C\u53EF\u7A0D\u540E\u624B\u52A8\u6267\u884C: git push origin ${e}`)}}import{readFileSync as oe,writeFileSync as we}from"fs";import{select as xe}from"@inquirer/prompts";function be(){return JSON.parse(oe("package.json","utf-8")).version||"0.0.0"}function ve(e){let a=JSON.parse(oe("package.json","utf-8"));a.version=e,we("package.json",JSON.stringify(a,null," ")+`
|
|
8
|
+
`)}function ye(e){let a=e.match(/^(\d+)\.(\d+)\.(\d+)-([a-zA-Z]+)\.(\d+)$/),n=e.match(/^(\d+)\.(\d+)\.(\d+)$/);if(a){let[,t,r,l,i,g]=a,s=Number(t),u=Number(r),w=Number(l),k=Number(g),$=`${s}.${u}.${w}`;return[{name:`pre \u2192 ${$}-${i}.${k+1}`,value:`${$}-${i}.${k+1}`},{name:`release \u2192 ${$}`,value:$},{name:`patch \u2192 ${s}.${u}.${w+1}`,value:`${s}.${u}.${w+1}`},{name:`minor \u2192 ${s}.${u+1}.0`,value:`${s}.${u+1}.0`},{name:`major \u2192 ${s+1}.0.0`,value:`${s+1}.0.0`}]}if(n){let[,t,r,l]=n,i=Number(t),g=Number(r),s=Number(l);return[{name:`patch \u2192 ${i}.${g}.${s+1}`,value:`${i}.${g}.${s+1}`},{name:`minor \u2192 ${i}.${g+1}.0`,value:`${i}.${g+1}.0`},{name:`major \u2192 ${i+1}.0.0`,value:`${i+1}.0.0`},{name:`alpha \u2192 ${i}.${g}.${s+1}-alpha.1`,value:`${i}.${g}.${s+1}-alpha.1`},{name:`beta \u2192 ${i}.${g}.${s+1}-beta.1`,value:`${i}.${g}.${s+1}-beta.1`},{name:`rc \u2192 ${i}.${g}.${s+1}-rc.1`,value:`${i}.${g}.${s+1}-rc.1`}]}return[{name:"patch \u2192 0.0.1",value:"0.0.1"},{name:"minor \u2192 0.1.0",value:"0.1.0"},{name:"major \u2192 1.0.0",value:"1.0.0"}]}async function se(){let e=be();console.log(o.yellow(`\u5F53\u524D\u7248\u672C: ${e}`)),d();let a=ye(e);a.push({name:"\u53D6\u6D88",value:"__cancel__"});let n=await xe({message:"\u9009\u62E9\u65B0\u7248\u672C:",choices:a,theme:c});if(n==="__cancel__"){console.log(o.yellow("\u5DF2\u53D6\u6D88"));return}ve(n),d(),console.log(o.green(`\u2713 \u7248\u672C\u53F7\u5DF2\u66F4\u65B0: ${e} \u2192 ${n}`))}import{existsSync as Se,writeFileSync as _e}from"fs";import{select as Ie,input as B,confirm as re}from"@inquirer/prompts";var G=".gwrc.json";async function ie(){if(Se(G)&&!await re({message:`${G} \u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u8986\u76D6?`,default:!1,theme:c})){console.log(o.yellow("\u5DF2\u53D6\u6D88"));return}console.log(o.dim(`\u914D\u7F6E git-workflow\uFF0C\u76F4\u63A5\u56DE\u8F66\u4F7F\u7528\u9ED8\u8BA4\u503C
|
|
9
|
+
`));let e={},a=await B({message:"\u9ED8\u8BA4\u57FA\u7840\u5206\u652F (\u7559\u7A7A\u81EA\u52A8\u68C0\u6D4B main/master):",theme:c});a&&(e.baseBranch=a),d();let n=await B({message:"Feature \u5206\u652F\u524D\u7F00:",default:"feature",theme:c});n!=="feature"&&(e.featurePrefix=n);let t=await B({message:"Hotfix \u5206\u652F\u524D\u7F00:",default:"hotfix",theme:c});t!=="hotfix"&&(e.hotfixPrefix=t),d(),await re({message:"\u662F\u5426\u8981\u6C42\u5FC5\u586B ID (Story ID / Issue ID)?",default:!1,theme:c})&&(e.requireId=!0);let l=await B({message:"Feature \u5206\u652F ID \u6807\u7B7E:",default:"Story ID",theme:c});l!=="Story ID"&&(e.featureIdLabel=l);let i=await B({message:"Hotfix \u5206\u652F ID \u6807\u7B7E:",default:"Issue ID",theme:c});i!=="Issue ID"&&(e.hotfixIdLabel=i),d();let g=await B({message:"\u9ED8\u8BA4 Tag \u524D\u7F00 (\u7559\u7A7A\u5219\u6BCF\u6B21\u9009\u62E9):",theme:c});g&&(e.defaultTagPrefix=g);let s=await Ie({message:"\u521B\u5EFA\u5206\u652F\u540E\u662F\u5426\u81EA\u52A8\u63A8\u9001?",choices:[{name:"\u6BCF\u6B21\u8BE2\u95EE",value:"ask"},{name:"\u81EA\u52A8\u63A8\u9001",value:"yes"},{name:"\u4E0D\u63A8\u9001",value:"no"}],theme:c});s==="yes"&&(e.autoPush=!0),s==="no"&&(e.autoPush=!1),d();let u=JSON.stringify(e,null,2);_e(G,u+`
|
|
10
|
+
`),console.log(o.green(`\u2713 \u914D\u7F6E\u5DF2\u4FDD\u5B58\u5230 ${G}`)),console.log(o.dim(`
|
|
11
|
+
`+u))}import{execSync as D}from"child_process";import{select as j,input as ge}from"@inquirer/prompts";import F from"ora";function Pe(){let e=h('git stash list --format="%gd|%s|%ar"');return e?e.split(`
|
|
12
|
+
`).filter(Boolean).map(a=>{let[n,t,r]=a.split("|"),l=parseInt(n.match(/stash@\{(\d+)\}/)?.[1]||"0"),g=t.match(/(?:WIP on|On) ([^:]+):/)?.[1]||"unknown",s=t.replace(/(?:WIP on|On) [^:]+:\s*/,"");t.startsWith("WIP")&&(s=s.replace(/^[a-f0-9]+ /,"")),s=s||"(no message)";let u=h(`git stash show stash@{${l}} --name-only 2>/dev/null`),w=u?u.split(`
|
|
13
|
+
`).filter(Boolean):[];return{index:l,branch:g,message:s,date:r,files:w}}):[]}function Te(e){let a=e.files.length,n=a>0?o.dim(` (${a} \u6587\u4EF6)`):"";return`${o.yellow(`[${e.index}]`)} ${o.green(e.branch)} ${e.message}${n} ${o.dim(e.date)}`}function Ce(e){console.log(),console.log(o.yellow(`Stash #${e.index}`)),console.log(`\u5206\u652F: ${o.green(e.branch)}`),console.log(`\u6D88\u606F: ${e.message}`),console.log(`\u65F6\u95F4: ${o.dim(e.date)}`),e.files.length>0&&(console.log(`\u6587\u4EF6 (${e.files.length}):`),e.files.slice(0,10).forEach(a=>console.log(` ${o.dim("\u2022")} ${a}`)),e.files.length>10&&console.log(o.dim(` ... \u8FD8\u6709 ${e.files.length-10} \u4E2A\u6587\u4EF6`)))}async function V(){let e=Pe();if(e.length===0){console.log(o.yellow("\u6CA1\u6709 stash \u8BB0\u5F55")),h("git status --porcelain")&&await j({message:"\u68C0\u6D4B\u5230\u672A\u63D0\u4EA4\u7684\u53D8\u66F4\uFF0C\u662F\u5426\u521B\u5EFA stash?",choices:[{name:"\u662F",value:!0},{name:"\u5426",value:!1}],theme:c})&&await ce();return}console.log(o.green(`\u5171 ${e.length} \u4E2A stash:
|
|
14
|
+
`));let a=e.map(r=>({name:Te(r),value:r.index.toString()}));a.push({name:o.dim("+ \u521B\u5EFA\u65B0 stash"),value:"__new__"}),a.push({name:o.dim("\u53D6\u6D88"),value:"__cancel__"});let n=await j({message:"\u9009\u62E9 stash:",choices:a,theme:c});if(n==="__cancel__")return;if(n==="__new__"){await ce();return}let t=e.find(r=>r.index.toString()===n);await fe(t)}async function fe(e){switch(Ce(e),d(),await j({message:"\u64CD\u4F5C:",choices:[{name:"\u5E94\u7528 (\u4FDD\u7559 stash)",value:"apply"},{name:"\u5F39\u51FA (\u5E94\u7528\u5E76\u5220\u9664)",value:"pop"},{name:"\u521B\u5EFA\u5206\u652F",value:"branch"},{name:"\u67E5\u770B\u5DEE\u5F02",value:"diff"},{name:"\u5220\u9664",value:"drop"},{name:"\u8FD4\u56DE\u5217\u8868",value:"back"},{name:"\u53D6\u6D88",value:"cancel"}],theme:c})){case"apply":le(e.index,!1);break;case"pop":le(e.index,!0);break;case"branch":await je(e.index);break;case"diff":await Be(e.index),await fe(e);break;case"drop":await ke(e.index);break;case"back":await V();break}}async function ce(){let e=h("git status --porcelain");if(!e){console.log(o.yellow("\u6CA1\u6709\u9700\u8981 stash \u7684\u53D8\u66F4"));return}let a=e.split(`
|
|
15
|
+
`).some(l=>l.startsWith("??")),n=!1;a&&(n=await j({message:"\u68C0\u6D4B\u5230\u672A\u8DDF\u8E2A\u7684\u6587\u4EF6\uFF0C\u662F\u5426\u4E00\u5E76 stash?",choices:[{name:"\u662F (\u5305\u542B\u672A\u8DDF\u8E2A\u6587\u4EF6)",value:!0},{name:"\u5426 (\u4EC5\u5DF2\u8DDF\u8E2A\u6587\u4EF6)",value:!1}],theme:c}));let t=await ge({message:"Stash \u6D88\u606F (\u53EF\u9009):",theme:c}),r=F("\u521B\u5EFA stash...").start();try{let l="git stash push";n&&(l+=" -u"),t&&(l+=` -m "${t.replace(/"/g,'\\"')}"`),D(l,{stdio:"pipe"}),r.succeed("Stash \u521B\u5EFA\u6210\u529F"),await V()}catch{r.fail("Stash \u521B\u5EFA\u5931\u8D25")}}function le(e,a){let n=a?"pop":"apply",t=F(`${a?"\u5F39\u51FA":"\u5E94\u7528"} stash...`).start();try{D(`git stash ${n} stash@{${e}}`,{stdio:"pipe"}),t.succeed(`Stash ${a?"\u5DF2\u5F39\u51FA":"\u5DF2\u5E94\u7528"}`)}catch{t.fail("\u64CD\u4F5C\u5931\u8D25\uFF0C\u53EF\u80FD\u5B58\u5728\u51B2\u7A81");let r=h("git status --porcelain");(r.includes("UU")||r.includes("AA"))&&console.log(o.yellow(`
|
|
16
|
+
\u5B58\u5728\u51B2\u7A81\uFF0C\u8BF7\u624B\u52A8\u89E3\u51B3\u540E\u63D0\u4EA4`))}}async function Be(e){try{D(`git stash show -p --color=always stash@{${e}}`,{stdio:"inherit"}),console.log(),await ge({message:o.dim("\u6309 Enter \u8FD4\u56DE\u83DC\u5355..."),theme:c})}catch{console.log(o.red("\u65E0\u6CD5\u663E\u793A\u5DEE\u5F02"))}}async function je(e){let a=await j({message:"\u9009\u62E9\u5206\u652F\u7C7B\u578B:",choices:[{name:"feature",value:"feature"},{name:"hotfix",value:"hotfix"},{name:"\u53D6\u6D88",value:"__cancel__"}],theme:c});if(a==="__cancel__"){console.log(o.yellow("\u5DF2\u53D6\u6D88"));return}let n=await W(a);if(!n)return;let t=F(`\u521B\u5EFA\u5206\u652F ${n}...`).start();try{D(`git stash branch "${n}" stash@{${e}}`,{stdio:"pipe"}),t.succeed(`\u5206\u652F\u5DF2\u521B\u5EFA: ${n} (stash \u5DF2\u81EA\u52A8\u5F39\u51FA)`)}catch{t.fail("\u521B\u5EFA\u5206\u652F\u5931\u8D25")}}async function ke(e){if(!await j({message:`\u786E\u8BA4\u5220\u9664 stash@{${e}}?`,choices:[{name:"\u662F",value:!0},{name:"\u5426",value:!1}],theme:c})){console.log(o.yellow("\u5DF2\u53D6\u6D88"));return}let n=F("\u5220\u9664 stash...").start();try{D(`git stash drop stash@{${e}}`,{stdio:"pipe"}),n.succeed("Stash \u5DF2\u5220\u9664")}catch{n.fail("\u5220\u9664\u5931\u8D25")}}function ue(){return`
|
|
17
|
+
\u5206\u652F\u547D\u4EE4:
|
|
18
|
+
gw feature [--base <branch>] \u521B\u5EFA feature \u5206\u652F
|
|
19
|
+
gw feat [--base <branch>] \u540C\u4E0A (\u7B80\u5199)
|
|
20
|
+
gw f [--base <branch>] \u540C\u4E0A (\u7B80\u5199)
|
|
21
|
+
|
|
22
|
+
gw hotfix [--base <branch>] \u521B\u5EFA hotfix \u5206\u652F
|
|
23
|
+
gw fix [--base <branch>] \u540C\u4E0A (\u7B80\u5199)
|
|
24
|
+
gw h [--base <branch>] \u540C\u4E0A (\u7B80\u5199)
|
|
25
|
+
|
|
26
|
+
gw delete [branch] \u5220\u9664\u672C\u5730/\u8FDC\u7A0B\u5206\u652F
|
|
27
|
+
gw del [branch] \u540C\u4E0A (\u7B80\u5199)
|
|
28
|
+
gw d [branch] \u540C\u4E0A (\u7B80\u5199)
|
|
29
|
+
|
|
30
|
+
Tag \u547D\u4EE4:
|
|
31
|
+
gw tags [prefix] \u5217\u51FA\u6240\u6709 tag\uFF0C\u53EF\u6309\u524D\u7F00\u8FC7\u6EE4
|
|
32
|
+
gw ts [prefix] \u540C\u4E0A (\u7B80\u5199)
|
|
33
|
+
|
|
34
|
+
gw tag [prefix] \u4EA4\u4E92\u5F0F\u9009\u62E9\u7248\u672C\u7C7B\u578B\u5E76\u521B\u5EFA tag
|
|
35
|
+
gw t [prefix] \u540C\u4E0A (\u7B80\u5199)
|
|
36
|
+
|
|
37
|
+
\u53D1\u5E03\u547D\u4EE4:
|
|
38
|
+
gw release \u4EA4\u4E92\u5F0F\u9009\u62E9\u7248\u672C\u53F7\u5E76\u66F4\u65B0 package.json
|
|
39
|
+
gw r \u540C\u4E0A (\u7B80\u5199)
|
|
40
|
+
|
|
41
|
+
\u914D\u7F6E\u547D\u4EE4:
|
|
42
|
+
gw init \u521D\u59CB\u5316\u914D\u7F6E\u6587\u4EF6 .gwrc.json
|
|
43
|
+
|
|
44
|
+
Stash \u547D\u4EE4:
|
|
45
|
+
gw stash \u4EA4\u4E92\u5F0F\u7BA1\u7406 stash
|
|
46
|
+
gw s \u540C\u4E0A (\u7B80\u5199)
|
|
47
|
+
|
|
48
|
+
\u793A\u4F8B:
|
|
49
|
+
gw feat \u57FA\u4E8E main/master \u521B\u5EFA feature \u5206\u652F
|
|
50
|
+
gw feat --base develop \u57FA\u4E8E develop \u5206\u652F\u521B\u5EFA feature \u5206\u652F
|
|
51
|
+
gw fix --base release \u57FA\u4E8E release \u5206\u652F\u521B\u5EFA hotfix \u5206\u652F
|
|
52
|
+
gw del \u4EA4\u4E92\u5F0F\u9009\u62E9\u5E76\u5220\u9664\u5206\u652F
|
|
53
|
+
gw del feature/xxx \u76F4\u63A5\u5220\u9664\u6307\u5B9A\u5206\u652F
|
|
54
|
+
gw tags v \u5217\u51FA\u6240\u6709 v \u5F00\u5934\u7684 tag
|
|
55
|
+
gw tag \u4EA4\u4E92\u5F0F\u521B\u5EFA tag
|
|
56
|
+
|
|
57
|
+
\u5206\u652F\u547D\u540D\u683C\u5F0F:
|
|
58
|
+
feature/${T}-<Story ID>-<\u63CF\u8FF0>
|
|
59
|
+
hotfix/${T}-<Issue ID>-<\u63CF\u8FF0>
|
|
60
|
+
`}var b=Ne("gw");b.command("feature","\u521B\u5EFA feature \u5206\u652F").alias("feat").alias("f").option("--base <branch>","\u6307\u5B9A\u57FA\u7840\u5206\u652F").action(e=>(P(),J("feature",e.base)));b.command("hotfix","\u521B\u5EFA hotfix \u5206\u652F").alias("fix").alias("h").option("--base <branch>","\u6307\u5B9A\u57FA\u7840\u5206\u652F").action(e=>(P(),J("hotfix",e.base)));b.command("delete [branch]","\u5220\u9664\u672C\u5730/\u8FDC\u7A0B\u5206\u652F").alias("del").alias("d").action(e=>(P(),Q(e)));b.command("tags [prefix]","\u5217\u51FA\u6240\u6709 tag\uFF0C\u53EF\u6309\u524D\u7F00\u8FC7\u6EE4").alias("ts").action(e=>(P(),ae(e)));b.command("tag [prefix]","\u4EA4\u4E92\u5F0F\u9009\u62E9\u7248\u672C\u7C7B\u578B\u5E76\u521B\u5EFA tag").alias("t").action(e=>(P(),ne(e)));b.command("release","\u4EA4\u4E92\u5F0F\u9009\u62E9\u7248\u672C\u53F7\u5E76\u66F4\u65B0 package.json").alias("r").action(()=>se());b.command("init","\u521D\u59CB\u5316\u914D\u7F6E\u6587\u4EF6 .gwrc.json").action(()=>ie());b.command("stash","\u4EA4\u4E92\u5F0F\u7BA1\u7406 stash").alias("s").alias("st").action(()=>(P(),V()));b.help(e=>{e.push({body:ue()})});b.version("0.0.1");b.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zjex/git-workflow",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "个人常用的 Git 工作流工具,快速创建规范的开发分支和管理 Tag",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"git-flow": "./dist/index.js",
|
|
8
|
+
"gw": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup",
|
|
15
|
+
"dev": "tsx src/index.ts",
|
|
16
|
+
"changelog": "changelogen -o CHANGELOG.md",
|
|
17
|
+
"publish:npm": "npm run build && npm run changelog && npm publish",
|
|
18
|
+
"prepublishOnly": "npm run build",
|
|
19
|
+
"prepare": "husky"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"git",
|
|
23
|
+
"workflow",
|
|
24
|
+
"branch",
|
|
25
|
+
"tag",
|
|
26
|
+
"cli"
|
|
27
|
+
],
|
|
28
|
+
"author": "zjex",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/iamzjt-front-end/git-workflow.git"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/iamzjt-front-end/git-workflow#readme",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/iamzjt-front-end/git-workflow/issues"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@inquirer/prompts": "^7.0.0",
|
|
40
|
+
"cac": "^6.7.14",
|
|
41
|
+
"ora": "^9.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^25.0.3",
|
|
45
|
+
"changelogen": "^0.6.2",
|
|
46
|
+
"husky": "^9.1.7",
|
|
47
|
+
"tsup": "^8.5.1",
|
|
48
|
+
"tsx": "^4.21.0",
|
|
49
|
+
"typescript": "^5.9.3"
|
|
50
|
+
}
|
|
51
|
+
}
|