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