@done-coding/cli-utils 0.8.2-alpha.2 → 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 +488 -558
  2. package/package.json +11 -10
  3. package/types/index.d.ts +79 -131
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";
2
+ import { homedir as V, tmpdir as K } from "node:os";
4
3
  import f from "node:path";
5
- import g, { existsSync as I, mkdirSync as yt, writeFileSync as T, 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";
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 yr } from "json5";
15
- import Mt from "lodash.merge";
16
- import At from "semver";
17
- import { default as Rr } from "lodash.get";
18
- import { default as Mr } from "lodash.set";
19
- import { default as $r } from "lodash.curry";
20
- import R from "pinyin";
21
- const q = "__DONE_CODING_ENV_CONFIG__", Q = Symbol.for(
22
- q
23
- ), b = ".done-coding", $t = `${b}/cli/assets-config`, It = "assets", Pt = "index.json", Nt = `${b}/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, ke = (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)];
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";
20
+ import { default as Ir } from "lodash.curry";
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,179 +53,106 @@ 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
- }, F = () => globalThis[Q], B = (t) => {
44
- const e = F();
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: `${b}/${e}/${Lt}`,
66
- processLogFileNameList: []
67
- };
68
- }, U = `${tt()}-${et()}`, it = (t) => {
69
- const e = {
70
- ...t,
71
- processLogFileNameList: [
72
- U,
73
- ...t.processLogFileNameList
74
- ].slice(0, 10)
75
- };
76
- return B(e);
77
- }, C = () => {
78
- const t = F();
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: [U]
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 B(s);
90
- }
91
- }, He = ({
92
- series: t,
93
- ...e
94
- }) => {
95
- if (jt)
96
- throw new Error("非顶级进程不允许调用该方法");
97
- if (F())
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: [U]
114
- };
115
- return B(o);
116
- }
117
- }
118
- }, ct = () => C().callMode, xt = () => ct() === "MCP", at = () => xt() ? !1 : C().consoleLog, kt = (t = !1) => f.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 = f.resolve(t), r = f.dirname(e), s = E.get(e);
128
- if (s) {
129
- if (!s.destroyed && s.writable)
130
- return s;
131
- E.delete(e);
132
90
  }
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 h = ({
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 lt = () => {
168
- const t = kt(), e = f.resolve(t, Ht()), r = Kt(e);
169
- if (!V) {
170
- const s = Jt();
171
- s && h({
172
- stream: r,
173
- type: m.SYSTEM,
174
- content: `父进程日志文件: ${s}`
175
- });
176
- const n = ct();
177
- h({
178
- stream: r,
179
- type: m.SYSTEM,
180
- content: `当前调用模式: ${n}`
181
- }), V = !0;
182
- }
183
- return r;
184
- }, Wt = (t, e) => {
185
- const r = lt(), s = t.map((n) => n instanceof Error ? n.stack || n.message : typeof n == "object" && n !== null ? JSON.stringify(n) : String(n)).join(" ");
186
- h({
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), ft = (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 = ft(zt), Je = ft(
209
- (t, ...e) => t === m.TABLE ? JSON.stringify(e) : X[t](...e)
210
- ), Ye = (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
  /** 优先找最远的父目录 */
@@ -219,9 +164,9 @@ const lt = () => {
219
164
  if (g.existsSync(o))
220
165
  return n;
221
166
  }
222
- }, ut = "aes-256-cbc", gt = 16, A = "hex", G = ":";
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,73 +177,100 @@ function pt(t) {
232
177
  "sha256"
233
178
  );
234
179
  }
235
- function Ve({
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
192
  const c = s.toString(A), i = o.toString(A);
244
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 Ke({
200
+ function He({
252
201
  encryptedText: t,
253
202
  secretKey: e
254
203
  }) {
255
204
  try {
256
205
  if (!t.includes(G))
257
206
  return "";
258
- const r = pt(e), [s, n] = t.split(G);
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, A), c = Buffer.from(n, A), i = M.createDecipheriv(ut, r, o);
262
- let l = i.update(c);
263
- return l = Buffer.concat([l, i.final()]), l.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 j = (...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
- }, Xt = 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
- const o = r == null ? void 0 : r[e];
286
- return o !== void 0 ? o : t ? (a.error("MCP场景的预设值不能为空"), process.exit(1)) : s ?? (n !== void 0 ? (await j(n))[e] : void 0);
287
- }, We = ({
288
- isMCP: t,
289
- presetAnswer: e
290
- }) => async (r, s, n) => Xt({
291
- key: r,
292
- questionConfig: s,
293
- defaultValue: n,
294
- isMCP: t,
295
- presetAnswer: e
296
- }), Zt = (t, e) => {
297
- t ? a.error(t) : a.error(e.message), e != null && e.stack && a.error(e.stack), process.exit(1);
298
- }, qt = () => {
299
- const t = vt(process.argv);
300
- return Rt(t);
301
- }, 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 = ({
302
274
  rootScriptName: t,
303
275
  packageJson: e
304
276
  }) => {
@@ -311,14 +283,14 @@ const j = (...t) => {
311
283
  if (typeof r == "string")
312
284
  return s.includes("/") ? void 0 : s;
313
285
  if (typeof r == "object") {
314
- const n = Object.entries(r), o = process.argv[1], c = n.filter(([, l]) => o == null ? void 0 : o.endsWith(l));
286
+ const n = Object.entries(r), o = process.argv[1], c = n.filter(([, u]) => o == null ? void 0 : o.endsWith(u));
315
287
  if (c.length !== 1)
316
288
  return;
317
289
  const [i] = c[0];
318
290
  return process.platform === "win32" ? i.toLowerCase() : i;
319
291
  }
320
292
  }
321
- }, mt = (t, {
293
+ }, lt = (t, {
322
294
  usage: e,
323
295
  version: r,
324
296
  demandCommandCount: s,
@@ -326,89 +298,31 @@ const j = (...t) => {
326
298
  positionals: o,
327
299
  subcommands: c,
328
300
  rootScriptName: i
329
- }, l) => {
330
- let u = t.strict();
331
- e && (u = u.usage(`Usage: ${e}`)), s && (u = u.demandCommand(s));
332
- const S = "help";
333
- 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, [N, d]) => y.positional(N, d), u)), c && (u = u.command(c)), l && i && (u = u.scriptName(i)), u;
334
- }, Xe = async ({ handler: t, ...e }) => {
335
- const r = await mt(qt(), e, !0).fail(
336
- Zt
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
337
309
  ).argv;
338
310
  return t ? t(r) : r;
339
- }, Ze = (t) => {
311
+ }, Je = (t) => {
340
312
  const { command: e, describe: r, handler: s = () => {
341
313
  }, ...n } = t;
342
314
  return {
343
315
  command: e,
344
316
  describe: r,
345
317
  builder(o) {
346
- return mt(o, n, !1);
318
+ return lt(o, n, !1);
347
319
  },
348
320
  handler: s
349
321
  };
350
- }, Qt = (t) => {
351
- if (!t)
352
- return ["pipe", "pipe", "pipe"];
353
- if (typeof t == "string")
354
- switch (t) {
355
- case "ignore":
356
- return ["ignore", "ignore", "ignore"];
357
- case "inherit":
358
- return ["inherit", "inherit", "inherit"];
359
- case "overlapped":
360
- return ["overlapped", "overlapped", "overlapped"];
361
- default:
362
- return ["pipe", "pipe", "pipe"];
363
- }
364
- if (Array.isArray(t)) {
365
- const e = [...t];
366
- for (let r = 0; r < 3; r++)
367
- e[r] === void 0 && (e[r] = "pipe");
368
- return e;
369
- }
370
- return ["pipe", "pipe", "pipe"];
371
- }, p = (t, e) => {
372
- if (at() || (e == null ? void 0 : e.stdio) === "ignore")
373
- return Y(t, e);
374
- const s = lt(), n = s.fd, o = Qt(e == null ? void 0 : e.stdio), c = o.map((i, l) => l === 0 ? "ignore" : (l === 1 || l === 2) && (i === "inherit" || i === "overlapped") ? n : i);
375
- try {
376
- h({
377
- stream: s,
378
- type: m.SYSTEM,
379
- content: `[子进程任务开始执行] ${t}`
380
- });
381
- const i = Y(t, {
382
- maxBuffer: 1024 * 1024 * 100,
383
- // 增加到 100MB,防止 pipe 模式下大数据溢出
384
- ...e,
385
- stdio: c,
386
- encoding: (e == null ? void 0 : e.encoding) || "utf-8"
387
- });
388
- return i && o[1] === "pipe" ? h({
389
- stream: s,
390
- type: m.SYSTEM,
391
- content: `[任务执行成功返回]: ${i.toString().trim()}`
392
- }) : h({
393
- stream: s,
394
- type: m.SYSTEM,
395
- content: "[任务执行成功]"
396
- }), i;
397
- } catch (i) {
398
- const l = i.stderr ? `
399
- STDERR: ${i.stderr}` : "";
400
- throw h({
401
- stream: s,
402
- type: m.ERROR,
403
- content: `[任务执行失败]: ${t}
404
- STATUS: ${i.status}
405
- MSG: ${i.message}${l}`
406
- }), i;
407
- }
408
322
  };
409
- var te = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(te || {});
410
- const ee = async () => {
411
- const { editorType: t } = await j([
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([
412
326
  {
413
327
  name: "editorType",
414
328
  type: "select",
@@ -425,24 +339,24 @@ const ee = async () => {
425
339
  }
426
340
  ]);
427
341
  return t;
428
- }, re = {
342
+ }, Zt = {
429
343
  Cursor: "cursor",
430
344
  VsCode: "code"
431
- }, se = (t, e, r) => {
345
+ }, qt = (t, e, r) => {
432
346
  try {
433
347
  p(`${t} -v`, { stdio: "ignore" }), p(`${t} ${e}`);
434
348
  } catch {
435
349
  r();
436
350
  }
437
- }, ne = (t, e) => {
438
- const r = (s) => a.info(`
351
+ }, Qt = (t, e) => {
352
+ const r = (s) => l.info(`
439
353
  ${s}, 请用编辑器打开 ${t} 进行编辑
440
354
  `);
441
355
  switch (e) {
442
356
  case "Cursor":
443
357
  case "VsCode": {
444
- const s = re[e];
445
- se(s, t, () => {
358
+ const s = Zt[e];
359
+ qt(s, t, () => {
446
360
  r(`${s}命令未安装`);
447
361
  });
448
362
  break;
@@ -450,7 +364,7 @@ const ee = async () => {
450
364
  default:
451
365
  r("其他编辑器");
452
366
  }
453
- }, oe = (t = process.cwd()) => ({
367
+ }, te = (t = process.cwd()) => ({
454
368
  /** 必须保留 */
455
369
  rootDir: {
456
370
  type: "string",
@@ -459,12 +373,12 @@ const ee = async () => {
459
373
  /** 必须设置默认值 */
460
374
  default: t
461
375
  }
462
- }), qe = ({
376
+ }), Ye = ({
463
377
  configPathDefault: t,
464
378
  rootDirDefault: e
465
379
  }) => ({
466
380
  /** 必须保留 */
467
- ...oe(e),
381
+ ...te(e),
468
382
  /** 必须保留 */
469
383
  configPath: {
470
384
  type: "string",
@@ -473,77 +387,77 @@ const ee = async () => {
473
387
  /** 必须设置默认值 */
474
388
  default: t
475
389
  }
476
- }), ie = async (t, e) => {
390
+ }), ee = async (t, e) => {
477
391
  const { configPath: r, rootDir: s } = e, n = f.resolve(s, r), o = f.dirname(n);
478
- return I(o) || yt(o, {
392
+ return M(o) || _t(o, {
479
393
  recursive: !0
480
- }), n.endsWith(".json5") ? (a.info(`json5模式写入 ${n}`), T(n, Z.stringify(t, null, 2)), n) : (a.info(`json模式写入 ${n}`), T(n, JSON.stringify(t, null, 2)), n);
481
- }, 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, {
482
396
  onFileGenerated: r,
483
397
  edit: s = !1
484
398
  } = {}) => {
485
- const n = await ie(t, e);
399
+ const n = await ee(t, e);
486
400
  if (r == null || r(n), s) {
487
- const o = await ee();
488
- ne(e.configPath, o);
401
+ const o = await zt();
402
+ Qt(e.configPath, o);
489
403
  }
490
- }, tr = async (t, e) => {
404
+ }, Ke = async (t, e) => {
491
405
  const { configPath: r, rootDir: s } = t, n = f.resolve(s, r);
492
- if (!I(n)) {
406
+ if (!M(n)) {
493
407
  if (e)
494
- return a.info("配置文件不存在,使用onNotExists返回值"), e();
408
+ return l.info("配置文件不存在,使用onNotExists返回值"), e();
495
409
  const o = `配置文件不存在 ${n}`;
496
410
  throw new Error(o);
497
411
  }
498
- return n.endsWith(".json5") ? (a.info(`json5模式解析 ${n}`), Z.parse(v(n, "utf8"))) : (a.info(`json模式解析 ${n}`), JSON.parse(v(n, "utf8")));
499
- }, er = async () => {
500
- const { useDefaultConfig: t } = await j({
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({
501
415
  name: "useDefaultConfig",
502
416
  type: "confirm",
503
417
  message: "使用默认模板配置",
504
418
  initial: !0
505
419
  });
506
420
  return t;
507
- }, St = "package.json", x = ({
421
+ }, ut = "package.json", H = ({
508
422
  rootDir: t
509
423
  }) => {
510
- const e = f.resolve(t, St);
511
- if (!I(e))
424
+ const e = f.resolve(t, ut);
425
+ if (!M(e))
512
426
  throw new Error(`${t}未找到package.json文件`);
513
- const r = v(e, "utf-8");
427
+ const r = N(e, "utf-8");
514
428
  return JSON.parse(r);
515
- }, ce = ({
429
+ }, re = ({
516
430
  rootDir: t,
517
431
  pkgJson: e,
518
432
  pkgName: r,
519
433
  isDevPkg: s
520
434
  }) => {
521
- 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;
522
436
  let c = o == null ? void 0 : o[r];
523
437
  if (!c) {
524
438
  const i = s ? n.dependencies : n.devDependencies;
525
- c = i == null ? void 0 : i[r], c && a.warn(
439
+ c = i == null ? void 0 : i[r], c && l.warn(
526
440
  `${s ? "开发" : "生产"}依赖包${r}可能错误的安装在${s ? "dependencies" : "devDependencies"}`
527
441
  );
528
442
  return;
529
443
  }
530
- return c || a.info(`依赖包${r}未安装`), c;
531
- }, rr = ({
444
+ return c || l.info(`依赖包${r}未安装`), c;
445
+ }, Xe = ({
532
446
  patchConfig: t,
533
447
  rootDir: e
534
448
  }) => {
535
449
  if (!t)
536
450
  return;
537
- const r = x({ rootDir: e }), s = Mt(r, t), n = f.resolve(e, St);
538
- T(n, JSON.stringify(s, null, 2), "utf-8");
539
- }, P = (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) => {
540
454
  const r = p("git rev-parse --show-toplevel", {
541
455
  cwd: t
542
456
  }).toString();
543
457
  if (!r)
544
458
  throw new Error("获取git根目录失败");
545
459
  return r.trim();
546
- }, sr = () => {
460
+ }, ze = () => {
547
461
  var t;
548
462
  try {
549
463
  const e = p("git symbolic-ref --short HEAD", {
@@ -553,12 +467,14 @@ const ee = async () => {
553
467
  } catch {
554
468
  try {
555
469
  const r = p("git rev-parse --short HEAD").toString().trim();
556
- a.skip(`当前未指向具体某个分支, 当前commit hash: ${r}`);
470
+ l.skip(
471
+ `当前未指向具体某个分支, 当前commit hash: ${r}`
472
+ );
557
473
  } finally {
558
474
  return;
559
475
  }
560
476
  }
561
- }, ae = (t) => {
477
+ }, se = (t) => {
562
478
  const e = t.match(/moving\s+from\s+(.*)\s+to\s+(.*)/);
563
479
  if (e) {
564
480
  const [, r, s] = e;
@@ -567,149 +483,124 @@ const ee = async () => {
567
483
  toBranch: s.trim()
568
484
  };
569
485
  }
570
- }, D = 73, le = (t) => {
571
- const r = g.statSync(t).mode;
572
- if ((r & D) === D)
573
- return;
574
- a.stage(`${t} 没有执行权限 添加... `);
575
- const s = r | D;
576
- g.chmodSync(t, s), a.success(`${t} 添加执行权限成功`);
577
- }, dt = (t) => g.existsSync(t), k = async (t) => {
578
- try {
579
- return await g.promises.lstat(t), !0;
580
- } catch (e) {
581
- return e.code !== "ENOENT";
582
- }
583
- }, fe = (t, e = !1) => {
584
- dt(t) && g.rmSync(t, { recursive: !0, force: e });
585
- }, ue = async (t, e = !1) => {
586
- await k(t) && await g.promises.rm(t, { recursive: !0, force: e });
587
- }, ge = (t) => g.readFileSync(t, "utf-8"), pe = (t) => g.promises.readFile(t, "utf-8"), nr = (t, e) => JSON.parse(ge(t)) || e, ht = async (t, e) => JSON.parse(await pe(t)) || e;
588
- 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))(_ || {});
589
- const me = "husky", Se = ".husky", de = ({ rootDir: t }) => {
590
- const e = P(t), r = ce({
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({
591
490
  rootDir: e,
592
- pkgJson: x({ rootDir: e }),
593
- pkgName: me,
491
+ pkgJson: H({ rootDir: e }),
492
+ pkgName: ne,
594
493
  isDevPkg: !0
595
494
  });
596
495
  if (!r)
597
496
  throw new Error("husky版本获取失败, 可能husky未安装");
598
497
  const s = r.replace(/^(\^|~)/, ""), n = "<9.0.0";
599
- return At.satisfies(s, n) ? (a.info(`${s}符合${n}`), `#!/usr/bin/env sh
600
- . "$(dirname -- "$0")/_/husky.sh"`) : (a.info(`${s}不符合${n}`), "");
601
- }, he = ({ rootDir: t }) => {
602
- const e = P(t);
603
- return f.resolve(e, Se);
604
- }, 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 = ({
605
504
  hookNames: t,
606
505
  rootDir: e,
607
506
  getCode: r
608
507
  }) => {
609
- const s = he({ rootDir: e });
508
+ const s = ce({ rootDir: e });
610
509
  g.existsSync(s) || g.mkdirSync(s, { recursive: !0 }), t.forEach((n) => {
611
510
  const o = f.resolve(s, n), c = g.existsSync(o);
612
511
  let i = r(n);
613
512
  if (c)
614
- 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(
615
516
  o,
616
517
  `
617
518
  ${i}
618
519
  `
619
- ), a.success(`${o} 添加 ${n}相关调用成功`));
520
+ ), l.success(`${o} 添加 ${n}相关调用成功`));
620
521
  else {
621
- const l = de({
522
+ const u = ie({
622
523
  rootDir: e
623
524
  });
624
525
  g.writeFileSync(
625
526
  o,
626
- `${l}
527
+ `${u}
627
528
 
628
529
  ${i}
629
530
  `,
630
531
  "utf-8"
631
- ), a.success(`${o} 添加 ${n}相关调用成功`);
532
+ ), l.success(`${o} 添加 ${n}相关调用成功`);
632
533
  }
633
- le(o);
534
+ Mt(o);
634
535
  });
635
- }, ir = [
536
+ }, qe = [
636
537
  // HooksNameEnum.PRE_MERGE_COMMIT,
637
- _.PREPARE_COMMIT_MSG,
638
- _.COMMIT_MSG
639
- ], cr = ({
538
+ y.PREPARE_COMMIT_MSG,
539
+ y.COMMIT_MSG
540
+ ], Qe = ({
640
541
  hookName: t,
641
542
  rootDir: e
642
543
  }) => {
643
- const r = P(e), s = f.resolve(r, ".git");
544
+ const r = L(e), s = f.resolve(r, ".git");
644
545
  switch (t) {
645
- case _.PREPARE_COMMIT_MSG:
646
- case _.COMMIT_MSG: {
546
+ case y.PREPARE_COMMIT_MSG:
547
+ case y.COMMIT_MSG: {
647
548
  const n = f.resolve(s, "MERGE_MSG");
648
- if (I(n))
649
- return v(n, "utf-8");
549
+ if (M(n))
550
+ return N(n, "utf-8");
650
551
  }
651
552
  }
652
553
  return "";
653
- }, ar = ({
554
+ }, tr = ({
654
555
  remoteAlias: t = "origin"
655
556
  } = {}) => {
656
557
  try {
657
- const e = p("git rev-parse HEAD").toString().trim(), r = p(
658
- 'git log -1 --pretty=format:"%an"'
659
- ).toString().trim(), s = p(
660
- 'git log -1 --pretty=format:"%ae"'
661
- ).toString().trim(), n = p(
662
- 'git log -1 --pretty=format:"%s"'
663
- ).toString().trim(), o = p("git config user.name").toString().trim(), c = p("git config user.email").toString().trim(), i = p(
664
- "git rev-parse --abbrev-ref HEAD"
665
- ).toString().trim();
666
- let l = "";
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 = "";
667
560
  try {
668
- l = p(
669
- `git config --get remote.${t}.url`
670
- ).toString().trim();
561
+ u = p(`git config --get remote.${t}.url`).toString().trim();
671
562
  } catch {
672
- a.warn("git远程仓库地址获取失败或者不存在");
563
+ l.warn("git远程仓库地址获取失败或者不存在");
673
564
  }
674
565
  return {
675
566
  lastHash: e,
676
567
  lastCommitter: r,
677
- lastCommitterPinYin: R(r, {
678
- style: R.STYLE_NORMAL,
568
+ lastCommitterPinYin: P(r, {
569
+ style: P.STYLE_NORMAL,
679
570
  heteronym: !1
680
571
  }).join(""),
681
572
  lastCommitEmail: s,
682
573
  lastCommitMsg: n,
683
574
  userName: o,
684
- userNamePinYin: R(o, {
685
- style: R.STYLE_NORMAL,
575
+ userNamePinYin: P(o, {
576
+ style: P.STYLE_NORMAL,
686
577
  heteronym: !1
687
578
  }).join(""),
688
579
  userEmail: c,
689
580
  branchName: i,
690
- remoteInfo: l ? {
581
+ remoteInfo: u ? {
691
582
  alias: t,
692
- url: l
583
+ url: u
693
584
  } : void 0
694
585
  };
695
586
  } catch (e) {
696
- throw a.error("获取git最后提交信息失败"), e;
587
+ throw l.error("获取git最后提交信息失败"), e;
697
588
  }
698
- }, Et = (t = "") => {
589
+ }, ft = (t = "") => {
699
590
  const e = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+into\s+['|"](.+)['|"]\s*/i, r = t.match(e);
700
591
  if (r) {
701
- const [, i, l] = r;
592
+ const [, i, u] = r;
702
593
  return {
703
594
  fromBranch: i,
704
- toBranch: l
595
+ toBranch: u
705
596
  };
706
597
  }
707
598
  const s = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+of\s+.+\s+into\s+['|"](.+)['|"]\s*/i, n = t.match(s);
708
599
  if (n) {
709
- const [, i, l] = n;
600
+ const [, i, u] = n;
710
601
  return {
711
602
  fromBranch: i,
712
- toBranch: l
603
+ toBranch: u
713
604
  };
714
605
  }
715
606
  const o = /\s*Merge\s+branch\s+['|"](.+)['|"](\s+of)?\s*/i, c = t.match(o);
@@ -719,12 +610,12 @@ ${i}
719
610
  fromBranch: i
720
611
  };
721
612
  }
722
- }, Ee = (t) => {
723
- if (t.startsWith(w.MERGE))
613
+ }, ae = (t) => {
614
+ if (t.startsWith(F.MERGE))
724
615
  return {
725
- fromBranch: t.replace(w.MERGE, "").trim()
616
+ fromBranch: t.replace(F.MERGE, "").trim()
726
617
  };
727
- }, lr = () => {
618
+ }, er = () => {
728
619
  const t = process.env.GIT_REFLOG_ACTION || "";
729
620
  if (!t)
730
621
  return;
@@ -743,15 +634,15 @@ ${i}
743
634
  };
744
635
  }
745
636
  };
746
- var w = /* @__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))(w || {});
747
- 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 = {
748
639
  stringify(t) {
749
- return JSON.stringify(t).replace(/"/g, K);
640
+ return JSON.stringify(t).replace(/"/g, Y);
750
641
  },
751
642
  parse(t) {
752
- return JSON.parse(t.replace(new RegExp(K, "g"), '"'));
643
+ return JSON.parse(t.replace(new RegExp(Y, "g"), '"'));
753
644
  }
754
- }, fr = ({
645
+ }, rr = ({
755
646
  count: t = 100
756
647
  } = {}) => {
757
648
  if (t <= 0)
@@ -774,18 +665,18 @@ const K = "__GIT_REPLACE_MARK__", $ = {
774
665
  commitTime: "%ci"
775
666
  };
776
667
  return p(
777
- `git --no-pager log --oneline -n ${t} --pretty=format:"${$.stringify(
668
+ `git --no-pager log --oneline -n ${t} --pretty=format:"${T.stringify(
778
669
  e
779
670
  )}"`
780
671
  ).toString().split(`
781
672
  `).map((o) => {
782
- const c = $.parse(o);
673
+ const c = T.parse(o);
783
674
  return {
784
675
  ...c,
785
- mergeInfo: Et(c.message)
676
+ mergeInfo: ft(c.message)
786
677
  };
787
678
  });
788
- }, ur = ({
679
+ }, sr = ({
789
680
  count: t = 100,
790
681
  filterItem: e = () => !0
791
682
  } = {}) => {
@@ -799,43 +690,43 @@ const K = "__GIT_REPLACE_MARK__", $ = {
799
690
  commitTime: "%ci"
800
691
  };
801
692
  return p(
802
- `git --no-pager reflog -n ${t} --pretty=format:"${$.stringify(
693
+ `git --no-pager reflog -n ${t} --pretty=format:"${T.stringify(
803
694
  r
804
695
  )}"`
805
696
  ).toString().split(`
806
- `).map((i) => $.parse(i)).filter(e).map((i) => {
807
- const { fullMessage: l, ...u } = i, S = ":", [y] = l.split(S, 1), N = l.slice(`${y}${S}`.length), d = y.trim(), O = N.trim();
808
- let L, H, _t;
809
- if (d.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(
810
701
  "checkout"
811
702
  /* CHECKOUT */
812
703
  ))
813
- H = ae(O);
814
- else if (d.startsWith(
704
+ R = se(d);
705
+ else if (E.startsWith(
815
706
  "merge"
816
707
  /* MERGE */
817
708
  ))
818
- L = Ee(d);
819
- else if (d.startsWith(
709
+ S = ae(E);
710
+ else if (E.startsWith(
820
711
  "commit (merge)"
821
712
  /* COMMIT_MERGE */
822
713
  )) {
823
- const J = Et(O);
824
- J || a.warn(
825
- `${i.hash} 是合并提交 但是未从提交信息(${O})中检测到合并分支信息,推测手动更改了提交内容`
826
- ), L = J;
714
+ const I = ft(d);
715
+ I || l.warn(
716
+ `${i.hash} 是合并提交 但是未从提交信息(${d})中检测到合并分支信息,推测手动更改了提交内容`
717
+ ), S = I;
827
718
  }
828
719
  return {
829
- ...u,
830
- type: d,
831
- message: O,
832
- mergeInfo: L,
833
- checkoutInfo: H,
834
- rebaseInfo: _t
720
+ ...a,
721
+ type: E,
722
+ message: d,
723
+ mergeInfo: S,
724
+ checkoutInfo: R,
725
+ rebaseInfo: _
835
726
  };
836
727
  });
837
- }, gr = (t) => {
838
- const e = P(t), r = f.resolve(e, ".git"), s = f.resolve(r, "rebase-merge");
728
+ }, nr = (t) => {
729
+ const e = L(t), r = f.resolve(e, ".git"), s = f.resolve(r, "rebase-merge");
839
730
  if (g.existsSync(s))
840
731
  return !0;
841
732
  const n = f.resolve(r, "rebase-apply");
@@ -843,7 +734,7 @@ const K = "__GIT_REPLACE_MARK__", $ = {
843
734
  return !0;
844
735
  const o = f.resolve(r, "REBASE_HEAD");
845
736
  return !!g.existsSync(o);
846
- }, pr = ({
737
+ }, or = ({
847
738
  branchName: t,
848
739
  version: e,
849
740
  remoteInfo: r
@@ -853,19 +744,19 @@ const K = "__GIT_REPLACE_MARK__", $ = {
853
744
  }), p(`git push ${r.alias} ${t}`, {
854
745
  stdio: "inherit"
855
746
  }));
856
- }, _e = (t) => /^https?:\/\//.test(t), Ce = (t) => /^git@/.test(t), mr = (t) => {
747
+ }, le = (t) => /^https?:\/\//.test(t), ue = (t) => /^git@/.test(t), ir = (t) => {
857
748
  const { hostname: e, pathname: r } = new URL(t);
858
749
  return `git@${e}:${r.replace("/", "")}`;
859
- }, ye = (t) => f.resolve(t, ".git"), Sr = (t) => ue(ye(t)), Oe = ({
750
+ }, fe = (t) => f.resolve(t, ".git"), cr = (t) => $t(fe(t)), ge = ({
860
751
  dir: t,
861
752
  fn: e,
862
753
  endClear: r = !0,
863
754
  exitClear: s = !0
864
755
  }) => {
865
- if (dt(t))
866
- return a.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
756
+ if (w(t))
757
+ return l.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
867
758
  const n = () => {
868
- fe(t);
759
+ Lt(t);
869
760
  };
870
761
  s && process.once("exit", () => {
871
762
  n();
@@ -877,19 +768,19 @@ const K = "__GIT_REPLACE_MARK__", $ = {
877
768
  throw r && n(), c;
878
769
  }
879
770
  return r && (o instanceof Promise ? o.finally(n) : n()), o;
880
- };
881
- var Re = /* @__PURE__ */ ((t) => (t.ASSETS_CONFIG_REPO_URL = "ASSETS_CONFIG_REPO_URL", t))(Re || {});
882
- const ve = (t) => f.resolve(
883
- z(),
884
- $t,
885
- `${t}-${et()}`
886
- ), Me = () => f.resolve(W(), Nt), Ae = async () => {
887
- const t = Me(), 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 = {
888
779
  ASSETS_CONFIG_REPO_URL: Tt
889
780
  };
890
781
  try {
891
- if (await k(t)) {
892
- const r = await ht(t, {});
782
+ if (await B(t)) {
783
+ const r = await Q(t, {});
893
784
  Object.entries(r).forEach(([s, n]) => {
894
785
  e[s] = n;
895
786
  });
@@ -897,36 +788,32 @@ const ve = (t) => f.resolve(
897
788
  } catch {
898
789
  }
899
790
  return e;
900
- }, $e = async (t) => {
901
- if (await k(t))
902
- return a.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
791
+ }, he = async (t) => {
792
+ if (await B(t))
793
+ return l.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
903
794
  const {
904
795
  [
905
796
  "ASSETS_CONFIG_REPO_URL"
906
797
  /* ASSETS_CONFIG_REPO_URL */
907
798
  ]: e
908
- } = await Ae();
909
- return Ce(e) || _e(e) ? p(
910
- `git clone ${e} ${t} --depth=1`
911
- ) : (g.mkdirSync(t, { recursive: !0 }), p(
912
- `cp -r ${e}/ ${t}/`
913
- )), {
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}/`)), {
914
801
  assetConfigRepoUrl: e
915
802
  };
916
- }, dr = async ({
803
+ }, ar = async ({
917
804
  moduleName: t,
918
805
  onSuccess: e
919
- }) => (a.stage(`拉取${t}配置,请稍等...`), Oe({
806
+ }) => (l.stage(`拉取${t}配置,请稍等...`), ge({
920
807
  // 资源配置仓库临时文件夹
921
- dir: ve(t),
808
+ dir: _e(t),
922
809
  fn: async (r) => {
923
- const { assetConfigRepoUrl: s } = await $e(r), n = f.join(
924
- It,
810
+ const { assetConfigRepoUrl: s } = await he(r), n = f.join(
811
+ Pt,
925
812
  t
926
813
  ), o = f.join(
927
814
  n,
928
- Pt
929
- ), c = f.resolve(r, o), i = await ht(c);
815
+ Nt
816
+ ), c = f.resolve(r, o), i = await Q(c);
930
817
  return await e({
931
818
  repoUrl: s,
932
819
  config: i,
@@ -935,87 +822,130 @@ const ve = (t) => f.resolve(
935
822
  assetsConfigRepoTempDir: r
936
823
  }), i;
937
824
  }
938
- })), hr = (t) => Object.entries(t).map(([e, r]) => `--${e}=${r}`).join(" ");
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
+ });
939
874
  export {
940
- Re as DoneCodingCliGlobalConfigKeyEnum,
941
- te as EditorTypeEnum,
942
- Ft as EnvConfigCallModeEnum,
943
- Bt as EnvConfigProcessKeyEnum,
944
- w as GitRefLogTypeEnum,
945
- _ as HooksNameEnum,
946
- m as LogTypeEnum,
947
- ir as SUPPORT_GET_COMMIT_BY_HOOKS_NAMES,
948
- $r as _curry,
949
- Rr as _get,
950
- Mr as _set,
951
- or as addHuskyHooks,
952
- rr as addPackageConfig,
953
- at as allowConsoleLog,
954
- Oe as applyUseTempDir,
955
- dt as assetIsExits,
956
- k as assetIsExitsAsync,
957
- gr as checkCurrentIsRebasing,
958
- Xe as createMainCommand,
959
- Ze as createSubcommand,
960
- Ke as decryptAES,
961
- Ve as encryptAES,
962
- p as execSyncWithLogDispatch,
963
- le as fileAddX,
964
- h as formatLogSteamWrite,
965
- We as generateGetAnswerSwiftFn,
966
- Xt as getAnswer,
967
- ct as getCallMode,
968
- ve as getCliModuleTempDir,
969
- cr as getCommitByHookName,
970
- qe as getConfigFileCommonOptions,
971
- fr as getCurrentBranchLastCommitList,
972
- sr as getCurrentBranchName,
973
- Ht as getCurrentProcessLogFileName,
974
- ee as getEditorType,
975
- ar as getGitLastCommitInfo,
976
- ye as getGitPath,
977
- P as getGitProjectDir,
978
- ur as getLastReflogList,
979
- kt as getLogOutputDir,
980
- Je as getLogText,
981
- tt as getLogTime,
982
- Vt as getLogTypeByValue,
983
- x as getPackageJson,
984
- Jt as getParentProcessLogFileName,
985
- st as getProcessEnv,
986
- lt as getProcessLogStream,
987
- ce as getRelyPkgVersion,
988
- oe as getRootDirOptions,
989
- ze as getRootScriptName,
990
- bt as getSafePath,
991
- er as getUseDefaultConfig,
992
- mr as http2sshGitUrl,
993
- ie as initConfigFile,
994
- He as initEnvConfig,
995
- Qe as initHandlerCommon,
996
- _e as isHttpGitUrl,
997
- xt as isMcpMode,
998
- Ce as isSshGitUrl,
999
- yr as json5,
1000
- a as log,
1001
- Ye as lookForParentTarget,
1002
- ne as openFileInEditor,
1003
- hr as params2cliParams,
1004
- ke as pathIsSafe,
1005
- pr as pushGitPublishInfoToRemote,
1006
- dr as readCliModuleAssetsConfig,
1007
- tr as readConfigFile,
1008
- ge as readFile,
1009
- pe as readFileAsync,
1010
- nr as readJsonFile,
1011
- ht as readJsonFileAsync,
1012
- fe as removeAsset,
1013
- ue as removeAssetAsync,
1014
- ae as resolveCheckoutInfoByRefInfo,
1015
- Et as resolveMergeInfoByCommitMsg,
1016
- lr as resolveMergeInfoByGitReflogAction,
1017
- Ee as resolveMergeInfoByRefType,
1018
- Sr as rmGitCtrlAsync,
1019
- et as uuidv4,
1020
- j as xPrompts
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,
881
+ Ir as _curry,
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
1021
951
  };