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

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