@zjex/git-workflow 0.3.7 → 0.3.8

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
@@ -91,9 +91,9 @@ __export(update_notifier_exports, {
91
91
  clearUpdateCache: () => clearUpdateCache
92
92
  });
93
93
  import { execSync as execSync6 } from "child_process";
94
- import { readFileSync as readFileSync3, writeFileSync as writeFileSync3, existsSync as existsSync3, unlinkSync } from "fs";
94
+ import { readFileSync as readFileSync3, writeFileSync as writeFileSync4, existsSync as existsSync3, unlinkSync as unlinkSync2 } from "fs";
95
95
  import { homedir as homedir3 } from "os";
96
- import { join as join3 } from "path";
96
+ import { join as join4 } from "path";
97
97
  import boxen from "boxen";
98
98
  import { select as select7 } from "@inquirer/prompts";
99
99
  import ora5 from "ora";
@@ -283,16 +283,16 @@ async function performUpdate(packageName) {
283
283
  }
284
284
  function clearUpdateCache() {
285
285
  try {
286
- const cacheFile = join3(homedir3(), CACHE_FILE);
286
+ const cacheFile = join4(homedir3(), CACHE_FILE);
287
287
  if (existsSync3(cacheFile)) {
288
- unlinkSync(cacheFile);
288
+ unlinkSync2(cacheFile);
289
289
  }
290
290
  } catch {
291
291
  }
292
292
  }
293
293
  function readCache() {
294
294
  try {
295
- const cacheFile = join3(homedir3(), CACHE_FILE);
295
+ const cacheFile = join4(homedir3(), CACHE_FILE);
296
296
  if (!existsSync3(cacheFile)) {
297
297
  return null;
298
298
  }
@@ -304,8 +304,8 @@ function readCache() {
304
304
  }
305
305
  function writeCache(cache) {
306
306
  try {
307
- const cacheFile = join3(homedir3(), CACHE_FILE);
308
- writeFileSync3(cacheFile, JSON.stringify(cache), "utf-8");
307
+ const cacheFile = join4(homedir3(), CACHE_FILE);
308
+ writeFileSync4(cacheFile, JSON.stringify(cache), "utf-8");
309
309
  } catch {
310
310
  }
311
311
  }
@@ -1791,6 +1791,9 @@ async function dropStash(index) {
1791
1791
  // src/commands/commit.ts
1792
1792
  init_utils();
1793
1793
  import { execSync as execSync5 } from "child_process";
1794
+ import { writeFileSync as writeFileSync3, unlinkSync } from "fs";
1795
+ import { tmpdir } from "os";
1796
+ import { join as join3 } from "path";
1794
1797
  import { select as select6, input as input5, checkbox } from "@inquirer/prompts";
1795
1798
  import ora4 from "ora";
1796
1799
 
@@ -2198,45 +2201,39 @@ function formatFileStatus(status) {
2198
2201
  }
2199
2202
  async function commit() {
2200
2203
  const config2 = getConfig();
2204
+ const autoStage = config2.autoStage ?? true;
2205
+ if (autoStage) {
2206
+ execSync5("git add -A", { stdio: "pipe" });
2207
+ }
2201
2208
  let { staged, unstaged } = parseGitStatus();
2202
- if (unstaged.length > 0) {
2203
- const autoStage = config2.autoStage ?? true;
2204
- if (autoStage) {
2205
- execSync5("git add -A", { stdio: "pipe" });
2206
- console.log(colors.green("\u2714 \u5DF2\u81EA\u52A8\u6682\u5B58\u6240\u6709\u66F4\u6539"));
2207
- divider();
2208
- const newStatus = parseGitStatus();
2209
- staged = newStatus.staged;
2210
- unstaged = newStatus.unstaged;
2211
- } else if (staged.length === 0) {
2212
- console.log(colors.yellow("\u6CA1\u6709\u6682\u5B58\u7684\u66F4\u6539"));
2213
- divider();
2214
- console.log("\u672A\u6682\u5B58\u7684\u6587\u4EF6:");
2215
- for (const { status, file } of unstaged) {
2216
- console.log(` ${formatFileStatus(status)} ${file}`);
2217
- }
2218
- divider();
2219
- const filesToStage = await checkbox({
2220
- message: "\u9009\u62E9\u8981\u6682\u5B58\u7684\u6587\u4EF6:",
2221
- choices: unstaged.map(({ status, file }) => ({
2222
- name: `${formatFileStatus(status)} ${file}`,
2223
- value: file,
2224
- checked: true
2225
- })),
2226
- theme
2227
- });
2228
- if (filesToStage.length === 0) {
2229
- console.log(colors.yellow("\u6CA1\u6709\u9009\u62E9\u4EFB\u4F55\u6587\u4EF6\uFF0C\u5DF2\u53D6\u6D88"));
2230
- return;
2231
- }
2232
- for (const file of filesToStage) {
2233
- execSync5(`git add "${file}"`, { stdio: "pipe" });
2234
- }
2235
- console.log(colors.green(`\u2714 \u5DF2\u6682\u5B58 ${filesToStage.length} \u4E2A\u6587\u4EF6`));
2236
- divider();
2237
- const newStatus = parseGitStatus();
2238
- staged = newStatus.staged;
2209
+ if (staged.length === 0 && unstaged.length > 0 && !autoStage) {
2210
+ console.log(colors.yellow("\u6CA1\u6709\u6682\u5B58\u7684\u66F4\u6539"));
2211
+ divider();
2212
+ console.log("\u672A\u6682\u5B58\u7684\u6587\u4EF6:");
2213
+ for (const { status, file } of unstaged) {
2214
+ console.log(` ${formatFileStatus(status)} ${file}`);
2239
2215
  }
2216
+ divider();
2217
+ const filesToStage = await checkbox({
2218
+ message: "\u9009\u62E9\u8981\u6682\u5B58\u7684\u6587\u4EF6:",
2219
+ choices: unstaged.map(({ status, file }) => ({
2220
+ name: `${formatFileStatus(status)} ${file}`,
2221
+ value: file,
2222
+ checked: true
2223
+ })),
2224
+ theme
2225
+ });
2226
+ if (filesToStage.length === 0) {
2227
+ console.log(colors.yellow("\u6CA1\u6709\u9009\u62E9\u4EFB\u4F55\u6587\u4EF6\uFF0C\u5DF2\u53D6\u6D88"));
2228
+ return;
2229
+ }
2230
+ for (const file of filesToStage) {
2231
+ execSync5(`git add "${file}"`, { stdio: "pipe" });
2232
+ }
2233
+ console.log(colors.green(`\u2714 \u5DF2\u6682\u5B58 ${filesToStage.length} \u4E2A\u6587\u4EF6`));
2234
+ divider();
2235
+ const newStatus = parseGitStatus();
2236
+ staged = newStatus.staged;
2240
2237
  }
2241
2238
  if (staged.length === 0) {
2242
2239
  console.log(colors.yellow("\u5DE5\u4F5C\u533A\u5E72\u51C0\uFF0C\u6CA1\u6709\u9700\u8981\u63D0\u4EA4\u7684\u66F4\u6539"));
@@ -2322,14 +2319,10 @@ async function commit() {
2322
2319
  }
2323
2320
  const spinner = ora4("\u6B63\u5728\u63D0\u4EA4...").start();
2324
2321
  try {
2325
- let finalStatus = parseGitStatus();
2326
- if (finalStatus.staged.length === 0 && finalStatus.unstaged.length > 0) {
2327
- const autoStage = config2.autoStage ?? true;
2328
- if (autoStage) {
2329
- execSync5("git add -A", { stdio: "pipe" });
2330
- finalStatus = parseGitStatus();
2331
- }
2322
+ if (autoStage) {
2323
+ execSync5("git add -A", { stdio: "pipe" });
2332
2324
  }
2325
+ const finalStatus = parseGitStatus();
2333
2326
  if (finalStatus.staged.length === 0) {
2334
2327
  spinner.fail("\u6CA1\u6709\u6682\u5B58\u7684\u6587\u4EF6\u53EF\u4EE5\u63D0\u4EA4");
2335
2328
  console.log("");
@@ -2340,9 +2333,18 @@ async function commit() {
2340
2333
  console.log("");
2341
2334
  return;
2342
2335
  }
2343
- execSync5(`git commit -F -`, {
2344
- input: message
2345
- });
2336
+ const tmpFile = join3(tmpdir(), `.gw-commit-msg-${Date.now()}`);
2337
+ try {
2338
+ writeFileSync3(tmpFile, message, "utf-8");
2339
+ execSync5(`git commit -F "${tmpFile}"`, {
2340
+ stdio: ["pipe", "pipe", "pipe"]
2341
+ });
2342
+ } finally {
2343
+ try {
2344
+ unlinkSync(tmpFile);
2345
+ } catch {
2346
+ }
2347
+ }
2346
2348
  spinner.succeed("\u63D0\u4EA4\u6210\u529F");
2347
2349
  const commitHash = execOutput("git rev-parse --short HEAD");
2348
2350
  console.log(colors.dim(`commit: ${commitHash}`));
@@ -2449,15 +2451,15 @@ import { execSync as execSync7 } from "child_process";
2449
2451
  import ora6 from "ora";
2450
2452
  import boxen2 from "boxen";
2451
2453
  import semver2 from "semver";
2452
- import { existsSync as existsSync4, unlinkSync as unlinkSync2 } from "fs";
2454
+ import { existsSync as existsSync4, unlinkSync as unlinkSync3 } from "fs";
2453
2455
  import { homedir as homedir4 } from "os";
2454
- import { join as join4 } from "path";
2456
+ import { join as join5 } from "path";
2455
2457
  var CACHE_FILE2 = ".gw-update-check";
2456
2458
  function clearUpdateCache2() {
2457
2459
  try {
2458
- const cacheFile = join4(homedir4(), CACHE_FILE2);
2460
+ const cacheFile = join5(homedir4(), CACHE_FILE2);
2459
2461
  if (existsSync4(cacheFile)) {
2460
- unlinkSync2(cacheFile);
2462
+ unlinkSync3(cacheFile);
2461
2463
  }
2462
2464
  } catch {
2463
2465
  }
@@ -2914,7 +2916,7 @@ process.on("SIGTERM", () => {
2914
2916
  console.log("");
2915
2917
  process.exit(0);
2916
2918
  });
2917
- var version = true ? "0.3.7" : "0.0.0-dev";
2919
+ var version = true ? "0.3.8" : "0.0.0-dev";
2918
2920
  async function mainMenu() {
2919
2921
  console.log(
2920
2922
  colors.green(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zjex/git-workflow",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "🚀 极简的 Git 工作流 CLI 工具,让分支管理和版本发布变得轻松愉快",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,4 +1,7 @@
1
1
  import { execSync } from "child_process";
2
+ import { writeFileSync, unlinkSync } from "fs";
3
+ import { tmpdir } from "os";
4
+ import { join } from "path";
2
5
  import { select, input, checkbox } from "@inquirer/prompts";
3
6
  import ora from "ora";
4
7
  import { colors, theme, execOutput, divider } from "../utils.js";
@@ -102,58 +105,52 @@ function formatFileStatus(status: string): string {
102
105
  */
103
106
  export async function commit(): Promise<void> {
104
107
  const config = getConfig();
105
- let { staged, unstaged } = parseGitStatus();
106
-
107
- // ========== 步骤 1: 处理未暂存的文件 ==========
108
- if (unstaged.length > 0) {
109
- const autoStage = config.autoStage ?? true;
108
+ const autoStage = config.autoStage ?? true;
110
109
 
111
- if (autoStage) {
112
- // 自动暂存所有文件
113
- execSync("git add -A", { stdio: "pipe" });
114
- console.log(colors.green("✔ 已自动暂存所有更改"));
115
- divider();
116
- // 重新获取状态
117
- const newStatus = parseGitStatus();
118
- staged = newStatus.staged;
119
- unstaged = newStatus.unstaged;
120
- } else if (staged.length === 0) {
121
- // 没有暂存的文件,且不自动暂存,让用户选择
122
- console.log(colors.yellow("没有暂存的更改"));
123
- divider();
124
- console.log("未暂存的文件:");
125
- for (const { status, file } of unstaged) {
126
- console.log(` ${formatFileStatus(status)} ${file}`);
127
- }
128
- divider();
110
+ // ========== 步骤 1: 自动暂存(如果启用)==========
111
+ if (autoStage) {
112
+ execSync("git add -A", { stdio: "pipe" });
113
+ }
129
114
 
130
- // 让用户选择要暂存的文件
131
- const filesToStage = await checkbox({
132
- message: "选择要暂存的文件:",
133
- choices: unstaged.map(({ status, file }) => ({
134
- name: `${formatFileStatus(status)} ${file}`,
135
- value: file,
136
- checked: true,
137
- })),
138
- theme,
139
- });
115
+ // 获取当前状态
116
+ let { staged, unstaged } = parseGitStatus();
140
117
 
141
- if (filesToStage.length === 0) {
142
- console.log(colors.yellow("没有选择任何文件,已取消"));
143
- return;
144
- }
118
+ // ========== 步骤 2: 如果没有暂存文件,让用户选择 ==========
119
+ if (staged.length === 0 && unstaged.length > 0 && !autoStage) {
120
+ console.log(colors.yellow("没有暂存的更改"));
121
+ divider();
122
+ console.log("未暂存的文件:");
123
+ for (const { status, file } of unstaged) {
124
+ console.log(` ${formatFileStatus(status)} ${file}`);
125
+ }
126
+ divider();
127
+
128
+ // 让用户选择要暂存的文件
129
+ const filesToStage = await checkbox({
130
+ message: "选择要暂存的文件:",
131
+ choices: unstaged.map(({ status, file }) => ({
132
+ name: `${formatFileStatus(status)} ${file}`,
133
+ value: file,
134
+ checked: true,
135
+ })),
136
+ theme,
137
+ });
145
138
 
146
- // 暂存选中的文件
147
- for (const file of filesToStage) {
148
- execSync(`git add "${file}"`, { stdio: "pipe" });
149
- }
150
- console.log(colors.green(`✔ 已暂存 ${filesToStage.length} 个文件`));
151
- divider();
139
+ if (filesToStage.length === 0) {
140
+ console.log(colors.yellow("没有选择任何文件,已取消"));
141
+ return;
142
+ }
152
143
 
153
- // 重新获取状态
154
- const newStatus = parseGitStatus();
155
- staged = newStatus.staged;
144
+ // 暂存选中的文件
145
+ for (const file of filesToStage) {
146
+ execSync(`git add "${file}"`, { stdio: "pipe" });
156
147
  }
148
+ console.log(colors.green(`✔ 已暂存 ${filesToStage.length} 个文件`));
149
+ divider();
150
+
151
+ // 重新获取状态
152
+ const newStatus = parseGitStatus();
153
+ staged = newStatus.staged;
157
154
  }
158
155
 
159
156
  // ========== 步骤 2: 检查是否有文件可提交 ==========
@@ -264,18 +261,13 @@ export async function commit(): Promise<void> {
264
261
  const spinner = ora("正在提交...").start();
265
262
 
266
263
  try {
267
- // 提交前再次检查是否有暂存的文件
268
- let finalStatus = parseGitStatus();
269
-
270
- // 如果暂存区为空,但有未暂存的更改,且开启了自动暂存,则重新暂存
271
- if (finalStatus.staged.length === 0 && finalStatus.unstaged.length > 0) {
272
- const autoStage = config.autoStage ?? true;
273
- if (autoStage) {
274
- execSync("git add -A", { stdio: "pipe" });
275
- finalStatus = parseGitStatus();
276
- }
264
+ // 提交前再次暂存所有更改(确保不会遗漏)
265
+ if (autoStage) {
266
+ execSync("git add -A", { stdio: "pipe" });
277
267
  }
278
268
 
269
+ // 检查是否有暂存的文件
270
+ const finalStatus = parseGitStatus();
279
271
  if (finalStatus.staged.length === 0) {
280
272
  spinner.fail("没有暂存的文件可以提交");
281
273
  console.log("");
@@ -287,11 +279,21 @@ export async function commit(): Promise<void> {
287
279
  return;
288
280
  }
289
281
 
290
- // 处理多行消息:使用 git commit -F - 通过 stdin 传递
291
- // 这样可以正确处理包含换行符的 commit message
292
- execSync(`git commit -F -`, {
293
- input: message,
294
- });
282
+ // 处理多行消息:使用临时文件传递 commit message
283
+ const tmpFile = join(tmpdir(), `.gw-commit-msg-${Date.now()}`);
284
+ try {
285
+ writeFileSync(tmpFile, message, "utf-8");
286
+ execSync(`git commit -F "${tmpFile}"`, {
287
+ stdio: ["pipe", "pipe", "pipe"],
288
+ });
289
+ } finally {
290
+ // 清理临时文件
291
+ try {
292
+ unlinkSync(tmpFile);
293
+ } catch {
294
+ // 忽略删除失败
295
+ }
296
+ }
295
297
  spinner.succeed("提交成功");
296
298
 
297
299
  // 显示提交信息