@zjex/git-workflow 0.2.16 → 0.2.17

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 CHANGED
@@ -2007,15 +2007,7 @@ async function performUpdate(packageName) {
2007
2007
  spinner: "dots"
2008
2008
  }).start();
2009
2009
  try {
2010
- try {
2011
- execSync6(`npm uninstall -g ${packageName}`, {
2012
- encoding: "utf-8",
2013
- stdio: ["pipe", "pipe", "pipe"]
2014
- });
2015
- spinner.text = "\u6B63\u5728\u5B89\u88C5\u65B0\u7248\u672C...";
2016
- } catch {
2017
- }
2018
- execSync6(`npm install -g ${packageName}`, {
2010
+ execSync6(`npm install -g ${packageName}@latest`, {
2019
2011
  encoding: "utf-8",
2020
2012
  stdio: ["pipe", "pipe", "pipe"]
2021
2013
  });
@@ -2026,11 +2018,7 @@ async function performUpdate(packageName) {
2026
2018
  [
2027
2019
  colors.bold("\u2728 \u66F4\u65B0\u5B8C\u6210\uFF01"),
2028
2020
  "",
2029
- colors.dim("\u8BF7\u8FD0\u884C\u4EE5\u4E0B\u547D\u4EE4\u5237\u65B0\u5E76\u4F7F\u7528\u65B0\u7248\u672C:"),
2030
- "",
2031
- colors.yellow(" hash -r && gw --version"),
2032
- "",
2033
- colors.dim("\u6216\u8005\u91CD\u65B0\u6253\u5F00\u7EC8\u7AEF")
2021
+ colors.dim("\u8BF7\u91CD\u65B0\u6253\u5F00\u7EC8\u7AEF\u4F7F\u7528\u65B0\u7248\u672C")
2034
2022
  ].join("\n"),
2035
2023
  {
2036
2024
  padding: 1,
@@ -2046,7 +2034,7 @@ async function performUpdate(packageName) {
2046
2034
  spinner.fail(colors.red("\u66F4\u65B0\u5931\u8D25"));
2047
2035
  console.log("");
2048
2036
  console.log(colors.dim(" \u4F60\u53EF\u4EE5\u624B\u52A8\u8FD0\u884C\u4EE5\u4E0B\u547D\u4EE4\u66F4\u65B0:"));
2049
- console.log(colors.cyan(` npm install -g ${packageName}`));
2037
+ console.log(colors.cyan(` npm install -g ${packageName}@latest`));
2050
2038
  console.log("");
2051
2039
  }
2052
2040
  }
@@ -2095,7 +2083,7 @@ process.on("SIGTERM", () => {
2095
2083
  console.log("");
2096
2084
  process.exit(0);
2097
2085
  });
2098
- var version = true ? "0.2.16" : "0.0.0-dev";
2086
+ var version = true ? "0.2.17" : "0.0.0-dev";
2099
2087
  async function mainMenu() {
2100
2088
  console.log(
2101
2089
  colors.green(`
@@ -2107,7 +2095,7 @@ async function mainMenu() {
2107
2095
  \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D
2108
2096
  `)
2109
2097
  );
2110
- console.log(colors.dim(` git-workflow v${version}
2098
+ console.log(colors.dim(` git-workflow v${colors.yellow(version)}
2111
2099
  `));
2112
2100
  const action = await select8({
2113
2101
  message: "\u9009\u62E9\u64CD\u4F5C:",
@@ -2275,5 +2263,10 @@ cli.help((sections) => {
2275
2263
  body: showHelp()
2276
2264
  });
2277
2265
  });
2278
- cli.version(version);
2266
+ cli.option("-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
2267
+ var args = process.argv.slice(2);
2268
+ if (args.includes("-v") || args.includes("--version")) {
2269
+ console.log(colors.yellow(`v${version}`));
2270
+ process.exit(0);
2271
+ }
2279
2272
  cli.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zjex/git-workflow",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "description": "🚀 极简的 Git 工作流 CLI 工具,让分支管理和版本发布变得轻松愉快",
5
5
  "type": "module",
6
6
  "bin": {
@@ -29,12 +29,15 @@ function exec(command, silent = false) {
29
29
  }
30
30
  }
31
31
 
32
- function runStep(stepNum, stepName, command) {
32
+ async function runStep(stepNum, stepName, command) {
33
33
  const spinner = ora({
34
34
  text: `${colors.blue(`[${stepNum}/${TOTAL_STEPS}]`)} ${stepName}...`,
35
35
  spinner: "dots",
36
36
  }).start();
37
37
 
38
+ // 给 spinner 一点时间渲染
39
+ await new Promise((resolve) => setTimeout(resolve, 100));
40
+
38
41
  try {
39
42
  execSync(command, { encoding: "utf-8", stdio: "pipe" });
40
43
  spinner.succeed(
@@ -56,7 +59,7 @@ async function main() {
56
59
  console.log("");
57
60
 
58
61
  // [1] 检查 Git 仓库
59
- if (!runStep(1, "检查 Git 仓库", "git rev-parse --git-dir")) {
62
+ if (!(await runStep(1, "检查 Git 仓库", "git rev-parse --git-dir"))) {
60
63
  console.log(colors.red("✖ 当前目录不是 git 仓库"));
61
64
  process.exit(1);
62
65
  }
@@ -67,6 +70,8 @@ async function main() {
67
70
  spinner: "dots",
68
71
  }).start();
69
72
 
73
+ await new Promise((resolve) => setTimeout(resolve, 100));
74
+
70
75
  const status = exec("git status --porcelain", true);
71
76
  if (status && status.trim()) {
72
77
  spinner2.fail(`${colors.blue("[2/11]")} 检查工作区状态`);
@@ -86,6 +91,8 @@ async function main() {
86
91
  spinner: "dots",
87
92
  }).start();
88
93
 
94
+ await new Promise((resolve) => setTimeout(resolve, 100));
95
+
89
96
  const npmUser = exec("npm whoami", true);
90
97
  if (!npmUser) {
91
98
  spinner3.fail(`${colors.blue("[3/11]")} 检查 npm 登录状态`);
@@ -102,7 +109,7 @@ async function main() {
102
109
  const currentBranch = exec("git branch --show-current", true).trim();
103
110
 
104
111
  // [4] 拉取最新代码
105
- if (!runStep(4, "拉取最新代码", `git pull origin ${currentBranch}`)) {
112
+ if (!(await runStep(4, "拉取最新代码", `git pull origin ${currentBranch}`))) {
106
113
  process.exit(1);
107
114
  }
108
115
 
@@ -167,12 +174,12 @@ async function main() {
167
174
  );
168
175
 
169
176
  // [6] 构建项目
170
- if (!runStep(6, "构建项目", "npm run build")) {
177
+ if (!(await runStep(6, "构建项目", "npm run build"))) {
171
178
  process.exit(1);
172
179
  }
173
180
 
174
181
  // [7] 生成 CHANGELOG
175
- if (!runStep(7, "生成 CHANGELOG", "npm run changelog")) {
182
+ if (!(await runStep(7, "生成 CHANGELOG", "npm run changelog"))) {
176
183
  process.exit(1);
177
184
  }
178
185
 
@@ -182,6 +189,8 @@ async function main() {
182
189
  spinner: "dots",
183
190
  }).start();
184
191
 
192
+ await new Promise((resolve) => setTimeout(resolve, 100));
193
+
185
194
  try {
186
195
  execSync("git add package.json CHANGELOG.md", { stdio: "pipe" });
187
196
  execSync(`git commit -m "🔖 chore(release): 发布 v${newVersion}"`, {
@@ -206,6 +215,8 @@ async function main() {
206
215
  spinner: "dots",
207
216
  }).start();
208
217
 
218
+ await new Promise((resolve) => setTimeout(resolve, 100));
219
+
209
220
  try {
210
221
  execSync(`git tag -a "v${newVersion}" -m "Release v${newVersion}"`, {
211
222
  stdio: "pipe",
@@ -227,6 +238,8 @@ async function main() {
227
238
  spinner: "dots",
228
239
  }).start();
229
240
 
241
+ await new Promise((resolve) => setTimeout(resolve, 100));
242
+
230
243
  try {
231
244
  execSync(`git push origin ${currentBranch}`, { stdio: "pipe" });
232
245
  execSync(`git push origin v${newVersion}`, { stdio: "pipe" });
package/src/index.ts CHANGED
@@ -66,7 +66,7 @@ async function mainMenu(): Promise<void> {
66
66
  ╚══════╝ ╚════╝ ╚══════╝╚═╝ ╚═╝
67
67
  `)
68
68
  );
69
- console.log(colors.dim(` git-workflow v${version}\n`));
69
+ console.log(colors.dim(` git-workflow v${colors.yellow(version)}\n`));
70
70
 
71
71
  const action = await select({
72
72
  message: "选择操作:",
@@ -287,6 +287,15 @@ cli.help((sections) => {
287
287
  body: showHelp(),
288
288
  });
289
289
  });
290
- cli.version(version);
290
+
291
+ // 不使用 cac 的 version,手动处理 --version
292
+ cli.option("-v, --version", "显示版本号");
293
+
294
+ // 在 parse 之前检查 --version
295
+ const args = process.argv.slice(2);
296
+ if (args.includes("-v") || args.includes("--version")) {
297
+ console.log(colors.yellow(`v${version}`));
298
+ process.exit(0);
299
+ }
291
300
 
292
301
  cli.parse();
@@ -145,19 +145,8 @@ async function performUpdate(packageName: string): Promise<void> {
145
145
  }).start();
146
146
 
147
147
  try {
148
- // 先卸载当前版本,确保干净安装
149
- try {
150
- execSync(`npm uninstall -g ${packageName}`, {
151
- encoding: "utf-8",
152
- stdio: ["pipe", "pipe", "pipe"],
153
- });
154
- spinner.text = "正在安装新版本...";
155
- } catch {
156
- // 当前版本不存在,忽略错误
157
- }
158
-
159
- // 执行安装命令
160
- execSync(`npm install -g ${packageName}`, {
148
+ // 直接安装最新版本(npm 会自动覆盖旧版本)
149
+ execSync(`npm install -g ${packageName}@latest`, {
161
150
  encoding: "utf-8",
162
151
  stdio: ["pipe", "pipe", "pipe"],
163
152
  });
@@ -169,11 +158,7 @@ async function performUpdate(packageName: string): Promise<void> {
169
158
  [
170
159
  colors.bold("✨ 更新完成!"),
171
160
  "",
172
- colors.dim("请运行以下命令刷新并使用新版本:"),
173
- "",
174
- colors.yellow(" hash -r && gw --version"),
175
- "",
176
- colors.dim("或者重新打开终端"),
161
+ colors.dim("请重新打开终端使用新版本"),
177
162
  ].join("\n"),
178
163
  {
179
164
  padding: 1,
@@ -191,7 +176,7 @@ async function performUpdate(packageName: string): Promise<void> {
191
176
  spinner.fail(colors.red("更新失败"));
192
177
  console.log("");
193
178
  console.log(colors.dim(" 你可以手动运行以下命令更新:"));
194
- console.log(colors.cyan(` npm install -g ${packageName}`));
179
+ console.log(colors.cyan(` npm install -g ${packageName}@latest`));
195
180
  console.log("");
196
181
  }
197
182
  }