@zjex/git-workflow 0.2.1 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zjex/git-workflow",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "个人常用的 Git 工作流工具,快速创建规范的开发分支和管理 Tag",
5
5
  "type": "module",
6
6
  "bin": {
@@ -80,9 +80,9 @@ async function showUpdateMessage(
80
80
  packageName: string
81
81
  ): Promise<"update" | "continue" | "dismiss"> {
82
82
  const message = [
83
- `${colors.bold}🎉 发现新版本可用!${colors.reset}`,
83
+ colors.bold("� 发现新版新本可用!"),
84
84
  "",
85
- `${colors.dim}${current}${colors.reset} → ${colors.green}${colors.bold}${latest}${colors.reset}`,
85
+ `${colors.dim(current)} → ${colors.green(colors.bold(latest))}`,
86
86
  ].join("\n");
87
87
 
88
88
  console.log("");
@@ -155,26 +155,22 @@ async function performUpdate(packageName: string): Promise<void> {
155
155
  stdio: ["pipe", "pipe", "pipe"],
156
156
  });
157
157
 
158
- spinner.succeed(colors.green + "更新成功!" + colors.reset);
158
+ spinner.succeed(colors.green("更新成功!"));
159
159
  console.log("");
160
- console.log(
161
- colors.cyan + " 提示: 请重新运行命令以使用新版本" + colors.reset
162
- );
160
+ console.log(colors.cyan(" 提示: 请重新运行命令以使用新版本"));
163
161
  console.log("");
164
162
 
165
163
  // 更新成功后退出,让用户重新运行
166
164
  process.exit(0);
167
165
  } catch (error) {
168
- spinner.fail(colors.red + "更新失败" + colors.reset);
166
+ spinner.fail(colors.red("更新失败"));
169
167
  console.log("");
170
- console.log(colors.dim + " 你可以手动运行以下命令更新:" + colors.reset);
171
- console.log(
172
- colors.yellow + " # 如果之前安装过旧版本,先卸载:" + colors.reset
173
- );
174
- console.log(colors.cyan + " npm uninstall -g git-workflow" + colors.reset);
168
+ console.log(colors.dim(" 你可以手动运行以下命令更新:"));
169
+ console.log(colors.yellow(" # 如果之前安装过旧版本,先卸载:"));
170
+ console.log(colors.cyan(" npm uninstall -g git-workflow"));
175
171
  console.log("");
176
- console.log(colors.yellow + " # 然后安装新版本:" + colors.reset);
177
- console.log(colors.cyan + ` npm install -g ${packageName}` + colors.reset);
172
+ console.log(colors.yellow(" # 然后安装新版本:"));
173
+ console.log(colors.cyan(` npm install -g ${packageName}`));
178
174
  console.log("");
179
175
  }
180
176
  }
package/src/utils.ts CHANGED
@@ -4,14 +4,20 @@ export interface Colors {
4
4
  red: (s: string) => string;
5
5
  green: (s: string) => string;
6
6
  yellow: (s: string) => string;
7
+ cyan: (s: string) => string;
7
8
  dim: (s: string) => string;
9
+ bold: (s: string) => string;
10
+ reset: string;
8
11
  }
9
12
 
10
13
  export const colors: Colors = {
11
14
  red: (s) => `\x1b[31m${s}\x1b[0m`,
12
15
  green: (s) => `\x1b[32m${s}\x1b[0m`,
13
16
  yellow: (s) => `\x1b[33m${s}\x1b[0m`,
17
+ cyan: (s) => `\x1b[36m${s}\x1b[0m`,
14
18
  dim: (s) => `\x1b[2m${s}\x1b[0m`,
19
+ bold: (s) => `\x1b[1m${s}\x1b[0m`,
20
+ reset: "\x1b[0m",
15
21
  };
16
22
 
17
23
  export const TODAY: string = new Date()
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+
3
+ import boxen from "boxen";
4
+ import { select } from "@inquirer/prompts";
5
+ import ora from "ora";
6
+
7
+ const colors = {
8
+ red: (s) => `\x1b[31m${s}\x1b[0m`,
9
+ green: (s) => `\x1b[32m${s}\x1b[0m`,
10
+ yellow: (s) => `\x1b[33m${s}\x1b[0m`,
11
+ cyan: (s) => `\x1b[36m${s}\x1b[0m`,
12
+ dim: (s) => `\x1b[2m${s}\x1b[0m`,
13
+ bold: (s) => `\x1b[1m${s}\x1b[0m`,
14
+ reset: "\x1b[0m",
15
+ };
16
+
17
+ async function testUpdateFlow() {
18
+ const current = "0.1.0";
19
+ const latest = "0.2.0";
20
+ const packageName = "@zjex/git-workflow";
21
+
22
+ // 1. 显示更新提示框
23
+ const message = [
24
+ colors.bold("🎉 发现新版本可用!"),
25
+ "",
26
+ `${colors.dim(current)} → ${colors.green(colors.bold(latest))}`,
27
+ ].join("\n");
28
+
29
+ console.log("");
30
+ console.log(
31
+ boxen(message, {
32
+ padding: 1,
33
+ margin: 1,
34
+ borderStyle: "round",
35
+ borderColor: "yellow",
36
+ align: "left",
37
+ })
38
+ );
39
+
40
+ // 2. 交互式选择
41
+ try {
42
+ const action = await select({
43
+ message: "你想做什么?",
44
+ choices: [
45
+ {
46
+ name: "🚀 立即更新",
47
+ value: "update",
48
+ description: `运行 npm install -g ${packageName}`,
49
+ },
50
+ {
51
+ name: "⏭️ 稍后更新,继续使用",
52
+ value: "continue",
53
+ description: "下次启动时会再次提示",
54
+ },
55
+ {
56
+ name: "🙈 跳过此版本 (24h 内不再提示)",
57
+ value: "dismiss",
58
+ description: "24 小时内不会再提示此版本",
59
+ },
60
+ ],
61
+ });
62
+
63
+ console.log("");
64
+
65
+ // 3. 根据选择执行操作
66
+ if (action === "update") {
67
+ // 模拟更新过程
68
+ const spinner = ora({
69
+ text: "正在更新...",
70
+ spinner: "dots",
71
+ }).start();
72
+
73
+ // 模拟卸载旧版本
74
+ await new Promise((resolve) => setTimeout(resolve, 1000));
75
+ spinner.text = "已卸载旧版本,正在安装新版本...";
76
+
77
+ // 模拟安装新版本
78
+ await new Promise((resolve) => setTimeout(resolve, 2000));
79
+
80
+ spinner.succeed(colors.green("更新成功!"));
81
+ console.log("");
82
+ console.log(colors.cyan(" 提示: 请重新运行命令以使用新版本"));
83
+ console.log("");
84
+ } else if (action === "continue") {
85
+ console.log(colors.cyan("继续使用当前版本..."));
86
+ console.log("");
87
+ } else if (action === "dismiss") {
88
+ console.log(colors.dim("已跳过此版本,24 小时内不再提示"));
89
+ console.log("");
90
+ }
91
+ } catch (error) {
92
+ console.log("");
93
+ console.log(colors.dim("已取消"));
94
+ console.log("");
95
+ }
96
+ }
97
+
98
+ testUpdateFlow();
package/tsup.config.ts CHANGED
@@ -7,10 +7,20 @@ export default defineConfig({
7
7
  entry: ["src/index.ts"],
8
8
  format: ["esm"],
9
9
  clean: true,
10
- shims: true,
11
- minify: true,
10
+ shims: false,
11
+ minify: false,
12
+ splitting: false,
13
+ treeshake: false,
14
+ external: [
15
+ // 不打包这些依赖,让 node 自己解析
16
+ "boxen",
17
+ "ora",
18
+ "@inquirer/prompts",
19
+ "@inquirer/core",
20
+ "cac",
21
+ ],
12
22
  banner: {
13
- js: "#!/usr/bin/env node --no-warnings",
23
+ js: "#!/usr/bin/env node",
14
24
  },
15
25
  define: {
16
26
  __VERSION__: JSON.stringify(pkg.version),