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