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

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