@zjex/git-workflow 0.2.18 → 0.2.19
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/README.md +49 -0
- package/dist/index.js +109 -1
- package/package.json +1 -1
- package/src/commands/help.ts +4 -0
- package/src/commands/update.ts +122 -0
- package/src/index.ts +8 -0
package/README.md
CHANGED
|
@@ -450,6 +450,12 @@ gw r
|
|
|
450
450
|
| --------- | ------------------------------------------------ |
|
|
451
451
|
| `gw init` | 交互式初始化配置文件(可选择全局配置或项目配置) |
|
|
452
452
|
|
|
453
|
+
### 🔄 更新命令
|
|
454
|
+
|
|
455
|
+
| 命令 | 别名 | 说明 |
|
|
456
|
+
| ----------- | -------- | -------------------- |
|
|
457
|
+
| `gw update` | `gw upt` | 检查并更新到最新版本 |
|
|
458
|
+
|
|
453
459
|
```bash
|
|
454
460
|
# 创建全局配置(推荐,一次配置所有项目生效)
|
|
455
461
|
gw init
|
|
@@ -462,6 +468,49 @@ gw init
|
|
|
462
468
|
# 配置保存到 .gwrc.json
|
|
463
469
|
```
|
|
464
470
|
|
|
471
|
+
#### 更新命令
|
|
472
|
+
|
|
473
|
+
```bash
|
|
474
|
+
# 检查并更新到最新版本
|
|
475
|
+
gw update
|
|
476
|
+
|
|
477
|
+
# 或使用别名
|
|
478
|
+
gw upt
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
**更新流程:**
|
|
482
|
+
|
|
483
|
+
```bash
|
|
484
|
+
gw update
|
|
485
|
+
|
|
486
|
+
🔍 检查更新...
|
|
487
|
+
|
|
488
|
+
┌─────────────────────────────────┐
|
|
489
|
+
│ │
|
|
490
|
+
│ 🎉 发现新版本! │
|
|
491
|
+
│ │
|
|
492
|
+
│ 0.2.16 → 0.2.17 │
|
|
493
|
+
│ │
|
|
494
|
+
└─────────────────────────────────┘
|
|
495
|
+
|
|
496
|
+
✔ 更新成功!
|
|
497
|
+
|
|
498
|
+
┌─────────────────────────────────┐
|
|
499
|
+
│ │
|
|
500
|
+
│ ✨ 更新完成! │
|
|
501
|
+
│ │
|
|
502
|
+
│ 请重新打开终端使用新版本 │
|
|
503
|
+
│ │
|
|
504
|
+
└─────────────────────────────────┘
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
**说明:**
|
|
508
|
+
|
|
509
|
+
- 自动检测最新版本
|
|
510
|
+
- 如果已是最新版本,显示提示
|
|
511
|
+
- 如果有新版本,自动更新
|
|
512
|
+
- 更新成功后提示重新打开终端
|
|
513
|
+
|
|
465
514
|
**配置流程:**
|
|
466
515
|
|
|
467
516
|
```bash
|
package/dist/index.js
CHANGED
|
@@ -1928,6 +1928,10 @@ Tag \u547D\u4EE4:
|
|
|
1928
1928
|
\u2022 \u9879\u76EE\u914D\u7F6E: .gwrc.json (\u4EC5\u5F53\u524D\u9879\u76EE)
|
|
1929
1929
|
\u8FD0\u884C\u65F6\u53EF\u9009\u62E9\u914D\u7F6E\u8303\u56F4
|
|
1930
1930
|
|
|
1931
|
+
\u66F4\u65B0\u547D\u4EE4:
|
|
1932
|
+
gw update \u68C0\u67E5\u5E76\u66F4\u65B0\u5230\u6700\u65B0\u7248\u672C
|
|
1933
|
+
gw upt \u540C\u4E0A (\u522B\u540D)
|
|
1934
|
+
|
|
1931
1935
|
Stash \u547D\u4EE4:
|
|
1932
1936
|
gw stash \u4EA4\u4E92\u5F0F\u7BA1\u7406 stash
|
|
1933
1937
|
gw s \u540C\u4E0A (\u522B\u540D)
|
|
@@ -2108,6 +2112,107 @@ function writeCache(cache) {
|
|
|
2108
2112
|
}
|
|
2109
2113
|
}
|
|
2110
2114
|
|
|
2115
|
+
// src/commands/update.ts
|
|
2116
|
+
import { execSync as execSync7 } from "child_process";
|
|
2117
|
+
import ora6 from "ora";
|
|
2118
|
+
import boxen2 from "boxen";
|
|
2119
|
+
async function getLatestVersion2(packageName) {
|
|
2120
|
+
try {
|
|
2121
|
+
const result = execSync7(`npm view ${packageName} version`, {
|
|
2122
|
+
encoding: "utf-8",
|
|
2123
|
+
timeout: 3e3,
|
|
2124
|
+
stdio: ["pipe", "pipe", "ignore"]
|
|
2125
|
+
});
|
|
2126
|
+
return result.trim();
|
|
2127
|
+
} catch {
|
|
2128
|
+
return null;
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
async function update(currentVersion) {
|
|
2132
|
+
const packageName = "@zjex/git-workflow";
|
|
2133
|
+
console.log("");
|
|
2134
|
+
console.log(colors.bold("\u{1F50D} \u68C0\u67E5\u66F4\u65B0..."));
|
|
2135
|
+
console.log("");
|
|
2136
|
+
const spinner = ora6("\u6B63\u5728\u83B7\u53D6\u6700\u65B0\u7248\u672C\u4FE1\u606F...").start();
|
|
2137
|
+
try {
|
|
2138
|
+
const latestVersion = await getLatestVersion2(packageName);
|
|
2139
|
+
if (!latestVersion) {
|
|
2140
|
+
spinner.fail("\u65E0\u6CD5\u83B7\u53D6\u6700\u65B0\u7248\u672C\u4FE1\u606F");
|
|
2141
|
+
console.log(colors.dim(" \u8BF7\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5\u540E\u91CD\u8BD5"));
|
|
2142
|
+
return;
|
|
2143
|
+
}
|
|
2144
|
+
spinner.stop();
|
|
2145
|
+
if (latestVersion === currentVersion) {
|
|
2146
|
+
console.log(
|
|
2147
|
+
boxen2(
|
|
2148
|
+
[
|
|
2149
|
+
colors.bold("\u2705 \u5DF2\u662F\u6700\u65B0\u7248\u672C"),
|
|
2150
|
+
"",
|
|
2151
|
+
`\u5F53\u524D\u7248\u672C: ${colors.green(currentVersion)}`
|
|
2152
|
+
].join("\n"),
|
|
2153
|
+
{
|
|
2154
|
+
padding: 1,
|
|
2155
|
+
margin: { top: 0, bottom: 1, left: 2, right: 2 },
|
|
2156
|
+
borderStyle: "round",
|
|
2157
|
+
borderColor: "green",
|
|
2158
|
+
align: "left"
|
|
2159
|
+
}
|
|
2160
|
+
)
|
|
2161
|
+
);
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2164
|
+
console.log(
|
|
2165
|
+
boxen2(
|
|
2166
|
+
[
|
|
2167
|
+
colors.bold("\u{1F389} \u53D1\u73B0\u65B0\u7248\u672C\uFF01"),
|
|
2168
|
+
"",
|
|
2169
|
+
`${colors.dim(currentVersion)} \u2192 ${colors.green(
|
|
2170
|
+
colors.bold(latestVersion)
|
|
2171
|
+
)}`
|
|
2172
|
+
].join("\n"),
|
|
2173
|
+
{
|
|
2174
|
+
padding: 1,
|
|
2175
|
+
margin: { top: 0, bottom: 1, left: 2, right: 2 },
|
|
2176
|
+
borderStyle: "round",
|
|
2177
|
+
borderColor: "yellow",
|
|
2178
|
+
align: "left"
|
|
2179
|
+
}
|
|
2180
|
+
)
|
|
2181
|
+
);
|
|
2182
|
+
const updateSpinner = ora6("\u6B63\u5728\u66F4\u65B0...").start();
|
|
2183
|
+
execSync7(`npm install -g ${packageName}@latest`, {
|
|
2184
|
+
encoding: "utf-8",
|
|
2185
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
2186
|
+
});
|
|
2187
|
+
updateSpinner.succeed(colors.green("\u66F4\u65B0\u6210\u529F\uFF01"));
|
|
2188
|
+
console.log("");
|
|
2189
|
+
console.log(
|
|
2190
|
+
boxen2(
|
|
2191
|
+
[
|
|
2192
|
+
colors.bold("\u2728 \u66F4\u65B0\u5B8C\u6210\uFF01"),
|
|
2193
|
+
"",
|
|
2194
|
+
colors.dim("\u8BF7\u91CD\u65B0\u6253\u5F00\u7EC8\u7AEF\u4F7F\u7528\u65B0\u7248\u672C")
|
|
2195
|
+
].join("\n"),
|
|
2196
|
+
{
|
|
2197
|
+
padding: 1,
|
|
2198
|
+
margin: { top: 0, bottom: 1, left: 2, right: 2 },
|
|
2199
|
+
borderStyle: "round",
|
|
2200
|
+
borderColor: "green",
|
|
2201
|
+
align: "left"
|
|
2202
|
+
}
|
|
2203
|
+
)
|
|
2204
|
+
);
|
|
2205
|
+
process.exit(0);
|
|
2206
|
+
} catch (error) {
|
|
2207
|
+
spinner.fail(colors.red("\u66F4\u65B0\u5931\u8D25"));
|
|
2208
|
+
console.log("");
|
|
2209
|
+
console.log(colors.dim(" \u4F60\u53EF\u4EE5\u624B\u52A8\u8FD0\u884C\u4EE5\u4E0B\u547D\u4EE4\u66F4\u65B0:"));
|
|
2210
|
+
console.log(colors.cyan(` npm install -g ${packageName}@latest`));
|
|
2211
|
+
console.log("");
|
|
2212
|
+
process.exit(1);
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2111
2216
|
// src/index.ts
|
|
2112
2217
|
process.on("uncaughtException", (err) => {
|
|
2113
2218
|
if (err instanceof ExitPromptError) {
|
|
@@ -2133,7 +2238,7 @@ process.on("SIGTERM", () => {
|
|
|
2133
2238
|
console.log("");
|
|
2134
2239
|
process.exit(0);
|
|
2135
2240
|
});
|
|
2136
|
-
var version = true ? "0.2.
|
|
2241
|
+
var version = true ? "0.2.19" : "0.0.0-dev";
|
|
2137
2242
|
async function mainMenu() {
|
|
2138
2243
|
console.log(
|
|
2139
2244
|
colors.green(`
|
|
@@ -2308,6 +2413,9 @@ cli.command("commit", "\u4EA4\u4E92\u5F0F\u63D0\u4EA4 (Conventional Commits + Gi
|
|
|
2308
2413
|
checkGitRepo();
|
|
2309
2414
|
return commit();
|
|
2310
2415
|
});
|
|
2416
|
+
cli.command("update", "\u68C0\u67E5\u5E76\u66F4\u65B0\u5230\u6700\u65B0\u7248\u672C").alias("upt").action(async () => {
|
|
2417
|
+
return update(version);
|
|
2418
|
+
});
|
|
2311
2419
|
cli.help((sections) => {
|
|
2312
2420
|
sections.push({
|
|
2313
2421
|
body: showHelp()
|
package/package.json
CHANGED
package/src/commands/help.ts
CHANGED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import boxen from "boxen";
|
|
4
|
+
import { colors } from "../utils.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 获取 npm 上的最新版本
|
|
8
|
+
*/
|
|
9
|
+
async function getLatestVersion(packageName: string): Promise<string | null> {
|
|
10
|
+
try {
|
|
11
|
+
const result = execSync(`npm view ${packageName} version`, {
|
|
12
|
+
encoding: "utf-8",
|
|
13
|
+
timeout: 3000,
|
|
14
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
15
|
+
});
|
|
16
|
+
return result.trim();
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 手动更新命令
|
|
24
|
+
*/
|
|
25
|
+
export async function update(currentVersion: string): Promise<void> {
|
|
26
|
+
const packageName = "@zjex/git-workflow";
|
|
27
|
+
|
|
28
|
+
console.log("");
|
|
29
|
+
console.log(colors.bold("🔍 检查更新..."));
|
|
30
|
+
console.log("");
|
|
31
|
+
|
|
32
|
+
const spinner = ora("正在获取最新版本信息...").start();
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const latestVersion = await getLatestVersion(packageName);
|
|
36
|
+
|
|
37
|
+
if (!latestVersion) {
|
|
38
|
+
spinner.fail("无法获取最新版本信息");
|
|
39
|
+
console.log(colors.dim(" 请检查网络连接后重试"));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
spinner.stop();
|
|
44
|
+
|
|
45
|
+
if (latestVersion === currentVersion) {
|
|
46
|
+
console.log(
|
|
47
|
+
boxen(
|
|
48
|
+
[
|
|
49
|
+
colors.bold("✅ 已是最新版本"),
|
|
50
|
+
"",
|
|
51
|
+
`当前版本: ${colors.green(currentVersion)}`,
|
|
52
|
+
].join("\n"),
|
|
53
|
+
{
|
|
54
|
+
padding: 1,
|
|
55
|
+
margin: { top: 0, bottom: 1, left: 2, right: 2 },
|
|
56
|
+
borderStyle: "round",
|
|
57
|
+
borderColor: "green",
|
|
58
|
+
align: "left",
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 有新版本
|
|
66
|
+
console.log(
|
|
67
|
+
boxen(
|
|
68
|
+
[
|
|
69
|
+
colors.bold("🎉 发现新版本!"),
|
|
70
|
+
"",
|
|
71
|
+
`${colors.dim(currentVersion)} → ${colors.green(
|
|
72
|
+
colors.bold(latestVersion)
|
|
73
|
+
)}`,
|
|
74
|
+
].join("\n"),
|
|
75
|
+
{
|
|
76
|
+
padding: 1,
|
|
77
|
+
margin: { top: 0, bottom: 1, left: 2, right: 2 },
|
|
78
|
+
borderStyle: "round",
|
|
79
|
+
borderColor: "yellow",
|
|
80
|
+
align: "left",
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// 开始更新
|
|
86
|
+
const updateSpinner = ora("正在更新...").start();
|
|
87
|
+
|
|
88
|
+
execSync(`npm install -g ${packageName}@latest`, {
|
|
89
|
+
encoding: "utf-8",
|
|
90
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
updateSpinner.succeed(colors.green("更新成功!"));
|
|
94
|
+
console.log("");
|
|
95
|
+
console.log(
|
|
96
|
+
boxen(
|
|
97
|
+
[
|
|
98
|
+
colors.bold("✨ 更新完成!"),
|
|
99
|
+
"",
|
|
100
|
+
colors.dim("请重新打开终端使用新版本"),
|
|
101
|
+
].join("\n"),
|
|
102
|
+
{
|
|
103
|
+
padding: 1,
|
|
104
|
+
margin: { top: 0, bottom: 1, left: 2, right: 2 },
|
|
105
|
+
borderStyle: "round",
|
|
106
|
+
borderColor: "green",
|
|
107
|
+
align: "left",
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// 更新成功后退出
|
|
113
|
+
process.exit(0);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
spinner.fail(colors.red("更新失败"));
|
|
116
|
+
console.log("");
|
|
117
|
+
console.log(colors.dim(" 你可以手动运行以下命令更新:"));
|
|
118
|
+
console.log(colors.cyan(` npm install -g ${packageName}@latest`));
|
|
119
|
+
console.log("");
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { stash } from "./commands/stash.js";
|
|
|
12
12
|
import { commit } from "./commands/commit.js";
|
|
13
13
|
import { showHelp } from "./commands/help.js";
|
|
14
14
|
import { checkForUpdates } from "./update-notifier.js";
|
|
15
|
+
import { update } from "./commands/update.js";
|
|
15
16
|
|
|
16
17
|
// 捕获 Ctrl+C 退出,静默处理
|
|
17
18
|
process.on("uncaughtException", (err) => {
|
|
@@ -282,6 +283,13 @@ cli
|
|
|
282
283
|
return commit();
|
|
283
284
|
});
|
|
284
285
|
|
|
286
|
+
cli
|
|
287
|
+
.command("update", "检查并更新到最新版本")
|
|
288
|
+
.alias("upt")
|
|
289
|
+
.action(async () => {
|
|
290
|
+
return update(version);
|
|
291
|
+
});
|
|
292
|
+
|
|
285
293
|
cli.help((sections) => {
|
|
286
294
|
sections.push({
|
|
287
295
|
body: showHelp(),
|