@done-coding/cli-utils 0.8.2-alpha.1 → 0.8.3-alpha.0

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.
Files changed (3) hide show
  1. package/es/index.mjs +500 -563
  2. package/package.json +11 -10
  3. package/types/index.d.ts +101 -135
package/es/index.mjs CHANGED
@@ -1,32 +1,50 @@
1
1
  #!/usr/bin/env node
2
- import { randomUUID as Ct } from "node:crypto";
3
- import { homedir as W, tmpdir as z } from "node:os";
4
- import l from "node:path";
5
- import g, { existsSync as A, mkdirSync as yt, writeFileSync as G, readFileSync as v } from "node:fs";
6
- import M from "crypto";
7
- import X from "chalk";
8
- import Ot from "prompts";
9
- import Rt from "yargs";
10
- import { hideBin as vt } from "yargs/helpers";
11
- import { execSync as Y } from "node:child_process";
12
- import Z from "json5";
2
+ import { homedir as V, tmpdir as K } from "node:os";
3
+ import f from "node:path";
4
+ import { createOutputLogFile as gt, createOutputConsole as pt, OutputConsoleTypeEnum as mt } from "@done-coding/output-node";
5
+ import g, { existsSync as M, mkdirSync as _t, writeFileSync as D, readFileSync as N } from "node:fs";
6
+ import Et from "dayjs";
7
+ import { default as _r } from "dayjs";
8
+ import v, { randomUUID as dt } from "node:crypto";
9
+ import ht from "prompts";
10
+ import St from "yargs";
11
+ import { hideBin as Ct } from "yargs/helpers";
12
+ import { execSync as p, spawn as Ot } from "node:child_process";
13
+ import W from "json5";
13
14
  export * from "json5";
14
- import { default as Cr } from "json5";
15
- import Mt from "lodash.merge";
16
- import It from "semver";
17
- import { default as Or } from "lodash.get";
18
- import { default as vr } from "lodash.set";
15
+ import { default as hr } from "json5";
16
+ import Rt from "lodash.merge";
17
+ import yt from "semver";
18
+ import { default as Cr } from "lodash.get";
19
+ import { default as Rr } from "lodash.set";
19
20
  import { default as Ir } from "lodash.curry";
20
- import R from "pinyin";
21
- const q = "__DONE_CODING_ENV_CONFIG__", Q = Symbol.for(
22
- q
23
- ), F = ".done-coding", $t = `${F}/cli/assets-config`, At = "assets", Pt = "index.json", Nt = `${F}/config.json`, Lt = "output/log", Dt = "default", Tt = "https://gitee.com/justsosu/done-coding-cli-assets-config.git", Gt = /[^a-zA-Z0-9._\-]/, wt = /[^a-zA-Z0-9._\-]/g, xe = (t) => t ? !Gt.test(t) : !1, bt = (t) => (t || "_").replace(wt, "_"), tt = () => {
24
- const t = /* @__PURE__ */ new Date();
25
- return `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, "0")}-${String(t.getDate()).padStart(2, "0")} ${String(t.getHours()).padStart(2, "0")}:${String(t.getMinutes()).padStart(2, "0")}:${String(t.getSeconds()).padStart(2, "0")}`;
26
- }, et = () => Ct();
27
- var Ft = /* @__PURE__ */ ((t) => (t.DEFAULT = "DEFAULT", t.MCP = "MCP", t))(Ft || {}), Bt = /* @__PURE__ */ ((t) => (t.GLOBAL_CONFIG_IMAGE = "GLOBAL_CONFIG_IMAGE", t))(Bt || {});
28
- const rt = (t) => `${q}_${t}`, st = (t, e) => {
29
- const r = process.env[rt(t)];
21
+ import P from "pinyin";
22
+ import { default as Nr } from "chalk";
23
+ const X = "__DONE_CODING_ENV_CONFIG__", z = Symbol.for(
24
+ X
25
+ ), k = Symbol.for(
26
+ "DONE_CODING_CURRENT_LOG_FILE_NAME"
27
+ ), Z = "DONE_CODING_PROCESS_CREATE_BY_HIJACK_PRESET_JSON", b = ".done-coding", It = `${b}/cli/assets-config`, Pt = "assets", Nt = "index.json", vt = `${b}/config.json`, At = "output/log", q = "default", Tt = "https://gitee.com/justsosu/done-coding-cli-assets-config.git", $ = 73, Mt = (t) => {
28
+ const r = g.statSync(t).mode;
29
+ if ((r & $) === $)
30
+ return;
31
+ l.stage(`${t} 没有执行权限 添加... `);
32
+ const s = r | $;
33
+ g.chmodSync(t, s), l.success(`${t} 添加执行权限成功`);
34
+ }, w = (t) => g.existsSync(t), B = async (t) => {
35
+ try {
36
+ return await g.promises.lstat(t), !0;
37
+ } catch (e) {
38
+ return e.code !== "ENOENT";
39
+ }
40
+ }, Lt = (t, e = !1) => {
41
+ w(t) && g.rmSync(t, { recursive: !0, force: e });
42
+ }, $t = async (t, e = !1) => {
43
+ await B(t) && await g.promises.rm(t, { recursive: !0, force: e });
44
+ }, Dt = (t) => g.readFileSync(t, "utf-8"), Gt = (t) => g.promises.readFile(t, "utf-8"), Fe = (t, e) => JSON.parse(Dt(t)) || e, Q = async (t, e) => JSON.parse(await Gt(t)) || e;
45
+ var Ft = /* @__PURE__ */ ((t) => (t.GLOBAL_CONFIG_IMAGE = "GLOBAL_CONFIG_IMAGE", t))(Ft || {});
46
+ const tt = (t) => `${X}_${t}`, et = (t, e) => {
47
+ const r = process.env[tt(t)];
30
48
  if (r !== void 0)
31
49
  try {
32
50
  return JSON.parse(r).value;
@@ -35,193 +53,120 @@ const rt = (t) => `${q}_${t}`, st = (t, e) => {
35
53
  }
36
54
  else
37
55
  return e;
38
- }, Ut = (t, e) => {
39
- if (st(t) !== void 0)
40
- return !1;
41
- const s = rt(t), n = { value: e };
42
- return process.env[s] = JSON.stringify(n), !0;
43
- }, B = () => globalThis[Q], U = (t) => {
44
- const e = B();
45
- if (e)
46
- return e;
47
- const r = Object.freeze({
56
+ }, bt = (t, e) => {
57
+ et(t);
58
+ const r = tt(t), s = { value: e };
59
+ process.env[r] = JSON.stringify(s);
60
+ }, rt = () => globalThis[z], st = () => {
61
+ const t = globalThis[k];
62
+ if (t)
63
+ return t;
64
+ {
65
+ const e = `${Et().format("YYYY-MM-DD_HH-mm-ss")}_${process.pid}.log`;
66
+ return globalThis[k] = e, e;
67
+ }
68
+ }, wt = (t) => {
69
+ const r = {
70
+ ...rt() || {},
48
71
  ...t
49
- });
50
- return Object.defineProperty(globalThis, Q, {
51
- value: r,
52
- writable: !1,
53
- enumerable: !1,
54
- configurable: !1
55
- }), Ut("GLOBAL_CONFIG_IMAGE", r), r;
56
- }, nt = () => st(
72
+ };
73
+ return bt("GLOBAL_CONFIG_IMAGE", r), globalThis[z] = r, r;
74
+ }, Bt = () => et(
57
75
  "GLOBAL_CONFIG_IMAGE"
58
76
  /* GLOBAL_CONFIG_IMAGE */
59
- ), jt = typeof process.send == "function", ot = (t = Dt) => {
60
- const e = bt(t);
61
- return {
62
- callMode: "DEFAULT",
63
- series: e,
64
- consoleLog: !0,
65
- logOutputDir: `${F}/${e}/${Lt}`,
66
- processLogFileNameList: []
67
- };
68
- }, j = `${tt()}-${et()}`, it = (t) => {
69
- const e = {
70
- ...t,
71
- processLogFileNameList: [
72
- j,
73
- ...t.processLogFileNameList
74
- ].slice(0, 10)
75
- };
76
- return U(e);
77
- }, C = () => {
78
- const t = B();
77
+ ), nt = (t) => `${b}/${t}/${At}`, Ut = () => {
78
+ const t = Bt();
79
+ let e;
79
80
  if (t)
80
- return t;
81
- const e = nt();
82
- if (e)
83
- return it(e);
84
- {
85
- const s = {
86
- ...ot(),
87
- processLogFileNameList: [j]
81
+ e = t;
82
+ else {
83
+ const m = q;
84
+ e = {
85
+ series: m,
86
+ consoleLog: !0,
87
+ logOutputDir: nt(m),
88
+ processLogFileNameList: []
88
89
  };
89
- return U(s);
90
- }
91
- }, ke = ({
92
- series: t,
93
- ...e
94
- }) => {
95
- if (jt)
96
- throw new Error("非顶级进程不允许调用该方法");
97
- if (B())
98
- throw new Error(`内存全局配置存在,说明是以下某个原因:
99
- 1. 顶级进程重复调用initEnvConfig
100
- 2. 顶级进程在调用该方法之前调用了getApplyConfig, 即获取配置应用的同时会冻结配置 不会后续变化
101
- ------
102
- 如果是顶级进程 请第一时间调用,请给对应调用包专门顶级进程才会调用的入口 并调用此方法
103
- 如 mcp模式入口 需要第一时间调用此方法
104
- `);
105
- {
106
- const s = nt();
107
- if (s)
108
- return it(s);
109
- {
110
- const o = {
111
- ...ot(t),
112
- ...e,
113
- processLogFileNameList: [j]
114
- };
115
- return U(o);
116
- }
117
90
  }
118
- }, ct = () => C().callMode, xt = () => ct() === "MCP", at = () => xt() ? !1 : C().consoleLog, kt = (t = !1) => l.resolve(
119
- t ? W() : z(),
120
- C().logOutputDir
121
- ), Ht = () => C().processLogFileNameList[0], Jt = () => C().processLogFileNameList[1];
122
- var m = /* @__PURE__ */ ((t) => (t.SYSTEM = "magenta", t.SUCCESS = "greenBright", t.STAGE = "blue", t.INFO = "white", t.WARN = "yellow", t.ERROR = "redBright", t.SKIP = "dim", t.TABLE = "table", t))(m || {});
123
- const Yt = Object.entries(m).reduce(
124
- (t, [e, r]) => (t[r] = e, t),
125
- {}
126
- ), Vt = (t) => Yt[t] ?? t, E = /* @__PURE__ */ new Map(), Kt = (t) => {
127
- const e = l.resolve(t), r = l.dirname(e), s = E.get(e);
128
- if (s) {
129
- if (!s.destroyed && s.writable)
130
- return s;
131
- E.delete(e);
132
- }
133
- g.existsSync(r) || g.mkdirSync(r, { recursive: !0 });
134
- const n = g.openSync(e, "a"), o = g.createWriteStream(e, {
135
- fd: n,
136
- autoClose: !0,
137
- // 关键:stream 销毁时自动关 fd
138
- encoding: "utf8",
139
- highWaterMark: 64 * 1024
140
- });
141
- if (o.on("error", () => {
142
- E.delete(e), o.destroy();
143
- }), o.on("close", () => {
144
- E.delete(e);
145
- }), E.set(e, o), typeof o.fd != "number")
146
- throw new Error(
147
- `Failed to get file descriptor from stream for ${o.path}`
148
- );
149
- return o;
150
- };
151
- process.once("exit", () => {
152
- for (const t of E.values())
91
+ const {
92
+ series: r,
93
+ consoleLog: s,
94
+ logOutputDir: n,
95
+ processLogFileNameList: o
96
+ } = e, c = st(), i = (o[0] === c ? o : [c, ...o]).slice(0, 10), u = process.env[Z];
97
+ let a;
98
+ if (u)
153
99
  try {
154
- t.destroyed || t.end();
100
+ a = JSON.parse(
101
+ u
102
+ );
155
103
  } catch {
156
104
  }
157
- });
158
- const d = ({
159
- stream: t,
160
- type: e,
161
- content: r
162
- }) => t.write(
163
- `[${tt()}] [${Vt(e)}] ${r}
164
- `
165
- );
166
- let V = !1;
167
- const ft = () => {
168
- const t = kt(), e = l.resolve(t, Ht()), r = Kt(e);
169
- if (!V) {
170
- const s = Jt();
171
- s && d({
172
- stream: r,
173
- type: m.SYSTEM,
174
- content: `父进程日志文件: ${s}`
175
- });
176
- const n = ct();
177
- d({
178
- stream: r,
179
- type: m.SYSTEM,
180
- content: `当前调用模式: ${n}`
181
- }), V = !0;
182
- }
183
- return r;
184
- }, Wt = (t, e) => {
185
- const r = ft(), s = t.map((n) => n instanceof Error ? n.stack || n.message : typeof n == "object" && n !== null ? JSON.stringify(n) : String(n)).join(" ");
186
- d({
187
- stream: r,
188
- type: e,
189
- content: s
105
+ return {
106
+ series: r,
107
+ consoleLog: s,
108
+ logOutputDir: n,
109
+ processLogFileNameList: i,
110
+ /** 自身或祖先进程是否被劫持进程创建 */
111
+ processCreateByHijack: !!a,
112
+ /** 自身或祖先进程被劫持进程创建 行为预设信息 */
113
+ processCreateByHijackPresetInfo: a
114
+ };
115
+ }, C = () => rt() || Ut(), be = ({
116
+ series: t = q,
117
+ consoleLog: e = !0
118
+ }) => {
119
+ const r = nt(t), s = {
120
+ ...C(),
121
+ series: t,
122
+ consoleLog: e,
123
+ logOutputDir: r
124
+ };
125
+ return wt(s);
126
+ }, x = () => C().processCreateByHijack, we = () => C().processCreateByHijackPresetInfo, Ht = (t = !1) => {
127
+ const e = f.resolve(
128
+ t ? V() : K(),
129
+ C().logOutputDir
130
+ );
131
+ return w(e) || g.mkdirSync(e, { recursive: !0 }), e;
132
+ }, jt = () => C().processLogFileNameList[1], kt = (() => {
133
+ const t = gt({
134
+ logFilePath: f.resolve(
135
+ Ht(),
136
+ st()
137
+ )
190
138
  });
191
- }, zt = (...[t, ...e]) => at() ? t === m.TABLE ? console.table(...e) : console.log(X[t](...e)) : Wt(e, t), lt = (t) => Object.assign(t, {
192
- /** 系统 */
193
- system: (...e) => t(m.SYSTEM, ...e),
194
- /** 成功 */
195
- success: (...e) => t(m.SUCCESS, ...e),
196
- /** /步骤 */
197
- stage: (...e) => t(m.STAGE, ...e),
198
- /** 提示信息 */
199
- info: (...e) => t(m.INFO, ...e),
200
- /** 警告 */
201
- warn: (...e) => t(m.WARN, ...e),
202
- /** 错误 */
203
- error: (...e) => t(m.ERROR, ...e),
204
- /** 跳过 */
205
- skip: (...e) => t(m.SKIP, ...e),
206
- /** 表格 */
207
- table: (...e) => t(m.TABLE, ...e)
208
- }), a = lt(zt), He = lt(
209
- (t, ...e) => t === m.TABLE ? JSON.stringify(e) : X[t](...e)
210
- ), Je = (t, {
139
+ let e = !1;
140
+ if (!e) {
141
+ const r = jt();
142
+ r && (t.info(`父进程日志文件: ${r}`), e = !0);
143
+ }
144
+ return t;
145
+ })(), xt = (t) => {
146
+ const e = C();
147
+ return typeof e.consoleLog == "boolean" ? e.consoleLog : e.consoleLog.includes(t);
148
+ }, l = pt({
149
+ isSwitchLogFile: (t) => !xt(t),
150
+ enableColor: !0,
151
+ outputFileFn: (t, ...e) => kt.info({
152
+ consoleType: mt[t],
153
+ consoleMessages: e
154
+ })
155
+ }), Be = (t, {
211
156
  /** 当前目录 */
212
157
  currentDir: e = process.cwd(),
213
158
  /** 优先找最远的父目录 */
214
159
  isFindFarthest: r = !0
215
160
  } = {}) => {
216
- const s = l.resolve(e).split(l.sep).map((n, o, c) => c.slice(0, o).concat(n).join(l.sep) || l.sep);
161
+ const s = f.resolve(e).split(f.sep).map((n, o, c) => c.slice(0, o).concat(n).join(f.sep) || f.sep);
217
162
  for (; s.length; ) {
218
- const n = r ? s.shift() : s.pop(), o = l.join(n, t);
163
+ const n = r ? s.shift() : s.pop(), o = f.join(n, t);
219
164
  if (g.existsSync(o))
220
165
  return n;
221
166
  }
222
- }, ut = "aes-256-cbc", gt = 16, I = "hex", w = ":";
223
- function pt(t) {
224
- return M.pbkdf2Sync(
167
+ }, ot = "aes-256-cbc", it = 16, A = "hex", G = ":";
168
+ function ct(t) {
169
+ return v.pbkdf2Sync(
225
170
  t,
226
171
  "done-coding-cli-salt",
227
172
  // 使用固定的盐值
@@ -232,67 +177,100 @@ function pt(t) {
232
177
  "sha256"
233
178
  );
234
179
  }
235
- function Ye({
180
+ function Ue({
236
181
  text: t,
237
182
  secretKey: e
238
183
  }) {
239
184
  try {
240
- const r = pt(e), s = M.randomBytes(gt), n = M.createCipheriv(ut, r, s);
185
+ const r = ct(e), s = v.randomBytes(it), n = v.createCipheriv(
186
+ ot,
187
+ r,
188
+ s
189
+ );
241
190
  let o = n.update(t);
242
191
  o = Buffer.concat([o, n.final()]);
243
- const c = s.toString(I), i = o.toString(I);
244
- return `${c}${w}${i}`;
192
+ const c = s.toString(A), i = o.toString(A);
193
+ return `${c}${G}${i}`;
245
194
  } catch (r) {
246
- return a.error(
195
+ return l.error(
247
196
  `加密失败: ${r instanceof Error ? r.message : String(r)}`
248
197
  ), "";
249
198
  }
250
199
  }
251
- function Ve({
200
+ function He({
252
201
  encryptedText: t,
253
202
  secretKey: e
254
203
  }) {
255
204
  try {
256
- if (!t.includes(w))
205
+ if (!t.includes(G))
257
206
  return "";
258
- const r = pt(e), [s, n] = t.split(w);
259
- if (s.length !== gt * 2)
207
+ const r = ct(e), [s, n] = t.split(G);
208
+ if (s.length !== it * 2)
260
209
  return "";
261
- const o = Buffer.from(s, I), c = Buffer.from(n, I), i = M.createDecipheriv(ut, r, o);
262
- let f = i.update(c);
263
- return f = Buffer.concat([f, i.final()]), f.toString();
210
+ const o = Buffer.from(s, A), c = Buffer.from(n, A), i = v.createDecipheriv(
211
+ ot,
212
+ r,
213
+ o
214
+ );
215
+ let u = i.update(
216
+ c
217
+ );
218
+ return u = Buffer.concat([u, i.final()]), u.toString();
264
219
  } catch (r) {
265
- return a.error(
220
+ return l.error(
266
221
  `解密失败: ${r instanceof Error ? r.message : String(r)}`
267
222
  ), "";
268
223
  }
269
224
  }
270
- const P = (...t) => {
225
+ const at = {
226
+ /** prompts 开始等待用户输入 */
227
+ PROMPTS_START_WAIT_USER_INPUT: "PROMPTS_START_WAIT_USER_INPUT",
228
+ /** prompts 结束等待用户输入 */
229
+ PROMPTS_END_WAIT_USER_INPUT: "PROMPTS_END_WAIT_USER_INPUT"
230
+ }, Jt = (t) => ({
231
+ type: at.PROMPTS_START_WAIT_USER_INPUT,
232
+ data: t
233
+ }), Yt = () => ({
234
+ type: at.PROMPTS_END_WAIT_USER_INPUT
235
+ }), J = (t) => (l.debug("发送进程自定义事件", t), new Promise((e, r) => {
236
+ process.send ? process.send(t, (s) => {
237
+ s ? (l.error("发送进程自定义事件失败", s), r(s)) : (l.debug("发送进程自定义事件成功", t), e());
238
+ }) : (l.error(
239
+ "进程自定义事件发送失败,process.send is not defined"
240
+ ), r(new Error("process.send is not defined")));
241
+ })), U = async (...t) => {
271
242
  const [e, r = {}] = t;
272
- return Ot(e, {
273
- onCancel(s) {
274
- return a.error(`退出${s == null ? void 0 : s.name}输入`), process.exit(1);
243
+ if (x())
244
+ return await J(Jt(t)), process.exit(1);
245
+ const s = ht(e, {
246
+ onCancel(n) {
247
+ return l.error(
248
+ `您取消了 “${(n == null ? void 0 : n.message) || (n == null ? void 0 : n.name)}” 相关表单输入`
249
+ ), process.exit(1);
275
250
  },
276
251
  ...r
277
252
  });
278
- }, Ke = async ({
279
- isMCP: t,
253
+ return x() && s.finally(() => {
254
+ J(Yt());
255
+ }), s;
256
+ }, Vt = async ({
257
+ key: t,
258
+ presetAnswer: e,
259
+ defaultValue: r,
260
+ questionConfig: s
261
+ }) => (e == null ? void 0 : e[t]) ?? r ?? (s !== void 0 ? (await U(s))[t] : void 0), je = ({
262
+ presetAnswer: t
263
+ }) => async (e, r, s) => Vt({
280
264
  key: e,
281
- presetAnswer: r,
265
+ questionConfig: r,
282
266
  defaultValue: s,
283
- questionConfig: n
284
- }) => {
285
- if (t) {
286
- const o = r == null ? void 0 : r[e];
287
- return o === void 0 ? (a.error("MCP场景的约束值不能为空"), process.exit(1)) : o;
288
- } else
289
- return (r == null ? void 0 : r[e]) ?? s ?? (await P(n))[e];
290
- }, We = async (t, e) => (await P(e))[t], Xt = (t, e) => {
291
- t ? a.error(t) : a.error(e.message), e != null && e.stack && a.error(e.stack), process.exit(1);
292
- }, Zt = () => {
293
- const t = vt(process.argv);
294
- return Rt(t);
295
- }, ze = ({
267
+ presetAnswer: t
268
+ }), Kt = (t, e) => {
269
+ t ? l.error(t) : l.error(e.message), e != null && e.stack && l.error(e.stack), process.exit(1);
270
+ }, Wt = () => {
271
+ const t = Ct(process.argv);
272
+ return St(t);
273
+ }, ke = ({
296
274
  rootScriptName: t,
297
275
  packageJson: e
298
276
  }) => {
@@ -305,14 +283,14 @@ const P = (...t) => {
305
283
  if (typeof r == "string")
306
284
  return s.includes("/") ? void 0 : s;
307
285
  if (typeof r == "object") {
308
- const n = Object.entries(r), o = process.argv[1], c = n.filter(([, f]) => o == null ? void 0 : o.endsWith(f));
286
+ const n = Object.entries(r), o = process.argv[1], c = n.filter(([, u]) => o == null ? void 0 : o.endsWith(u));
309
287
  if (c.length !== 1)
310
288
  return;
311
289
  const [i] = c[0];
312
290
  return process.platform === "win32" ? i.toLowerCase() : i;
313
291
  }
314
292
  }
315
- }, mt = (t, {
293
+ }, lt = (t, {
316
294
  usage: e,
317
295
  version: r,
318
296
  demandCommandCount: s,
@@ -320,89 +298,31 @@ const P = (...t) => {
320
298
  positionals: o,
321
299
  subcommands: c,
322
300
  rootScriptName: i
323
- }, f) => {
324
- let u = t.strict();
325
- e && (u = u.usage(`Usage: ${e}`)), s && (u = u.demandCommand(s));
326
- const S = "help";
327
- return u = u.help(S), r ? u = u.version(r).alias("h", S).alias("v", "version") : u = u.alias("h", S), n && (u = u.options(n)), o && (u = Object.entries(o).reduce((y, [L, h]) => y.positional(L, h), u)), c && (u = u.command(c)), f && i && (u = u.scriptName(i)), u;
328
- }, Xe = async ({ handler: t, ...e }) => {
329
- const r = await mt(Zt(), e, !0).fail(
330
- Xt
301
+ }, u) => {
302
+ let a = t.strict();
303
+ e && (a = a.usage(`Usage: ${e}`)), s && (a = a.demandCommand(s));
304
+ const m = "help";
305
+ return a = a.help(m), r ? a = a.version(r).alias("h", m).alias("v", "version") : a = a.alias("h", m), n && (a = a.options(n)), o && (a = Object.entries(o).reduce((h, [O, E]) => h.positional(O, E), a)), c && (a = a.command(c)), u && i && (a = a.scriptName(i)), a;
306
+ }, xe = async ({ handler: t, ...e }) => {
307
+ const r = await lt(Wt(), e, !0).fail(
308
+ Kt
331
309
  ).argv;
332
310
  return t ? t(r) : r;
333
- }, Ze = (t) => {
311
+ }, Je = (t) => {
334
312
  const { command: e, describe: r, handler: s = () => {
335
313
  }, ...n } = t;
336
314
  return {
337
315
  command: e,
338
316
  describe: r,
339
317
  builder(o) {
340
- return mt(o, n, !1);
318
+ return lt(o, n, !1);
341
319
  },
342
320
  handler: s
343
321
  };
344
- }, qt = (t) => {
345
- if (!t)
346
- return ["pipe", "pipe", "pipe"];
347
- if (typeof t == "string")
348
- switch (t) {
349
- case "ignore":
350
- return ["ignore", "ignore", "ignore"];
351
- case "inherit":
352
- return ["inherit", "inherit", "inherit"];
353
- case "overlapped":
354
- return ["overlapped", "overlapped", "overlapped"];
355
- default:
356
- return ["pipe", "pipe", "pipe"];
357
- }
358
- if (Array.isArray(t)) {
359
- const e = [...t];
360
- for (let r = 0; r < 3; r++)
361
- e[r] === void 0 && (e[r] = "pipe");
362
- return e;
363
- }
364
- return ["pipe", "pipe", "pipe"];
365
- }, p = (t, e) => {
366
- if (at() || (e == null ? void 0 : e.stdio) === "ignore")
367
- return Y(t, e);
368
- const s = ft(), n = s.fd, o = qt(e == null ? void 0 : e.stdio), c = o.map((i, f) => f === 0 ? "ignore" : (f === 1 || f === 2) && (i === "inherit" || i === "overlapped") ? n : i);
369
- try {
370
- d({
371
- stream: s,
372
- type: m.SYSTEM,
373
- content: `[子进程任务开始执行] ${t}`
374
- });
375
- const i = Y(t, {
376
- maxBuffer: 1024 * 1024 * 100,
377
- // 增加到 100MB,防止 pipe 模式下大数据溢出
378
- ...e,
379
- stdio: c,
380
- encoding: (e == null ? void 0 : e.encoding) || "utf-8"
381
- });
382
- return i && o[1] === "pipe" ? d({
383
- stream: s,
384
- type: m.SYSTEM,
385
- content: `[任务执行成功返回]: ${i.toString().trim()}`
386
- }) : d({
387
- stream: s,
388
- type: m.SYSTEM,
389
- content: "[任务执行成功]"
390
- }), i;
391
- } catch (i) {
392
- const f = i.stderr ? `
393
- STDERR: ${i.stderr}` : "";
394
- throw d({
395
- stream: s,
396
- type: m.ERROR,
397
- content: `[任务执行失败]: ${t}
398
- STATUS: ${i.status}
399
- MSG: ${i.message}${f}`
400
- }), i;
401
- }
402
322
  };
403
- var Qt = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(Qt || {});
404
- const te = async () => {
405
- const { editorType: t } = await P([
323
+ var Xt = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(Xt || {});
324
+ const zt = async () => {
325
+ const { editorType: t } = await U([
406
326
  {
407
327
  name: "editorType",
408
328
  type: "select",
@@ -419,24 +339,24 @@ const te = async () => {
419
339
  }
420
340
  ]);
421
341
  return t;
422
- }, ee = {
342
+ }, Zt = {
423
343
  Cursor: "cursor",
424
344
  VsCode: "code"
425
- }, re = (t, e, r) => {
345
+ }, qt = (t, e, r) => {
426
346
  try {
427
347
  p(`${t} -v`, { stdio: "ignore" }), p(`${t} ${e}`);
428
348
  } catch {
429
349
  r();
430
350
  }
431
- }, se = (t, e) => {
432
- const r = (s) => a.info(`
351
+ }, Qt = (t, e) => {
352
+ const r = (s) => l.info(`
433
353
  ${s}, 请用编辑器打开 ${t} 进行编辑
434
354
  `);
435
355
  switch (e) {
436
356
  case "Cursor":
437
357
  case "VsCode": {
438
- const s = ee[e];
439
- re(s, t, () => {
358
+ const s = Zt[e];
359
+ qt(s, t, () => {
440
360
  r(`${s}命令未安装`);
441
361
  });
442
362
  break;
@@ -444,7 +364,7 @@ const te = async () => {
444
364
  default:
445
365
  r("其他编辑器");
446
366
  }
447
- }, ne = (t = process.cwd()) => ({
367
+ }, te = (t = process.cwd()) => ({
448
368
  /** 必须保留 */
449
369
  rootDir: {
450
370
  type: "string",
@@ -453,12 +373,12 @@ const te = async () => {
453
373
  /** 必须设置默认值 */
454
374
  default: t
455
375
  }
456
- }), qe = ({
376
+ }), Ye = ({
457
377
  configPathDefault: t,
458
378
  rootDirDefault: e
459
379
  }) => ({
460
380
  /** 必须保留 */
461
- ...ne(e),
381
+ ...te(e),
462
382
  /** 必须保留 */
463
383
  configPath: {
464
384
  type: "string",
@@ -467,77 +387,77 @@ const te = async () => {
467
387
  /** 必须设置默认值 */
468
388
  default: t
469
389
  }
470
- }), oe = async (t, e) => {
471
- const { configPath: r, rootDir: s } = e, n = l.resolve(s, r), o = l.dirname(n);
472
- return A(o) || yt(o, {
390
+ }), ee = async (t, e) => {
391
+ const { configPath: r, rootDir: s } = e, n = f.resolve(s, r), o = f.dirname(n);
392
+ return M(o) || _t(o, {
473
393
  recursive: !0
474
- }), n.endsWith(".json5") ? (a.info(`json5模式写入 ${n}`), G(n, Z.stringify(t, null, 2)), n) : (a.info(`json模式写入 ${n}`), G(n, JSON.stringify(t, null, 2)), n);
475
- }, Qe = async (t, e, {
394
+ }), n.endsWith(".json5") ? (l.info(`json5模式写入 ${n}`), D(n, W.stringify(t, null, 2)), n) : (l.info(`json模式写入 ${n}`), D(n, JSON.stringify(t, null, 2)), n);
395
+ }, Ve = async (t, e, {
476
396
  onFileGenerated: r,
477
397
  edit: s = !1
478
398
  } = {}) => {
479
- const n = await oe(t, e);
399
+ const n = await ee(t, e);
480
400
  if (r == null || r(n), s) {
481
- const o = await te();
482
- se(e.configPath, o);
401
+ const o = await zt();
402
+ Qt(e.configPath, o);
483
403
  }
484
- }, tr = async (t, e) => {
485
- const { configPath: r, rootDir: s } = t, n = l.resolve(s, r);
486
- if (!A(n)) {
404
+ }, Ke = async (t, e) => {
405
+ const { configPath: r, rootDir: s } = t, n = f.resolve(s, r);
406
+ if (!M(n)) {
487
407
  if (e)
488
- return a.info("配置文件不存在,使用onNotExists返回值"), e();
408
+ return l.info("配置文件不存在,使用onNotExists返回值"), e();
489
409
  const o = `配置文件不存在 ${n}`;
490
410
  throw new Error(o);
491
411
  }
492
- return n.endsWith(".json5") ? (a.info(`json5模式解析 ${n}`), Z.parse(v(n, "utf8"))) : (a.info(`json模式解析 ${n}`), JSON.parse(v(n, "utf8")));
493
- }, er = async () => {
494
- const { useDefaultConfig: t } = await P({
412
+ return n.endsWith(".json5") ? (l.info(`json5模式解析 ${n}`), W.parse(N(n, "utf8"))) : (l.info(`json模式解析 ${n}`), JSON.parse(N(n, "utf8")));
413
+ }, We = async () => {
414
+ const { useDefaultConfig: t } = await U({
495
415
  name: "useDefaultConfig",
496
416
  type: "confirm",
497
417
  message: "使用默认模板配置",
498
418
  initial: !0
499
419
  });
500
420
  return t;
501
- }, St = "package.json", x = ({
421
+ }, ut = "package.json", H = ({
502
422
  rootDir: t
503
423
  }) => {
504
- const e = l.resolve(t, St);
505
- if (!A(e))
424
+ const e = f.resolve(t, ut);
425
+ if (!M(e))
506
426
  throw new Error(`${t}未找到package.json文件`);
507
- const r = v(e, "utf-8");
427
+ const r = N(e, "utf-8");
508
428
  return JSON.parse(r);
509
- }, ie = ({
429
+ }, re = ({
510
430
  rootDir: t,
511
431
  pkgJson: e,
512
432
  pkgName: r,
513
433
  isDevPkg: s
514
434
  }) => {
515
- const n = e || x({ rootDir: t }), o = s ? n.devDependencies : n.dependencies;
435
+ const n = e || H({ rootDir: t }), o = s ? n.devDependencies : n.dependencies;
516
436
  let c = o == null ? void 0 : o[r];
517
437
  if (!c) {
518
438
  const i = s ? n.dependencies : n.devDependencies;
519
- c = i == null ? void 0 : i[r], c && a.warn(
439
+ c = i == null ? void 0 : i[r], c && l.warn(
520
440
  `${s ? "开发" : "生产"}依赖包${r}可能错误的安装在${s ? "dependencies" : "devDependencies"}`
521
441
  );
522
442
  return;
523
443
  }
524
- return c || a.info(`依赖包${r}未安装`), c;
525
- }, rr = ({
444
+ return c || l.info(`依赖包${r}未安装`), c;
445
+ }, Xe = ({
526
446
  patchConfig: t,
527
447
  rootDir: e
528
448
  }) => {
529
449
  if (!t)
530
450
  return;
531
- const r = x({ rootDir: e }), s = Mt(r, t), n = l.resolve(e, St);
532
- G(n, JSON.stringify(s, null, 2), "utf-8");
533
- }, N = (t) => {
451
+ const r = H({ rootDir: e }), s = Rt(r, t), n = f.resolve(e, ut);
452
+ D(n, JSON.stringify(s, null, 2), "utf-8");
453
+ }, L = (t) => {
534
454
  const r = p("git rev-parse --show-toplevel", {
535
455
  cwd: t
536
456
  }).toString();
537
457
  if (!r)
538
458
  throw new Error("获取git根目录失败");
539
459
  return r.trim();
540
- }, sr = () => {
460
+ }, ze = () => {
541
461
  var t;
542
462
  try {
543
463
  const e = p("git symbolic-ref --short HEAD", {
@@ -547,12 +467,14 @@ const te = async () => {
547
467
  } catch {
548
468
  try {
549
469
  const r = p("git rev-parse --short HEAD").toString().trim();
550
- a.skip(`当前未指向具体某个分支, 当前commit hash: ${r}`);
470
+ l.skip(
471
+ `当前未指向具体某个分支, 当前commit hash: ${r}`
472
+ );
551
473
  } finally {
552
474
  return;
553
475
  }
554
476
  }
555
- }, ce = (t) => {
477
+ }, se = (t) => {
556
478
  const e = t.match(/moving\s+from\s+(.*)\s+to\s+(.*)/);
557
479
  if (e) {
558
480
  const [, r, s] = e;
@@ -561,149 +483,124 @@ const te = async () => {
561
483
  toBranch: s.trim()
562
484
  };
563
485
  }
564
- }, T = 73, ae = (t) => {
565
- const r = g.statSync(t).mode;
566
- if ((r & T) === T)
567
- return;
568
- a.stage(`${t} 没有执行权限 添加... `);
569
- const s = r | T;
570
- g.chmodSync(t, s), a.success(`${t} 添加执行权限成功`);
571
- }, ht = (t) => g.existsSync(t), k = async (t) => {
572
- try {
573
- return await g.promises.lstat(t), !0;
574
- } catch (e) {
575
- return e.code !== "ENOENT";
576
- }
577
- }, fe = (t, e = !1) => {
578
- ht(t) && g.rmSync(t, { recursive: !0, force: e });
579
- }, le = async (t, e = !1) => {
580
- await k(t) && await g.promises.rm(t, { recursive: !0, force: e });
581
- }, ue = (t) => g.readFileSync(t, "utf-8"), ge = (t) => g.promises.readFile(t, "utf-8"), nr = (t, e) => JSON.parse(ue(t)) || e, dt = async (t, e) => JSON.parse(await ge(t)) || e;
582
- var _ = /* @__PURE__ */ ((t) => (t.PRE_COMMIT = "pre-commit", t.PRE_MERGE_COMMIT = "pre-merge-commit", t.PREPARE_COMMIT_MSG = "prepare-commit-msg", t.COMMIT_MSG = "commit-msg", t.PRE_REBASE = "pre-rebase", t.POST_COMMIT = "post-commit", t.POST_MERGE = "post-merge", t.PRE_PUSH = "pre-push", t))(_ || {});
583
- const pe = "husky", me = ".husky", Se = ({ rootDir: t }) => {
584
- const e = N(t), r = ie({
486
+ };
487
+ var y = /* @__PURE__ */ ((t) => (t.PRE_COMMIT = "pre-commit", t.PRE_MERGE_COMMIT = "pre-merge-commit", t.PREPARE_COMMIT_MSG = "prepare-commit-msg", t.COMMIT_MSG = "commit-msg", t.PRE_REBASE = "pre-rebase", t.POST_COMMIT = "post-commit", t.POST_MERGE = "post-merge", t.PRE_PUSH = "pre-push", t))(y || {});
488
+ const ne = "husky", oe = ".husky", ie = ({ rootDir: t }) => {
489
+ const e = L(t), r = re({
585
490
  rootDir: e,
586
- pkgJson: x({ rootDir: e }),
587
- pkgName: pe,
491
+ pkgJson: H({ rootDir: e }),
492
+ pkgName: ne,
588
493
  isDevPkg: !0
589
494
  });
590
495
  if (!r)
591
496
  throw new Error("husky版本获取失败, 可能husky未安装");
592
497
  const s = r.replace(/^(\^|~)/, ""), n = "<9.0.0";
593
- return It.satisfies(s, n) ? (a.info(`${s}符合${n}`), `#!/usr/bin/env sh
594
- . "$(dirname -- "$0")/_/husky.sh"`) : (a.info(`${s}不符合${n}`), "");
595
- }, he = ({ rootDir: t }) => {
596
- const e = N(t);
597
- return l.resolve(e, me);
598
- }, or = ({
498
+ return yt.satisfies(s, n) ? (l.info(`${s}符合${n}`), `#!/usr/bin/env sh
499
+ . "$(dirname -- "$0")/_/husky.sh"`) : (l.info(`${s}不符合${n}`), "");
500
+ }, ce = ({ rootDir: t }) => {
501
+ const e = L(t);
502
+ return f.resolve(e, oe);
503
+ }, Ze = ({
599
504
  hookNames: t,
600
505
  rootDir: e,
601
506
  getCode: r
602
507
  }) => {
603
- const s = he({ rootDir: e });
508
+ const s = ce({ rootDir: e });
604
509
  g.existsSync(s) || g.mkdirSync(s, { recursive: !0 }), t.forEach((n) => {
605
- const o = l.resolve(s, n), c = g.existsSync(o);
510
+ const o = f.resolve(s, n), c = g.existsSync(o);
606
511
  let i = r(n);
607
512
  if (c)
608
- g.readFileSync(o, "utf-8").includes(i) ? a.skip(`${o} ${n}相关调用 ${i} 已存在 跳过`) : (g.appendFileSync(
513
+ g.readFileSync(o, "utf-8").includes(i) ? l.skip(
514
+ `${o} ${n}相关调用 ${i} 已存在 跳过`
515
+ ) : (g.appendFileSync(
609
516
  o,
610
517
  `
611
518
  ${i}
612
519
  `
613
- ), a.success(`${o} 添加 ${n}相关调用成功`));
520
+ ), l.success(`${o} 添加 ${n}相关调用成功`));
614
521
  else {
615
- const f = Se({
522
+ const u = ie({
616
523
  rootDir: e
617
524
  });
618
525
  g.writeFileSync(
619
526
  o,
620
- `${f}
527
+ `${u}
621
528
 
622
529
  ${i}
623
530
  `,
624
531
  "utf-8"
625
- ), a.success(`${o} 添加 ${n}相关调用成功`);
532
+ ), l.success(`${o} 添加 ${n}相关调用成功`);
626
533
  }
627
- ae(o);
534
+ Mt(o);
628
535
  });
629
- }, ir = [
536
+ }, qe = [
630
537
  // HooksNameEnum.PRE_MERGE_COMMIT,
631
- _.PREPARE_COMMIT_MSG,
632
- _.COMMIT_MSG
633
- ], cr = ({
538
+ y.PREPARE_COMMIT_MSG,
539
+ y.COMMIT_MSG
540
+ ], Qe = ({
634
541
  hookName: t,
635
542
  rootDir: e
636
543
  }) => {
637
- const r = N(e), s = l.resolve(r, ".git");
544
+ const r = L(e), s = f.resolve(r, ".git");
638
545
  switch (t) {
639
- case _.PREPARE_COMMIT_MSG:
640
- case _.COMMIT_MSG: {
641
- const n = l.resolve(s, "MERGE_MSG");
642
- if (A(n))
643
- return v(n, "utf-8");
546
+ case y.PREPARE_COMMIT_MSG:
547
+ case y.COMMIT_MSG: {
548
+ const n = f.resolve(s, "MERGE_MSG");
549
+ if (M(n))
550
+ return N(n, "utf-8");
644
551
  }
645
552
  }
646
553
  return "";
647
- }, ar = ({
554
+ }, tr = ({
648
555
  remoteAlias: t = "origin"
649
556
  } = {}) => {
650
557
  try {
651
- const e = p("git rev-parse HEAD").toString().trim(), r = p(
652
- 'git log -1 --pretty=format:"%an"'
653
- ).toString().trim(), s = p(
654
- 'git log -1 --pretty=format:"%ae"'
655
- ).toString().trim(), n = p(
656
- 'git log -1 --pretty=format:"%s"'
657
- ).toString().trim(), o = p("git config user.name").toString().trim(), c = p("git config user.email").toString().trim(), i = p(
658
- "git rev-parse --abbrev-ref HEAD"
659
- ).toString().trim();
660
- let f = "";
558
+ const e = p("git rev-parse HEAD").toString().trim(), r = p('git log -1 --pretty=format:"%an"').toString().trim(), s = p('git log -1 --pretty=format:"%ae"').toString().trim(), n = p('git log -1 --pretty=format:"%s"').toString().trim(), o = p("git config user.name").toString().trim(), c = p("git config user.email").toString().trim(), i = p("git rev-parse --abbrev-ref HEAD").toString().trim();
559
+ let u = "";
661
560
  try {
662
- f = p(
663
- `git config --get remote.${t}.url`
664
- ).toString().trim();
561
+ u = p(`git config --get remote.${t}.url`).toString().trim();
665
562
  } catch {
666
- a.warn("git远程仓库地址获取失败或者不存在");
563
+ l.warn("git远程仓库地址获取失败或者不存在");
667
564
  }
668
565
  return {
669
566
  lastHash: e,
670
567
  lastCommitter: r,
671
- lastCommitterPinYin: R(r, {
672
- style: R.STYLE_NORMAL,
568
+ lastCommitterPinYin: P(r, {
569
+ style: P.STYLE_NORMAL,
673
570
  heteronym: !1
674
571
  }).join(""),
675
572
  lastCommitEmail: s,
676
573
  lastCommitMsg: n,
677
574
  userName: o,
678
- userNamePinYin: R(o, {
679
- style: R.STYLE_NORMAL,
575
+ userNamePinYin: P(o, {
576
+ style: P.STYLE_NORMAL,
680
577
  heteronym: !1
681
578
  }).join(""),
682
579
  userEmail: c,
683
580
  branchName: i,
684
- remoteInfo: f ? {
581
+ remoteInfo: u ? {
685
582
  alias: t,
686
- url: f
583
+ url: u
687
584
  } : void 0
688
585
  };
689
586
  } catch (e) {
690
- throw a.error("获取git最后提交信息失败"), e;
587
+ throw l.error("获取git最后提交信息失败"), e;
691
588
  }
692
- }, Et = (t = "") => {
589
+ }, ft = (t = "") => {
693
590
  const e = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+into\s+['|"](.+)['|"]\s*/i, r = t.match(e);
694
591
  if (r) {
695
- const [, i, f] = r;
592
+ const [, i, u] = r;
696
593
  return {
697
594
  fromBranch: i,
698
- toBranch: f
595
+ toBranch: u
699
596
  };
700
597
  }
701
598
  const s = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+of\s+.+\s+into\s+['|"](.+)['|"]\s*/i, n = t.match(s);
702
599
  if (n) {
703
- const [, i, f] = n;
600
+ const [, i, u] = n;
704
601
  return {
705
602
  fromBranch: i,
706
- toBranch: f
603
+ toBranch: u
707
604
  };
708
605
  }
709
606
  const o = /\s*Merge\s+branch\s+['|"](.+)['|"](\s+of)?\s*/i, c = t.match(o);
@@ -713,12 +610,12 @@ ${i}
713
610
  fromBranch: i
714
611
  };
715
612
  }
716
- }, de = (t) => {
717
- if (t.startsWith(b.MERGE))
613
+ }, ae = (t) => {
614
+ if (t.startsWith(F.MERGE))
718
615
  return {
719
- fromBranch: t.replace(b.MERGE, "").trim()
616
+ fromBranch: t.replace(F.MERGE, "").trim()
720
617
  };
721
- }, fr = () => {
618
+ }, er = () => {
722
619
  const t = process.env.GIT_REFLOG_ACTION || "";
723
620
  if (!t)
724
621
  return;
@@ -737,15 +634,15 @@ ${i}
737
634
  };
738
635
  }
739
636
  };
740
- var b = /* @__PURE__ */ ((t) => (t.CHECKOUT = "checkout", t.MERGE = "merge", t.COMMIT = "commit", t.COMMIT_MERGE = "commit (merge)", t.PULL = "pull", t.RESET = "reset", t.REBASE_START = "rebase (start)", t.REBASE_FINISH = "rebase (finish)", t.REBASE_ABORT = "rebase (abort)", t.REBASE_CONTINUE = "rebase (continue)", t))(b || {});
741
- const K = "__GIT_REPLACE_MARK__", $ = {
637
+ var F = /* @__PURE__ */ ((t) => (t.CHECKOUT = "checkout", t.MERGE = "merge", t.COMMIT = "commit", t.COMMIT_MERGE = "commit (merge)", t.PULL = "pull", t.RESET = "reset", t.REBASE_START = "rebase (start)", t.REBASE_FINISH = "rebase (finish)", t.REBASE_ABORT = "rebase (abort)", t.REBASE_CONTINUE = "rebase (continue)", t))(F || {});
638
+ const Y = "__GIT_REPLACE_MARK__", T = {
742
639
  stringify(t) {
743
- return JSON.stringify(t).replace(/"/g, K);
640
+ return JSON.stringify(t).replace(/"/g, Y);
744
641
  },
745
642
  parse(t) {
746
- return JSON.parse(t.replace(new RegExp(K, "g"), '"'));
643
+ return JSON.parse(t.replace(new RegExp(Y, "g"), '"'));
747
644
  }
748
- }, lr = ({
645
+ }, rr = ({
749
646
  count: t = 100
750
647
  } = {}) => {
751
648
  if (t <= 0)
@@ -768,18 +665,18 @@ const K = "__GIT_REPLACE_MARK__", $ = {
768
665
  commitTime: "%ci"
769
666
  };
770
667
  return p(
771
- `git --no-pager log --oneline -n ${t} --pretty=format:"${$.stringify(
668
+ `git --no-pager log --oneline -n ${t} --pretty=format:"${T.stringify(
772
669
  e
773
670
  )}"`
774
671
  ).toString().split(`
775
672
  `).map((o) => {
776
- const c = $.parse(o);
673
+ const c = T.parse(o);
777
674
  return {
778
675
  ...c,
779
- mergeInfo: Et(c.message)
676
+ mergeInfo: ft(c.message)
780
677
  };
781
678
  });
782
- }, ur = ({
679
+ }, sr = ({
783
680
  count: t = 100,
784
681
  filterItem: e = () => !0
785
682
  } = {}) => {
@@ -793,51 +690,51 @@ const K = "__GIT_REPLACE_MARK__", $ = {
793
690
  commitTime: "%ci"
794
691
  };
795
692
  return p(
796
- `git --no-pager reflog -n ${t} --pretty=format:"${$.stringify(
693
+ `git --no-pager reflog -n ${t} --pretty=format:"${T.stringify(
797
694
  r
798
695
  )}"`
799
696
  ).toString().split(`
800
- `).map((i) => $.parse(i)).filter(e).map((i) => {
801
- const { fullMessage: f, ...u } = i, S = ":", [y] = f.split(S, 1), L = f.slice(`${y}${S}`.length), h = y.trim(), O = L.trim();
802
- let D, H, _t;
803
- if (h.startsWith(
697
+ `).map((i) => T.parse(i)).filter(e).map((i) => {
698
+ const { fullMessage: u, ...a } = i, m = ":", [h] = u.split(m, 1), O = u.slice(`${h}${m}`.length), E = h.trim(), d = O.trim();
699
+ let S, R, _;
700
+ if (E.startsWith(
804
701
  "checkout"
805
702
  /* CHECKOUT */
806
703
  ))
807
- H = ce(O);
808
- else if (h.startsWith(
704
+ R = se(d);
705
+ else if (E.startsWith(
809
706
  "merge"
810
707
  /* MERGE */
811
708
  ))
812
- D = de(h);
813
- else if (h.startsWith(
709
+ S = ae(E);
710
+ else if (E.startsWith(
814
711
  "commit (merge)"
815
712
  /* COMMIT_MERGE */
816
713
  )) {
817
- const J = Et(O);
818
- J || a.warn(
819
- `${i.hash} 是合并提交 但是未从提交信息(${O})中检测到合并分支信息,推测手动更改了提交内容`
820
- ), D = J;
714
+ const I = ft(d);
715
+ I || l.warn(
716
+ `${i.hash} 是合并提交 但是未从提交信息(${d})中检测到合并分支信息,推测手动更改了提交内容`
717
+ ), S = I;
821
718
  }
822
719
  return {
823
- ...u,
824
- type: h,
825
- message: O,
826
- mergeInfo: D,
827
- checkoutInfo: H,
828
- rebaseInfo: _t
720
+ ...a,
721
+ type: E,
722
+ message: d,
723
+ mergeInfo: S,
724
+ checkoutInfo: R,
725
+ rebaseInfo: _
829
726
  };
830
727
  });
831
- }, gr = (t) => {
832
- const e = N(t), r = l.resolve(e, ".git"), s = l.resolve(r, "rebase-merge");
728
+ }, nr = (t) => {
729
+ const e = L(t), r = f.resolve(e, ".git"), s = f.resolve(r, "rebase-merge");
833
730
  if (g.existsSync(s))
834
731
  return !0;
835
- const n = l.resolve(r, "rebase-apply");
732
+ const n = f.resolve(r, "rebase-apply");
836
733
  if (g.existsSync(n))
837
734
  return !0;
838
- const o = l.resolve(r, "REBASE_HEAD");
735
+ const o = f.resolve(r, "REBASE_HEAD");
839
736
  return !!g.existsSync(o);
840
- }, pr = ({
737
+ }, or = ({
841
738
  branchName: t,
842
739
  version: e,
843
740
  remoteInfo: r
@@ -847,22 +744,22 @@ const K = "__GIT_REPLACE_MARK__", $ = {
847
744
  }), p(`git push ${r.alias} ${t}`, {
848
745
  stdio: "inherit"
849
746
  }));
850
- }, Ee = (t) => /^https?:\/\//.test(t), _e = (t) => /^git@/.test(t), mr = (t) => {
747
+ }, le = (t) => /^https?:\/\//.test(t), ue = (t) => /^git@/.test(t), ir = (t) => {
851
748
  const { hostname: e, pathname: r } = new URL(t);
852
749
  return `git@${e}:${r.replace("/", "")}`;
853
- }, Ce = (t) => l.resolve(t, ".git"), Sr = (t) => le(Ce(t)), ye = ({
750
+ }, fe = (t) => f.resolve(t, ".git"), cr = (t) => $t(fe(t)), ge = ({
854
751
  dir: t,
855
752
  fn: e,
856
753
  endClear: r = !0,
857
754
  exitClear: s = !0
858
755
  }) => {
859
- if (ht(t))
860
- return a.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
756
+ if (w(t))
757
+ return l.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
861
758
  const n = () => {
862
- a.stage("正在清理临时目录...", t), fe(t);
759
+ Lt(t);
863
760
  };
864
761
  s && process.once("exit", () => {
865
- a.stage("发现进程退出,正在清理临时目录...", t), n();
762
+ n();
866
763
  });
867
764
  let o;
868
765
  try {
@@ -871,19 +768,19 @@ const K = "__GIT_REPLACE_MARK__", $ = {
871
768
  throw r && n(), c;
872
769
  }
873
770
  return r && (o instanceof Promise ? o.finally(n) : n()), o;
874
- };
875
- var Oe = /* @__PURE__ */ ((t) => (t.ASSETS_CONFIG_REPO_URL = "ASSETS_CONFIG_REPO_URL", t))(Oe || {});
876
- const Re = (t) => l.resolve(
877
- z(),
878
- $t,
879
- `${t}-${et()}`
880
- ), ve = () => l.resolve(W(), Nt), Me = async () => {
881
- const t = ve(), e = {
771
+ }, pe = () => dt();
772
+ var me = /* @__PURE__ */ ((t) => (t.ASSETS_CONFIG_REPO_URL = "ASSETS_CONFIG_REPO_URL", t))(me || {});
773
+ const _e = (t) => f.resolve(
774
+ K(),
775
+ It,
776
+ `${t}-${pe()}`
777
+ ), Ee = () => f.resolve(V(), vt), de = async () => {
778
+ const t = Ee(), e = {
882
779
  ASSETS_CONFIG_REPO_URL: Tt
883
780
  };
884
781
  try {
885
- if (await k(t)) {
886
- const r = await dt(t, {});
782
+ if (await B(t)) {
783
+ const r = await Q(t, {});
887
784
  Object.entries(r).forEach(([s, n]) => {
888
785
  e[s] = n;
889
786
  });
@@ -891,36 +788,32 @@ const Re = (t) => l.resolve(
891
788
  } catch {
892
789
  }
893
790
  return e;
894
- }, Ie = async (t) => {
895
- if (await k(t))
896
- return a.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
791
+ }, he = async (t) => {
792
+ if (await B(t))
793
+ return l.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
897
794
  const {
898
795
  [
899
796
  "ASSETS_CONFIG_REPO_URL"
900
797
  /* ASSETS_CONFIG_REPO_URL */
901
798
  ]: e
902
- } = await Me();
903
- return _e(e) || Ee(e) ? p(
904
- `git clone ${e} ${t} --depth=1`
905
- ) : (g.mkdirSync(t, { recursive: !0 }), p(
906
- `cp -r ${e}/ ${t}/`
907
- )), {
799
+ } = await de();
800
+ return ue(e) || le(e) ? p(`git clone ${e} ${t} --depth=1`) : (g.mkdirSync(t, { recursive: !0 }), p(`cp -r ${e}/ ${t}/`)), {
908
801
  assetConfigRepoUrl: e
909
802
  };
910
- }, hr = async ({
803
+ }, ar = async ({
911
804
  moduleName: t,
912
805
  onSuccess: e
913
- }) => (a.stage(`拉取${t}配置,请稍等...`), ye({
806
+ }) => (l.stage(`拉取${t}配置,请稍等...`), ge({
914
807
  // 资源配置仓库临时文件夹
915
- dir: Re(t),
808
+ dir: _e(t),
916
809
  fn: async (r) => {
917
- const { assetConfigRepoUrl: s } = await Ie(r), n = l.join(
918
- At,
810
+ const { assetConfigRepoUrl: s } = await he(r), n = f.join(
811
+ Pt,
919
812
  t
920
- ), o = l.join(
813
+ ), o = f.join(
921
814
  n,
922
- Pt
923
- ), c = l.resolve(r, o), i = await dt(c);
815
+ Nt
816
+ ), c = f.resolve(r, o), i = await Q(c);
924
817
  return await e({
925
818
  repoUrl: s,
926
819
  config: i,
@@ -929,86 +822,130 @@ const Re = (t) => l.resolve(
929
822
  assetsConfigRepoTempDir: r
930
823
  }), i;
931
824
  }
932
- }));
825
+ })), Se = /[^a-zA-Z0-9._\-]/, Ce = /[^a-zA-Z0-9._\-]/g, lr = (t) => t ? !Se.test(t) : !1, ur = (t) => (t || "_").replace(Ce, "_"), fr = (t) => Object.entries(t).map(([e, r]) => `--${e}=${r}`), gr = ({
826
+ command: t,
827
+ args: e,
828
+ env: r,
829
+ cwd: s,
830
+ beforeInputExit: n
831
+ }) => new Promise((o, c) => {
832
+ var S, R;
833
+ let i = !1;
834
+ const u = {
835
+ beforeInputExit: n
836
+ }, a = Ot(t, e, {
837
+ cwd: s,
838
+ stdio: ["pipe", "pipe", "pipe", "ipc"],
839
+ env: {
840
+ ...r,
841
+ [Z]: JSON.stringify(
842
+ u
843
+ )
844
+ }
845
+ }), m = () => {
846
+ i = !0, a.removeAllListeners();
847
+ }, h = (_) => {
848
+ i || (m(), c(_));
849
+ }, O = (_) => {
850
+ if (l.debug("劫持子进程消息:", _, i), !i)
851
+ switch (_.type) {
852
+ }
853
+ };
854
+ a.once("error", h), a.on("message", O);
855
+ let E = "", d = "";
856
+ (S = a.stdout) == null || S.on("data", (_) => {
857
+ E += _;
858
+ }), (R = a.stderr) == null || R.on("data", (_) => {
859
+ d += _;
860
+ }), a.once("exit", (_, I) => {
861
+ if (i)
862
+ return;
863
+ m();
864
+ const j = _ === 0;
865
+ j ? o({
866
+ success: j,
867
+ code: _ ?? null,
868
+ signal: I ?? null,
869
+ stdout: E,
870
+ stderr: d
871
+ }) : c(new Error(`进程退出,退出码: ${_}`));
872
+ });
873
+ });
933
874
  export {
934
- Oe as DoneCodingCliGlobalConfigKeyEnum,
935
- Qt as EditorTypeEnum,
936
- Ft as EnvConfigCallModeEnum,
937
- Bt as EnvConfigProcessKeyEnum,
938
- b as GitRefLogTypeEnum,
939
- _ as HooksNameEnum,
940
- m as LogTypeEnum,
941
- ir as SUPPORT_GET_COMMIT_BY_HOOKS_NAMES,
875
+ me as DoneCodingCliGlobalConfigKeyEnum,
876
+ Xt as EditorTypeEnum,
877
+ Ft as EnvConfigProcessKeyEnum,
878
+ F as GitRefLogTypeEnum,
879
+ y as HooksNameEnum,
880
+ qe as SUPPORT_GET_COMMIT_BY_HOOKS_NAMES,
942
881
  Ir as _curry,
943
- Or as _get,
944
- vr as _set,
945
- or as addHuskyHooks,
946
- rr as addPackageConfig,
947
- at as allowConsoleLog,
948
- ye as applyUseTempDir,
949
- ht as assetIsExits,
950
- k as assetIsExitsAsync,
951
- gr as checkCurrentIsRebasing,
952
- Xe as createMainCommand,
953
- Ze as createSubcommand,
954
- Ve as decryptAES,
955
- Ye as encryptAES,
956
- p as execSyncWithLogDispatch,
957
- ae as fileAddX,
958
- d as formatLogSteamWrite,
959
- We as getAnswerSwift,
960
- Ke as getAnswerWithMCP,
961
- ct as getCallMode,
962
- Re as getCliModuleTempDir,
963
- cr as getCommitByHookName,
964
- qe as getConfigFileCommonOptions,
965
- lr as getCurrentBranchLastCommitList,
966
- sr as getCurrentBranchName,
967
- Ht as getCurrentProcessLogFileName,
968
- te as getEditorType,
969
- ar as getGitLastCommitInfo,
970
- Ce as getGitPath,
971
- N as getGitProjectDir,
972
- ur as getLastReflogList,
973
- kt as getLogOutputDir,
974
- He as getLogText,
975
- tt as getLogTime,
976
- Vt as getLogTypeByValue,
977
- x as getPackageJson,
978
- Jt as getParentProcessLogFileName,
979
- st as getProcessEnv,
980
- ft as getProcessLogStream,
981
- ie as getRelyPkgVersion,
982
- ne as getRootDirOptions,
983
- ze as getRootScriptName,
984
- bt as getSafePath,
985
- er as getUseDefaultConfig,
986
- mr as http2sshGitUrl,
987
- oe as initConfigFile,
988
- ke as initEnvConfig,
989
- Qe as initHandlerCommon,
990
- Ee as isHttpGitUrl,
991
- xt as isMcpMode,
992
- _e as isSshGitUrl,
993
- Cr as json5,
994
- a as log,
995
- Je as lookForParentTarget,
996
- se as openFileInEditor,
997
- xe as pathIsSafe,
998
- pr as pushGitPublishInfoToRemote,
999
- hr as readCliModuleAssetsConfig,
1000
- tr as readConfigFile,
1001
- ue as readFile,
1002
- ge as readFileAsync,
1003
- nr as readJsonFile,
1004
- dt as readJsonFileAsync,
1005
- fe as removeAsset,
1006
- le as removeAssetAsync,
1007
- ce as resolveCheckoutInfoByRefInfo,
1008
- Et as resolveMergeInfoByCommitMsg,
1009
- fr as resolveMergeInfoByGitReflogAction,
1010
- de as resolveMergeInfoByRefType,
1011
- Sr as rmGitCtrlAsync,
1012
- et as uuidv4,
1013
- P as xPrompts
882
+ Cr as _get,
883
+ Rr as _set,
884
+ Ze as addHuskyHooks,
885
+ Xe as addPackageConfig,
886
+ ge as applyUseTempDir,
887
+ w as assetIsExits,
888
+ B as assetIsExitsAsync,
889
+ Nr as chalk,
890
+ nr as checkCurrentIsRebasing,
891
+ xe as createMainCommand,
892
+ Je as createSubcommand,
893
+ _r as dayjs,
894
+ He as decryptAES,
895
+ Ue as encryptAES,
896
+ Mt as fileAddX,
897
+ je as generateGetAnswerSwiftFn,
898
+ Vt as getAnswer,
899
+ _e as getCliModuleTempDir,
900
+ Qe as getCommitByHookName,
901
+ Ye as getConfigFileCommonOptions,
902
+ rr as getCurrentBranchLastCommitList,
903
+ ze as getCurrentBranchName,
904
+ st as getCurrentProcessLogFileName,
905
+ zt as getEditorType,
906
+ tr as getGitLastCommitInfo,
907
+ fe as getGitPath,
908
+ L as getGitProjectDir,
909
+ sr as getLastReflogList,
910
+ Ht as getLogOutputDir,
911
+ H as getPackageJson,
912
+ jt as getParentProcessLogFileName,
913
+ we as getProcessCreateByHijackPresetInfo,
914
+ et as getProcessEnv,
915
+ re as getRelyPkgVersion,
916
+ te as getRootDirOptions,
917
+ ke as getRootScriptName,
918
+ ur as getSafePath,
919
+ We as getUseDefaultConfig,
920
+ gr as hijackChildProcess,
921
+ ir as http2sshGitUrl,
922
+ ee as initConfigFile,
923
+ Ve as initHandlerCommon,
924
+ le as isHttpGitUrl,
925
+ ue as isSshGitUrl,
926
+ hr as json5,
927
+ kt as logger,
928
+ Be as lookForParentTarget,
929
+ Qt as openFileInEditor,
930
+ l as outputConsole,
931
+ fr as params2cliParams,
932
+ lr as pathIsSafe,
933
+ x as processIsHijacked,
934
+ or as pushGitPublishInfoToRemote,
935
+ ar as readCliModuleAssetsConfig,
936
+ Ke as readConfigFile,
937
+ Dt as readFile,
938
+ Gt as readFileAsync,
939
+ Fe as readJsonFile,
940
+ Q as readJsonFileAsync,
941
+ Lt as removeAsset,
942
+ $t as removeAssetAsync,
943
+ se as resolveCheckoutInfoByRefInfo,
944
+ ft as resolveMergeInfoByCommitMsg,
945
+ er as resolveMergeInfoByGitReflogAction,
946
+ ae as resolveMergeInfoByRefType,
947
+ cr as rmGitCtrlAsync,
948
+ be as updateEnvConfig,
949
+ pe as uuidv4,
950
+ U as xPrompts
1014
951
  };