@zjex/git-workflow 0.2.3 → 0.2.5
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/dist/index.js +7 -5
- package/package.json +1 -1
- package/src/index.ts +5 -5
- package/src/update-notifier.ts +7 -3
- package/test-ctrl-c.mjs +32 -0
- package/test-full-flow.mjs +108 -0
- package/tsup.config.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env -S node --no-warnings=ExperimentalWarning
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { cac } from "cac";
|
|
@@ -1368,6 +1368,9 @@ async function checkForUpdates(currentVersion, packageName = "@zjex/git-workflow
|
|
|
1368
1368
|
}
|
|
1369
1369
|
}
|
|
1370
1370
|
} catch (error) {
|
|
1371
|
+
if (error?.constructor?.name === "ExitPromptError") {
|
|
1372
|
+
throw error;
|
|
1373
|
+
}
|
|
1371
1374
|
}
|
|
1372
1375
|
}
|
|
1373
1376
|
async function getLatestVersion(packageName) {
|
|
@@ -1423,7 +1426,7 @@ async function showUpdateMessage(current, latest, packageName) {
|
|
|
1423
1426
|
return action;
|
|
1424
1427
|
} catch (error) {
|
|
1425
1428
|
console.log("");
|
|
1426
|
-
|
|
1429
|
+
throw error;
|
|
1427
1430
|
}
|
|
1428
1431
|
}
|
|
1429
1432
|
async function performUpdate(packageName) {
|
|
@@ -1490,10 +1493,9 @@ process.on("uncaughtException", (err) => {
|
|
|
1490
1493
|
console.error(err);
|
|
1491
1494
|
process.exit(1);
|
|
1492
1495
|
});
|
|
1493
|
-
var version = true ? "0.2.
|
|
1496
|
+
var version = true ? "0.2.5" : "0.0.0-dev";
|
|
1494
1497
|
async function mainMenu() {
|
|
1495
|
-
checkForUpdates(version, "@zjex/git-workflow")
|
|
1496
|
-
});
|
|
1498
|
+
await checkForUpdates(version, "@zjex/git-workflow");
|
|
1497
1499
|
console.log(
|
|
1498
1500
|
colors.green(`
|
|
1499
1501
|
\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557
|
package/package.json
CHANGED
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 { checkForUpdates } from "./update-notifier.js";
|
|
15
16
|
|
|
16
17
|
// 捕获 Ctrl+C 退出,静默处理
|
|
17
18
|
process.on("uncaughtException", (err) => {
|
|
@@ -26,15 +27,14 @@ declare const __VERSION__: string | undefined;
|
|
|
26
27
|
|
|
27
28
|
// 开发环境下从 package.json 读取版本号
|
|
28
29
|
const version: string =
|
|
29
|
-
typeof __VERSION__ !== "undefined"
|
|
30
|
+
typeof __VERSION__ !== "undefined" && __VERSION__ !== ""
|
|
30
31
|
? __VERSION__
|
|
31
|
-
:
|
|
32
|
-
.version;
|
|
32
|
+
: "0.0.0-dev";
|
|
33
33
|
|
|
34
34
|
// 交互式主菜单
|
|
35
35
|
async function mainMenu(): Promise<void> {
|
|
36
|
-
//
|
|
37
|
-
checkForUpdates(version, "@zjex/git-workflow")
|
|
36
|
+
// 先检查更新,等待完成后再显示主菜单
|
|
37
|
+
await checkForUpdates(version, "@zjex/git-workflow");
|
|
38
38
|
|
|
39
39
|
// ASCII Art Logo
|
|
40
40
|
console.log(
|
package/src/update-notifier.ts
CHANGED
|
@@ -53,7 +53,11 @@ export async function checkForUpdates(
|
|
|
53
53
|
// action === "continue" 时直接继续,不记录
|
|
54
54
|
}
|
|
55
55
|
} catch (error) {
|
|
56
|
-
//
|
|
56
|
+
// 如果是用户按 Ctrl+C,重新抛出让全局处理
|
|
57
|
+
if (error?.constructor?.name === "ExitPromptError") {
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
// 其他错误静默失败,不影响主程序
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
|
|
@@ -123,9 +127,9 @@ async function showUpdateMessage(
|
|
|
123
127
|
|
|
124
128
|
return action as "update" | "continue" | "dismiss";
|
|
125
129
|
} catch (error) {
|
|
126
|
-
// 用户按了 Ctrl+C
|
|
130
|
+
// 用户按了 Ctrl+C,重新抛出错误让全局处理
|
|
127
131
|
console.log("");
|
|
128
|
-
|
|
132
|
+
throw error;
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
135
|
|
package/test-ctrl-c.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { select } from "@inquirer/prompts";
|
|
4
|
+
import { ExitPromptError } from "@inquirer/core";
|
|
5
|
+
|
|
6
|
+
// 捕获 Ctrl+C 退出,静默处理
|
|
7
|
+
process.on("uncaughtException", (err) => {
|
|
8
|
+
if (err instanceof ExitPromptError) {
|
|
9
|
+
console.log("\n✓ Ctrl+C 被正确捕获,程序退出");
|
|
10
|
+
process.exit(0);
|
|
11
|
+
}
|
|
12
|
+
console.error("其他错误:", err);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
async function test() {
|
|
17
|
+
try {
|
|
18
|
+
const choice = await select({
|
|
19
|
+
message: "测试 Ctrl+C (按 Ctrl+C 退出):",
|
|
20
|
+
choices: [
|
|
21
|
+
{ name: "选项 1", value: "1" },
|
|
22
|
+
{ name: "选项 2", value: "2" },
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
console.log(`你选择了: ${choice}`);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.log("\n在 catch 中捕获到错误,重新抛出...");
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
test();
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import boxen from "boxen";
|
|
4
|
+
import { select } from "@inquirer/prompts";
|
|
5
|
+
import { ExitPromptError } from "@inquirer/core";
|
|
6
|
+
|
|
7
|
+
// 捕获 Ctrl+C 退出,静默处理
|
|
8
|
+
process.on("uncaughtException", (err) => {
|
|
9
|
+
if (err instanceof ExitPromptError) {
|
|
10
|
+
process.exit(0);
|
|
11
|
+
}
|
|
12
|
+
console.error(err);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const colors = {
|
|
17
|
+
green: (s) => `\x1b[32m${s}\x1b[0m`,
|
|
18
|
+
dim: (s) => `\x1b[2m${s}\x1b[0m`,
|
|
19
|
+
bold: (s) => `\x1b[1m${s}\x1b[0m`,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
async function checkForUpdates() {
|
|
23
|
+
const current = "0.2.3";
|
|
24
|
+
const latest = "0.2.4";
|
|
25
|
+
const packageName = "@zjex/git-workflow";
|
|
26
|
+
|
|
27
|
+
const message = [
|
|
28
|
+
colors.bold("🎉 发现新版本可用!"),
|
|
29
|
+
"",
|
|
30
|
+
`${colors.dim(current)} → ${colors.green(colors.bold(latest))}`,
|
|
31
|
+
].join("\n");
|
|
32
|
+
|
|
33
|
+
console.log("");
|
|
34
|
+
console.log(
|
|
35
|
+
boxen(message, {
|
|
36
|
+
padding: 1,
|
|
37
|
+
margin: 1,
|
|
38
|
+
borderStyle: "round",
|
|
39
|
+
borderColor: "yellow",
|
|
40
|
+
align: "left",
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const action = await select({
|
|
46
|
+
message: "你想做什么?",
|
|
47
|
+
choices: [
|
|
48
|
+
{
|
|
49
|
+
name: "🚀 立即更新",
|
|
50
|
+
value: "update",
|
|
51
|
+
description: `运行 npm install -g ${packageName}`,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "⏭️ 稍后更新,继续使用",
|
|
55
|
+
value: "continue",
|
|
56
|
+
description: "下次启动时会再次提示",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "🙈 跳过此版本 (24h 内不再提示)",
|
|
60
|
+
value: "dismiss",
|
|
61
|
+
description: "24 小时内不会再提示此版本",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (action === "update") {
|
|
67
|
+
console.log("\n模拟更新中...\n");
|
|
68
|
+
process.exit(0);
|
|
69
|
+
} else if (action === "dismiss") {
|
|
70
|
+
console.log(colors.dim("\n已跳过此版本,24 小时内不再提示\n"));
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
// 用户按了 Ctrl+C,重新抛出让全局处理
|
|
74
|
+
console.log("");
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function mainMenu() {
|
|
80
|
+
// 先检查更新,等待完成
|
|
81
|
+
await checkForUpdates();
|
|
82
|
+
|
|
83
|
+
// 然后显示主菜单
|
|
84
|
+
console.log(
|
|
85
|
+
colors.green(`
|
|
86
|
+
███████╗ ██╗███████╗██╗ ██╗
|
|
87
|
+
╚══███╔╝ ██║██╔════╝╚██╗██╔╝
|
|
88
|
+
███╔╝ ██║█████╗ ╚███╔╝
|
|
89
|
+
███╔╝ ██ ██║██╔══╝ ██╔██╗
|
|
90
|
+
███████╗╚█████╔╝███████╗██╔╝ ██╗
|
|
91
|
+
╚══════╝ ╚════╝ ╚══════╝╚═╝ ╚═╝
|
|
92
|
+
`)
|
|
93
|
+
);
|
|
94
|
+
console.log(colors.dim(` git-workflow v0.2.4\n`));
|
|
95
|
+
|
|
96
|
+
const choice = await select({
|
|
97
|
+
message: "选择操作:",
|
|
98
|
+
choices: [
|
|
99
|
+
{ name: "[1] ✨ 创建 feature 分支 gw f", value: "1" },
|
|
100
|
+
{ name: "[2] 🐛 创建 hotfix 分支 gw h", value: "2" },
|
|
101
|
+
{ name: "[3] 🗑️ 删除分支 gw d", value: "3" },
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
console.log(`\n你选择了: ${choice}\n`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
mainMenu();
|