@done-coding/cli-utils 0.8.2-alpha.1 → 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 +209 -202
  2. package/package.json +2 -2
  3. package/types/index.d.ts +28 -10
package/es/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { randomUUID as Ct } from "node:crypto";
3
3
  import { homedir as W, tmpdir as z } from "node:os";
4
- import l from "node:path";
5
- import g, { existsSync as A, mkdirSync as yt, writeFileSync as G, readFileSync as v } from "node:fs";
4
+ import f from "node:path";
5
+ import g, { existsSync as I, mkdirSync as yt, writeFileSync as T, readFileSync as v } from "node:fs";
6
6
  import M from "crypto";
7
7
  import X from "chalk";
8
8
  import Ot from "prompts";
@@ -11,16 +11,16 @@ import { hideBin as vt } from "yargs/helpers";
11
11
  import { execSync as Y } from "node:child_process";
12
12
  import Z from "json5";
13
13
  export * from "json5";
14
- import { default as Cr } from "json5";
14
+ import { default as yr } from "json5";
15
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";
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
20
  import R from "pinyin";
21
21
  const q = "__DONE_CODING_ENV_CONFIG__", Q = Symbol.for(
22
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 = () => {
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
24
  const t = /* @__PURE__ */ new Date();
25
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
26
  }, et = () => Ct();
@@ -40,8 +40,8 @@ const rt = (t) => `${q}_${t}`, st = (t, e) => {
40
40
  return !1;
41
41
  const s = rt(t), n = { value: e };
42
42
  return process.env[s] = JSON.stringify(n), !0;
43
- }, B = () => globalThis[Q], U = (t) => {
44
- const e = B();
43
+ }, F = () => globalThis[Q], B = (t) => {
44
+ const e = F();
45
45
  if (e)
46
46
  return e;
47
47
  const r = Object.freeze({
@@ -62,20 +62,20 @@ const rt = (t) => `${q}_${t}`, st = (t, e) => {
62
62
  callMode: "DEFAULT",
63
63
  series: e,
64
64
  consoleLog: !0,
65
- logOutputDir: `${F}/${e}/${Lt}`,
65
+ logOutputDir: `${b}/${e}/${Lt}`,
66
66
  processLogFileNameList: []
67
67
  };
68
- }, j = `${tt()}-${et()}`, it = (t) => {
68
+ }, U = `${tt()}-${et()}`, it = (t) => {
69
69
  const e = {
70
70
  ...t,
71
71
  processLogFileNameList: [
72
- j,
72
+ U,
73
73
  ...t.processLogFileNameList
74
74
  ].slice(0, 10)
75
75
  };
76
- return U(e);
76
+ return B(e);
77
77
  }, C = () => {
78
- const t = B();
78
+ const t = F();
79
79
  if (t)
80
80
  return t;
81
81
  const e = nt();
@@ -84,17 +84,17 @@ const rt = (t) => `${q}_${t}`, st = (t, e) => {
84
84
  {
85
85
  const s = {
86
86
  ...ot(),
87
- processLogFileNameList: [j]
87
+ processLogFileNameList: [U]
88
88
  };
89
- return U(s);
89
+ return B(s);
90
90
  }
91
- }, ke = ({
91
+ }, He = ({
92
92
  series: t,
93
93
  ...e
94
94
  }) => {
95
95
  if (jt)
96
96
  throw new Error("非顶级进程不允许调用该方法");
97
- if (B())
97
+ if (F())
98
98
  throw new Error(`内存全局配置存在,说明是以下某个原因:
99
99
  1. 顶级进程重复调用initEnvConfig
100
100
  2. 顶级进程在调用该方法之前调用了getApplyConfig, 即获取配置应用的同时会冻结配置 不会后续变化
@@ -110,12 +110,12 @@ const rt = (t) => `${q}_${t}`, st = (t, e) => {
110
110
  const o = {
111
111
  ...ot(t),
112
112
  ...e,
113
- processLogFileNameList: [j]
113
+ processLogFileNameList: [U]
114
114
  };
115
- return U(o);
115
+ return B(o);
116
116
  }
117
117
  }
118
- }, ct = () => C().callMode, xt = () => ct() === "MCP", at = () => xt() ? !1 : C().consoleLog, kt = (t = !1) => l.resolve(
118
+ }, ct = () => C().callMode, xt = () => ct() === "MCP", at = () => xt() ? !1 : C().consoleLog, kt = (t = !1) => f.resolve(
119
119
  t ? W() : z(),
120
120
  C().logOutputDir
121
121
  ), Ht = () => C().processLogFileNameList[0], Jt = () => C().processLogFileNameList[1];
@@ -124,7 +124,7 @@ const Yt = Object.entries(m).reduce(
124
124
  (t, [e, r]) => (t[r] = e, t),
125
125
  {}
126
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);
127
+ const e = f.resolve(t), r = f.dirname(e), s = E.get(e);
128
128
  if (s) {
129
129
  if (!s.destroyed && s.writable)
130
130
  return s;
@@ -155,7 +155,7 @@ process.once("exit", () => {
155
155
  } catch {
156
156
  }
157
157
  });
158
- const d = ({
158
+ const h = ({
159
159
  stream: t,
160
160
  type: e,
161
161
  content: r
@@ -164,17 +164,17 @@ const d = ({
164
164
  `
165
165
  );
166
166
  let V = !1;
167
- const ft = () => {
168
- const t = kt(), e = l.resolve(t, Ht()), r = Kt(e);
167
+ const lt = () => {
168
+ const t = kt(), e = f.resolve(t, Ht()), r = Kt(e);
169
169
  if (!V) {
170
170
  const s = Jt();
171
- s && d({
171
+ s && h({
172
172
  stream: r,
173
173
  type: m.SYSTEM,
174
174
  content: `父进程日志文件: ${s}`
175
175
  });
176
176
  const n = ct();
177
- d({
177
+ h({
178
178
  stream: r,
179
179
  type: m.SYSTEM,
180
180
  content: `当前调用模式: ${n}`
@@ -182,13 +182,13 @@ const ft = () => {
182
182
  }
183
183
  return r;
184
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({
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
187
  stream: r,
188
188
  type: e,
189
189
  content: s
190
190
  });
191
- }, zt = (...[t, ...e]) => at() ? t === m.TABLE ? console.table(...e) : console.log(X[t](...e)) : Wt(e, t), lt = (t) => Object.assign(t, {
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
192
  /** 系统 */
193
193
  system: (...e) => t(m.SYSTEM, ...e),
194
194
  /** 成功 */
@@ -205,21 +205,21 @@ const ft = () => {
205
205
  skip: (...e) => t(m.SKIP, ...e),
206
206
  /** 表格 */
207
207
  table: (...e) => t(m.TABLE, ...e)
208
- }), a = lt(zt), He = lt(
208
+ }), a = ft(zt), Je = ft(
209
209
  (t, ...e) => t === m.TABLE ? JSON.stringify(e) : X[t](...e)
210
- ), Je = (t, {
210
+ ), Ye = (t, {
211
211
  /** 当前目录 */
212
212
  currentDir: e = process.cwd(),
213
213
  /** 优先找最远的父目录 */
214
214
  isFindFarthest: r = !0
215
215
  } = {}) => {
216
- const s = l.resolve(e).split(l.sep).map((n, o, c) => c.slice(0, o).concat(n).join(l.sep) || l.sep);
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
217
  for (; s.length; ) {
218
- const n = r ? s.shift() : s.pop(), o = l.join(n, t);
218
+ const n = r ? s.shift() : s.pop(), o = f.join(n, t);
219
219
  if (g.existsSync(o))
220
220
  return n;
221
221
  }
222
- }, ut = "aes-256-cbc", gt = 16, I = "hex", w = ":";
222
+ }, ut = "aes-256-cbc", gt = 16, A = "hex", G = ":";
223
223
  function pt(t) {
224
224
  return M.pbkdf2Sync(
225
225
  t,
@@ -232,7 +232,7 @@ function pt(t) {
232
232
  "sha256"
233
233
  );
234
234
  }
235
- function Ye({
235
+ function Ve({
236
236
  text: t,
237
237
  secretKey: e
238
238
  }) {
@@ -240,34 +240,34 @@ function Ye({
240
240
  const r = pt(e), s = M.randomBytes(gt), n = M.createCipheriv(ut, r, s);
241
241
  let o = n.update(t);
242
242
  o = Buffer.concat([o, n.final()]);
243
- const c = s.toString(I), i = o.toString(I);
244
- return `${c}${w}${i}`;
243
+ const c = s.toString(A), i = o.toString(A);
244
+ return `${c}${G}${i}`;
245
245
  } catch (r) {
246
246
  return a.error(
247
247
  `加密失败: ${r instanceof Error ? r.message : String(r)}`
248
248
  ), "";
249
249
  }
250
250
  }
251
- function Ve({
251
+ function Ke({
252
252
  encryptedText: t,
253
253
  secretKey: e
254
254
  }) {
255
255
  try {
256
- if (!t.includes(w))
256
+ if (!t.includes(G))
257
257
  return "";
258
- const r = pt(e), [s, n] = t.split(w);
258
+ const r = pt(e), [s, n] = t.split(G);
259
259
  if (s.length !== gt * 2)
260
260
  return "";
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();
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();
264
264
  } catch (r) {
265
265
  return a.error(
266
266
  `解密失败: ${r instanceof Error ? r.message : String(r)}`
267
267
  ), "";
268
268
  }
269
269
  }
270
- const P = (...t) => {
270
+ const j = (...t) => {
271
271
  const [e, r = {}] = t;
272
272
  return Ot(e, {
273
273
  onCancel(s) {
@@ -275,21 +275,27 @@ const P = (...t) => {
275
275
  },
276
276
  ...r
277
277
  });
278
- }, Ke = async ({
278
+ }, Xt = async ({
279
279
  isMCP: t,
280
280
  key: e,
281
281
  presetAnswer: r,
282
282
  defaultValue: s,
283
283
  questionConfig: n
284
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) => {
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) => {
291
297
  t ? a.error(t) : a.error(e.message), e != null && e.stack && a.error(e.stack), process.exit(1);
292
- }, Zt = () => {
298
+ }, qt = () => {
293
299
  const t = vt(process.argv);
294
300
  return Rt(t);
295
301
  }, ze = ({
@@ -305,7 +311,7 @@ const P = (...t) => {
305
311
  if (typeof r == "string")
306
312
  return s.includes("/") ? void 0 : s;
307
313
  if (typeof r == "object") {
308
- const n = Object.entries(r), o = process.argv[1], c = n.filter(([, f]) => o == null ? void 0 : o.endsWith(f));
314
+ const n = Object.entries(r), o = process.argv[1], c = n.filter(([, l]) => o == null ? void 0 : o.endsWith(l));
309
315
  if (c.length !== 1)
310
316
  return;
311
317
  const [i] = c[0];
@@ -320,14 +326,14 @@ const P = (...t) => {
320
326
  positionals: o,
321
327
  subcommands: c,
322
328
  rootScriptName: i
323
- }, f) => {
329
+ }, l) => {
324
330
  let u = t.strict();
325
331
  e && (u = u.usage(`Usage: ${e}`)), s && (u = u.demandCommand(s));
326
332
  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;
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;
328
334
  }, Xe = async ({ handler: t, ...e }) => {
329
- const r = await mt(Zt(), e, !0).fail(
330
- Xt
335
+ const r = await mt(qt(), e, !0).fail(
336
+ Zt
331
337
  ).argv;
332
338
  return t ? t(r) : r;
333
339
  }, Ze = (t) => {
@@ -341,7 +347,7 @@ const P = (...t) => {
341
347
  },
342
348
  handler: s
343
349
  };
344
- }, qt = (t) => {
350
+ }, Qt = (t) => {
345
351
  if (!t)
346
352
  return ["pipe", "pipe", "pipe"];
347
353
  if (typeof t == "string")
@@ -365,9 +371,9 @@ const P = (...t) => {
365
371
  }, p = (t, e) => {
366
372
  if (at() || (e == null ? void 0 : e.stdio) === "ignore")
367
373
  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);
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);
369
375
  try {
370
- d({
376
+ h({
371
377
  stream: s,
372
378
  type: m.SYSTEM,
373
379
  content: `[子进程任务开始执行] ${t}`
@@ -379,30 +385,30 @@ const P = (...t) => {
379
385
  stdio: c,
380
386
  encoding: (e == null ? void 0 : e.encoding) || "utf-8"
381
387
  });
382
- return i && o[1] === "pipe" ? d({
388
+ return i && o[1] === "pipe" ? h({
383
389
  stream: s,
384
390
  type: m.SYSTEM,
385
391
  content: `[任务执行成功返回]: ${i.toString().trim()}`
386
- }) : d({
392
+ }) : h({
387
393
  stream: s,
388
394
  type: m.SYSTEM,
389
395
  content: "[任务执行成功]"
390
396
  }), i;
391
397
  } catch (i) {
392
- const f = i.stderr ? `
398
+ const l = i.stderr ? `
393
399
  STDERR: ${i.stderr}` : "";
394
- throw d({
400
+ throw h({
395
401
  stream: s,
396
402
  type: m.ERROR,
397
403
  content: `[任务执行失败]: ${t}
398
404
  STATUS: ${i.status}
399
- MSG: ${i.message}${f}`
405
+ MSG: ${i.message}${l}`
400
406
  }), i;
401
407
  }
402
408
  };
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([
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([
406
412
  {
407
413
  name: "editorType",
408
414
  type: "select",
@@ -419,24 +425,24 @@ const te = async () => {
419
425
  }
420
426
  ]);
421
427
  return t;
422
- }, ee = {
428
+ }, re = {
423
429
  Cursor: "cursor",
424
430
  VsCode: "code"
425
- }, re = (t, e, r) => {
431
+ }, se = (t, e, r) => {
426
432
  try {
427
433
  p(`${t} -v`, { stdio: "ignore" }), p(`${t} ${e}`);
428
434
  } catch {
429
435
  r();
430
436
  }
431
- }, se = (t, e) => {
437
+ }, ne = (t, e) => {
432
438
  const r = (s) => a.info(`
433
439
  ${s}, 请用编辑器打开 ${t} 进行编辑
434
440
  `);
435
441
  switch (e) {
436
442
  case "Cursor":
437
443
  case "VsCode": {
438
- const s = ee[e];
439
- re(s, t, () => {
444
+ const s = re[e];
445
+ se(s, t, () => {
440
446
  r(`${s}命令未安装`);
441
447
  });
442
448
  break;
@@ -444,7 +450,7 @@ const te = async () => {
444
450
  default:
445
451
  r("其他编辑器");
446
452
  }
447
- }, ne = (t = process.cwd()) => ({
453
+ }, oe = (t = process.cwd()) => ({
448
454
  /** 必须保留 */
449
455
  rootDir: {
450
456
  type: "string",
@@ -458,7 +464,7 @@ const te = async () => {
458
464
  rootDirDefault: e
459
465
  }) => ({
460
466
  /** 必须保留 */
461
- ...ne(e),
467
+ ...oe(e),
462
468
  /** 必须保留 */
463
469
  configPath: {
464
470
  type: "string",
@@ -467,23 +473,23 @@ const te = async () => {
467
473
  /** 必须设置默认值 */
468
474
  default: t
469
475
  }
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, {
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, {
473
479
  recursive: !0
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);
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);
475
481
  }, Qe = async (t, e, {
476
482
  onFileGenerated: r,
477
483
  edit: s = !1
478
484
  } = {}) => {
479
- const n = await oe(t, e);
485
+ const n = await ie(t, e);
480
486
  if (r == null || r(n), s) {
481
- const o = await te();
482
- se(e.configPath, o);
487
+ const o = await ee();
488
+ ne(e.configPath, o);
483
489
  }
484
490
  }, tr = async (t, e) => {
485
- const { configPath: r, rootDir: s } = t, n = l.resolve(s, r);
486
- if (!A(n)) {
491
+ const { configPath: r, rootDir: s } = t, n = f.resolve(s, r);
492
+ if (!I(n)) {
487
493
  if (e)
488
494
  return a.info("配置文件不存在,使用onNotExists返回值"), e();
489
495
  const o = `配置文件不存在 ${n}`;
@@ -491,7 +497,7 @@ const te = async () => {
491
497
  }
492
498
  return n.endsWith(".json5") ? (a.info(`json5模式解析 ${n}`), Z.parse(v(n, "utf8"))) : (a.info(`json模式解析 ${n}`), JSON.parse(v(n, "utf8")));
493
499
  }, er = async () => {
494
- const { useDefaultConfig: t } = await P({
500
+ const { useDefaultConfig: t } = await j({
495
501
  name: "useDefaultConfig",
496
502
  type: "confirm",
497
503
  message: "使用默认模板配置",
@@ -501,12 +507,12 @@ const te = async () => {
501
507
  }, St = "package.json", x = ({
502
508
  rootDir: t
503
509
  }) => {
504
- const e = l.resolve(t, St);
505
- if (!A(e))
510
+ const e = f.resolve(t, St);
511
+ if (!I(e))
506
512
  throw new Error(`${t}未找到package.json文件`);
507
513
  const r = v(e, "utf-8");
508
514
  return JSON.parse(r);
509
- }, ie = ({
515
+ }, ce = ({
510
516
  rootDir: t,
511
517
  pkgJson: e,
512
518
  pkgName: r,
@@ -528,9 +534,9 @@ const te = async () => {
528
534
  }) => {
529
535
  if (!t)
530
536
  return;
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) => {
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) => {
534
540
  const r = p("git rev-parse --show-toplevel", {
535
541
  cwd: t
536
542
  }).toString();
@@ -552,7 +558,7 @@ const te = async () => {
552
558
  return;
553
559
  }
554
560
  }
555
- }, ce = (t) => {
561
+ }, ae = (t) => {
556
562
  const e = t.match(/moving\s+from\s+(.*)\s+to\s+(.*)/);
557
563
  if (e) {
558
564
  const [, r, s] = e;
@@ -561,40 +567,40 @@ const te = async () => {
561
567
  toBranch: s.trim()
562
568
  };
563
569
  }
564
- }, T = 73, ae = (t) => {
570
+ }, D = 73, le = (t) => {
565
571
  const r = g.statSync(t).mode;
566
- if ((r & T) === T)
572
+ if ((r & D) === D)
567
573
  return;
568
574
  a.stage(`${t} 没有执行权限 添加... `);
569
- const s = r | T;
575
+ const s = r | D;
570
576
  g.chmodSync(t, s), a.success(`${t} 添加执行权限成功`);
571
- }, ht = (t) => g.existsSync(t), k = async (t) => {
577
+ }, dt = (t) => g.existsSync(t), k = async (t) => {
572
578
  try {
573
579
  return await g.promises.lstat(t), !0;
574
580
  } catch (e) {
575
581
  return e.code !== "ENOENT";
576
582
  }
577
583
  }, fe = (t, e = !1) => {
578
- ht(t) && g.rmSync(t, { recursive: !0, force: e });
579
- }, le = async (t, e = !1) => {
584
+ dt(t) && g.rmSync(t, { recursive: !0, force: e });
585
+ }, ue = async (t, e = !1) => {
580
586
  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;
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;
582
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))(_ || {});
583
- const pe = "husky", me = ".husky", Se = ({ rootDir: t }) => {
584
- const e = N(t), r = ie({
589
+ const me = "husky", Se = ".husky", de = ({ rootDir: t }) => {
590
+ const e = P(t), r = ce({
585
591
  rootDir: e,
586
592
  pkgJson: x({ rootDir: e }),
587
- pkgName: pe,
593
+ pkgName: me,
588
594
  isDevPkg: !0
589
595
  });
590
596
  if (!r)
591
597
  throw new Error("husky版本获取失败, 可能husky未安装");
592
598
  const s = r.replace(/^(\^|~)/, ""), n = "<9.0.0";
593
- return It.satisfies(s, n) ? (a.info(`${s}符合${n}`), `#!/usr/bin/env sh
599
+ return At.satisfies(s, n) ? (a.info(`${s}符合${n}`), `#!/usr/bin/env sh
594
600
  . "$(dirname -- "$0")/_/husky.sh"`) : (a.info(`${s}不符合${n}`), "");
595
601
  }, he = ({ rootDir: t }) => {
596
- const e = N(t);
597
- return l.resolve(e, me);
602
+ const e = P(t);
603
+ return f.resolve(e, Se);
598
604
  }, or = ({
599
605
  hookNames: t,
600
606
  rootDir: e,
@@ -602,7 +608,7 @@ const pe = "husky", me = ".husky", Se = ({ rootDir: t }) => {
602
608
  }) => {
603
609
  const s = he({ rootDir: e });
604
610
  g.existsSync(s) || g.mkdirSync(s, { recursive: !0 }), t.forEach((n) => {
605
- const o = l.resolve(s, n), c = g.existsSync(o);
611
+ const o = f.resolve(s, n), c = g.existsSync(o);
606
612
  let i = r(n);
607
613
  if (c)
608
614
  g.readFileSync(o, "utf-8").includes(i) ? a.skip(`${o} ${n}相关调用 ${i} 已存在 跳过`) : (g.appendFileSync(
@@ -612,19 +618,19 @@ ${i}
612
618
  `
613
619
  ), a.success(`${o} 添加 ${n}相关调用成功`));
614
620
  else {
615
- const f = Se({
621
+ const l = de({
616
622
  rootDir: e
617
623
  });
618
624
  g.writeFileSync(
619
625
  o,
620
- `${f}
626
+ `${l}
621
627
 
622
628
  ${i}
623
629
  `,
624
630
  "utf-8"
625
631
  ), a.success(`${o} 添加 ${n}相关调用成功`);
626
632
  }
627
- ae(o);
633
+ le(o);
628
634
  });
629
635
  }, ir = [
630
636
  // HooksNameEnum.PRE_MERGE_COMMIT,
@@ -634,12 +640,12 @@ ${i}
634
640
  hookName: t,
635
641
  rootDir: e
636
642
  }) => {
637
- const r = N(e), s = l.resolve(r, ".git");
643
+ const r = P(e), s = f.resolve(r, ".git");
638
644
  switch (t) {
639
645
  case _.PREPARE_COMMIT_MSG:
640
646
  case _.COMMIT_MSG: {
641
- const n = l.resolve(s, "MERGE_MSG");
642
- if (A(n))
647
+ const n = f.resolve(s, "MERGE_MSG");
648
+ if (I(n))
643
649
  return v(n, "utf-8");
644
650
  }
645
651
  }
@@ -657,9 +663,9 @@ ${i}
657
663
  ).toString().trim(), o = p("git config user.name").toString().trim(), c = p("git config user.email").toString().trim(), i = p(
658
664
  "git rev-parse --abbrev-ref HEAD"
659
665
  ).toString().trim();
660
- let f = "";
666
+ let l = "";
661
667
  try {
662
- f = p(
668
+ l = p(
663
669
  `git config --get remote.${t}.url`
664
670
  ).toString().trim();
665
671
  } catch {
@@ -681,9 +687,9 @@ ${i}
681
687
  }).join(""),
682
688
  userEmail: c,
683
689
  branchName: i,
684
- remoteInfo: f ? {
690
+ remoteInfo: l ? {
685
691
  alias: t,
686
- url: f
692
+ url: l
687
693
  } : void 0
688
694
  };
689
695
  } catch (e) {
@@ -692,18 +698,18 @@ ${i}
692
698
  }, Et = (t = "") => {
693
699
  const e = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+into\s+['|"](.+)['|"]\s*/i, r = t.match(e);
694
700
  if (r) {
695
- const [, i, f] = r;
701
+ const [, i, l] = r;
696
702
  return {
697
703
  fromBranch: i,
698
- toBranch: f
704
+ toBranch: l
699
705
  };
700
706
  }
701
707
  const s = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+of\s+.+\s+into\s+['|"](.+)['|"]\s*/i, n = t.match(s);
702
708
  if (n) {
703
- const [, i, f] = n;
709
+ const [, i, l] = n;
704
710
  return {
705
711
  fromBranch: i,
706
- toBranch: f
712
+ toBranch: l
707
713
  };
708
714
  }
709
715
  const o = /\s*Merge\s+branch\s+['|"](.+)['|"](\s+of)?\s*/i, c = t.match(o);
@@ -713,12 +719,12 @@ ${i}
713
719
  fromBranch: i
714
720
  };
715
721
  }
716
- }, de = (t) => {
717
- if (t.startsWith(b.MERGE))
722
+ }, Ee = (t) => {
723
+ if (t.startsWith(w.MERGE))
718
724
  return {
719
- fromBranch: t.replace(b.MERGE, "").trim()
725
+ fromBranch: t.replace(w.MERGE, "").trim()
720
726
  };
721
- }, fr = () => {
727
+ }, lr = () => {
722
728
  const t = process.env.GIT_REFLOG_ACTION || "";
723
729
  if (!t)
724
730
  return;
@@ -737,7 +743,7 @@ ${i}
737
743
  };
738
744
  }
739
745
  };
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 || {});
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 || {});
741
747
  const K = "__GIT_REPLACE_MARK__", $ = {
742
748
  stringify(t) {
743
749
  return JSON.stringify(t).replace(/"/g, K);
@@ -745,7 +751,7 @@ const K = "__GIT_REPLACE_MARK__", $ = {
745
751
  parse(t) {
746
752
  return JSON.parse(t.replace(new RegExp(K, "g"), '"'));
747
753
  }
748
- }, lr = ({
754
+ }, fr = ({
749
755
  count: t = 100
750
756
  } = {}) => {
751
757
  if (t <= 0)
@@ -798,44 +804,44 @@ const K = "__GIT_REPLACE_MARK__", $ = {
798
804
  )}"`
799
805
  ).toString().split(`
800
806
  `).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;
803
- if (h.startsWith(
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(
804
810
  "checkout"
805
811
  /* CHECKOUT */
806
812
  ))
807
- H = ce(O);
808
- else if (h.startsWith(
813
+ H = ae(O);
814
+ else if (d.startsWith(
809
815
  "merge"
810
816
  /* MERGE */
811
817
  ))
812
- D = de(h);
813
- else if (h.startsWith(
818
+ L = Ee(d);
819
+ else if (d.startsWith(
814
820
  "commit (merge)"
815
821
  /* COMMIT_MERGE */
816
822
  )) {
817
823
  const J = Et(O);
818
824
  J || a.warn(
819
825
  `${i.hash} 是合并提交 但是未从提交信息(${O})中检测到合并分支信息,推测手动更改了提交内容`
820
- ), D = J;
826
+ ), L = J;
821
827
  }
822
828
  return {
823
829
  ...u,
824
- type: h,
830
+ type: d,
825
831
  message: O,
826
- mergeInfo: D,
832
+ mergeInfo: L,
827
833
  checkoutInfo: H,
828
834
  rebaseInfo: _t
829
835
  };
830
836
  });
831
837
  }, gr = (t) => {
832
- const e = N(t), r = l.resolve(e, ".git"), s = l.resolve(r, "rebase-merge");
838
+ const e = P(t), r = f.resolve(e, ".git"), s = f.resolve(r, "rebase-merge");
833
839
  if (g.existsSync(s))
834
840
  return !0;
835
- const n = l.resolve(r, "rebase-apply");
841
+ const n = f.resolve(r, "rebase-apply");
836
842
  if (g.existsSync(n))
837
843
  return !0;
838
- const o = l.resolve(r, "REBASE_HEAD");
844
+ const o = f.resolve(r, "REBASE_HEAD");
839
845
  return !!g.existsSync(o);
840
846
  }, pr = ({
841
847
  branchName: t,
@@ -847,22 +853,22 @@ const K = "__GIT_REPLACE_MARK__", $ = {
847
853
  }), p(`git push ${r.alias} ${t}`, {
848
854
  stdio: "inherit"
849
855
  }));
850
- }, Ee = (t) => /^https?:\/\//.test(t), _e = (t) => /^git@/.test(t), mr = (t) => {
856
+ }, _e = (t) => /^https?:\/\//.test(t), Ce = (t) => /^git@/.test(t), mr = (t) => {
851
857
  const { hostname: e, pathname: r } = new URL(t);
852
858
  return `git@${e}:${r.replace("/", "")}`;
853
- }, Ce = (t) => l.resolve(t, ".git"), Sr = (t) => le(Ce(t)), ye = ({
859
+ }, ye = (t) => f.resolve(t, ".git"), Sr = (t) => ue(ye(t)), Oe = ({
854
860
  dir: t,
855
861
  fn: e,
856
862
  endClear: r = !0,
857
863
  exitClear: s = !0
858
864
  }) => {
859
- if (ht(t))
865
+ if (dt(t))
860
866
  return a.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
861
867
  const n = () => {
862
- a.stage("正在清理临时目录...", t), fe(t);
868
+ fe(t);
863
869
  };
864
870
  s && process.once("exit", () => {
865
- a.stage("发现进程退出,正在清理临时目录...", t), n();
871
+ n();
866
872
  });
867
873
  let o;
868
874
  try {
@@ -872,18 +878,18 @@ const K = "__GIT_REPLACE_MARK__", $ = {
872
878
  }
873
879
  return r && (o instanceof Promise ? o.finally(n) : n()), o;
874
880
  };
875
- var Oe = /* @__PURE__ */ ((t) => (t.ASSETS_CONFIG_REPO_URL = "ASSETS_CONFIG_REPO_URL", t))(Oe || {});
876
- const Re = (t) => l.resolve(
881
+ var Re = /* @__PURE__ */ ((t) => (t.ASSETS_CONFIG_REPO_URL = "ASSETS_CONFIG_REPO_URL", t))(Re || {});
882
+ const ve = (t) => f.resolve(
877
883
  z(),
878
884
  $t,
879
885
  `${t}-${et()}`
880
- ), ve = () => l.resolve(W(), Nt), Me = async () => {
881
- const t = ve(), e = {
886
+ ), Me = () => f.resolve(W(), Nt), Ae = async () => {
887
+ const t = Me(), e = {
882
888
  ASSETS_CONFIG_REPO_URL: Tt
883
889
  };
884
890
  try {
885
891
  if (await k(t)) {
886
- const r = await dt(t, {});
892
+ const r = await ht(t, {});
887
893
  Object.entries(r).forEach(([s, n]) => {
888
894
  e[s] = n;
889
895
  });
@@ -891,7 +897,7 @@ const Re = (t) => l.resolve(
891
897
  } catch {
892
898
  }
893
899
  return e;
894
- }, Ie = async (t) => {
900
+ }, $e = async (t) => {
895
901
  if (await k(t))
896
902
  return a.error(`${t} 已存在,请手动删除该目录再试`), process.exit(1);
897
903
  const {
@@ -899,28 +905,28 @@ const Re = (t) => l.resolve(
899
905
  "ASSETS_CONFIG_REPO_URL"
900
906
  /* ASSETS_CONFIG_REPO_URL */
901
907
  ]: e
902
- } = await Me();
903
- return _e(e) || Ee(e) ? p(
908
+ } = await Ae();
909
+ return Ce(e) || _e(e) ? p(
904
910
  `git clone ${e} ${t} --depth=1`
905
911
  ) : (g.mkdirSync(t, { recursive: !0 }), p(
906
912
  `cp -r ${e}/ ${t}/`
907
913
  )), {
908
914
  assetConfigRepoUrl: e
909
915
  };
910
- }, hr = async ({
916
+ }, dr = async ({
911
917
  moduleName: t,
912
918
  onSuccess: e
913
- }) => (a.stage(`拉取${t}配置,请稍等...`), ye({
919
+ }) => (a.stage(`拉取${t}配置,请稍等...`), Oe({
914
920
  // 资源配置仓库临时文件夹
915
- dir: Re(t),
921
+ dir: ve(t),
916
922
  fn: async (r) => {
917
- const { assetConfigRepoUrl: s } = await Ie(r), n = l.join(
918
- At,
923
+ const { assetConfigRepoUrl: s } = await $e(r), n = f.join(
924
+ It,
919
925
  t
920
- ), o = l.join(
926
+ ), o = f.join(
921
927
  n,
922
928
  Pt
923
- ), c = l.resolve(r, o), i = await dt(c);
929
+ ), c = f.resolve(r, o), i = await ht(c);
924
930
  return await e({
925
931
  repoUrl: s,
926
932
  config: i,
@@ -929,86 +935,87 @@ const Re = (t) => l.resolve(
929
935
  assetsConfigRepoTempDir: r
930
936
  }), i;
931
937
  }
932
- }));
938
+ })), hr = (t) => Object.entries(t).map(([e, r]) => `--${e}=${r}`).join(" ");
933
939
  export {
934
- Oe as DoneCodingCliGlobalConfigKeyEnum,
935
- Qt as EditorTypeEnum,
940
+ Re as DoneCodingCliGlobalConfigKeyEnum,
941
+ te as EditorTypeEnum,
936
942
  Ft as EnvConfigCallModeEnum,
937
943
  Bt as EnvConfigProcessKeyEnum,
938
- b as GitRefLogTypeEnum,
944
+ w as GitRefLogTypeEnum,
939
945
  _ as HooksNameEnum,
940
946
  m as LogTypeEnum,
941
947
  ir as SUPPORT_GET_COMMIT_BY_HOOKS_NAMES,
942
- Ir as _curry,
943
- Or as _get,
944
- vr as _set,
948
+ $r as _curry,
949
+ Rr as _get,
950
+ Mr as _set,
945
951
  or as addHuskyHooks,
946
952
  rr as addPackageConfig,
947
953
  at as allowConsoleLog,
948
- ye as applyUseTempDir,
949
- ht as assetIsExits,
954
+ Oe as applyUseTempDir,
955
+ dt as assetIsExits,
950
956
  k as assetIsExitsAsync,
951
957
  gr as checkCurrentIsRebasing,
952
958
  Xe as createMainCommand,
953
959
  Ze as createSubcommand,
954
- Ve as decryptAES,
955
- Ye as encryptAES,
960
+ Ke as decryptAES,
961
+ Ve as encryptAES,
956
962
  p as execSyncWithLogDispatch,
957
- ae as fileAddX,
958
- d as formatLogSteamWrite,
959
- We as getAnswerSwift,
960
- Ke as getAnswerWithMCP,
963
+ le as fileAddX,
964
+ h as formatLogSteamWrite,
965
+ We as generateGetAnswerSwiftFn,
966
+ Xt as getAnswer,
961
967
  ct as getCallMode,
962
- Re as getCliModuleTempDir,
968
+ ve as getCliModuleTempDir,
963
969
  cr as getCommitByHookName,
964
970
  qe as getConfigFileCommonOptions,
965
- lr as getCurrentBranchLastCommitList,
971
+ fr as getCurrentBranchLastCommitList,
966
972
  sr as getCurrentBranchName,
967
973
  Ht as getCurrentProcessLogFileName,
968
- te as getEditorType,
974
+ ee as getEditorType,
969
975
  ar as getGitLastCommitInfo,
970
- Ce as getGitPath,
971
- N as getGitProjectDir,
976
+ ye as getGitPath,
977
+ P as getGitProjectDir,
972
978
  ur as getLastReflogList,
973
979
  kt as getLogOutputDir,
974
- He as getLogText,
980
+ Je as getLogText,
975
981
  tt as getLogTime,
976
982
  Vt as getLogTypeByValue,
977
983
  x as getPackageJson,
978
984
  Jt as getParentProcessLogFileName,
979
985
  st as getProcessEnv,
980
- ft as getProcessLogStream,
981
- ie as getRelyPkgVersion,
982
- ne as getRootDirOptions,
986
+ lt as getProcessLogStream,
987
+ ce as getRelyPkgVersion,
988
+ oe as getRootDirOptions,
983
989
  ze as getRootScriptName,
984
990
  bt as getSafePath,
985
991
  er as getUseDefaultConfig,
986
992
  mr as http2sshGitUrl,
987
- oe as initConfigFile,
988
- ke as initEnvConfig,
993
+ ie as initConfigFile,
994
+ He as initEnvConfig,
989
995
  Qe as initHandlerCommon,
990
- Ee as isHttpGitUrl,
996
+ _e as isHttpGitUrl,
991
997
  xt as isMcpMode,
992
- _e as isSshGitUrl,
993
- Cr as json5,
998
+ Ce as isSshGitUrl,
999
+ yr as json5,
994
1000
  a as log,
995
- Je as lookForParentTarget,
996
- se as openFileInEditor,
997
- xe as pathIsSafe,
1001
+ Ye as lookForParentTarget,
1002
+ ne as openFileInEditor,
1003
+ hr as params2cliParams,
1004
+ ke as pathIsSafe,
998
1005
  pr as pushGitPublishInfoToRemote,
999
- hr as readCliModuleAssetsConfig,
1006
+ dr as readCliModuleAssetsConfig,
1000
1007
  tr as readConfigFile,
1001
- ue as readFile,
1002
- ge as readFileAsync,
1008
+ ge as readFile,
1009
+ pe as readFileAsync,
1003
1010
  nr as readJsonFile,
1004
- dt as readJsonFileAsync,
1011
+ ht as readJsonFileAsync,
1005
1012
  fe as removeAsset,
1006
- le as removeAssetAsync,
1007
- ce as resolveCheckoutInfoByRefInfo,
1013
+ ue as removeAssetAsync,
1014
+ ae as resolveCheckoutInfoByRefInfo,
1008
1015
  Et as resolveMergeInfoByCommitMsg,
1009
- fr as resolveMergeInfoByGitReflogAction,
1010
- de as resolveMergeInfoByRefType,
1016
+ lr as resolveMergeInfoByGitReflogAction,
1017
+ Ee as resolveMergeInfoByRefType,
1011
1018
  Sr as rmGitCtrlAsync,
1012
1019
  et as uuidv4,
1013
- P as xPrompts
1020
+ j as xPrompts
1014
1021
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-utils",
3
- "version": "0.8.2-alpha.1",
3
+ "version": "0.8.2-alpha.2",
4
4
  "description": "cli utils",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -68,5 +68,5 @@
68
68
  "semver": "^7.5.4",
69
69
  "yargs": "^17.7.2"
70
70
  },
71
- "gitHead": "660e39fc523e4eba1ea621e3c59122f98015a2de"
71
+ "gitHead": "7683cce31678dfecc6b35014f9658ad8b59f0c97"
72
72
  }
package/types/index.d.ts CHANGED
@@ -225,12 +225,14 @@ export declare const formatLogSteamWrite: ({ stream, type, content, }: {
225
225
  content: string;
226
226
  }) => boolean;
227
227
 
228
- export { _get }
229
-
230
- /** 快捷获取答案 */
231
- export declare const getAnswerSwift: <V = unknown, T extends string = string>(key: T,
228
+ /** 生成 获取答案的快捷函数 */
229
+ export declare const generateGetAnswerSwiftFn: ({ isMCP, presetAnswer, }: Pick<GetAnswerOptions<unknown, string>, "isMCP" | "presetAnswer">) => <V = unknown, T extends string = string>(key: T,
232
230
  /** 表单问询配置 */
233
- questionConfig: Parameters<typeof prompts<T>>[0]) => Promise<V>;
231
+ questionConfig?: Parameters<typeof prompts<T>>[0],
232
+ /** 默认值 */
233
+ defaultValue?: V) => Promise<V | undefined>;
234
+
235
+ export { _get }
234
236
 
235
237
  /**
236
238
  * 获取答案 考虑mcp情况
@@ -238,18 +240,26 @@ questionConfig: Parameters<typeof prompts<T>>[0]) => Promise<V>;
238
240
  * mcp 只拿预设值,非mcp优先拿默认值
239
241
  * 有预设值的场景: MCP
240
242
  */
241
- export declare const getAnswerWithMCP: <V = unknown, T extends string = string>({ isMCP, key, presetAnswer, defaultValue, questionConfig, }: {
243
+ export declare const getAnswer: <V = unknown, T extends string = string>({ isMCP, key, presetAnswer, defaultValue, questionConfig, }: GetAnswerOptions<V, T>) => GetAnswerResult<V, T, typeof questionConfig>;
244
+
245
+ /** 获取答案 考虑mcp情况 的选项 */
246
+ export declare interface GetAnswerOptions<V, T extends string> {
242
247
  /** 是否mcp场景 */
243
- isMCP: boolean;
248
+ isMCP?: boolean;
244
249
  /** 表单key */
245
250
  key: T;
246
251
  /** 预设答案所在的对象 */
247
- presetAnswer?: object & { [K in T]: any; };
252
+ presetAnswer?: object & {
253
+ [K in T]?: any;
254
+ };
248
255
  /** 默认值 */
249
256
  defaultValue?: V;
250
257
  /** 表单问询配置 */
251
- questionConfig: Parameters<typeof prompts<T>>[0];
252
- }) => Promise<V>;
258
+ questionConfig?: Parameters<typeof prompts<T>>[0];
259
+ }
260
+
261
+ /** 获取答案结果类型 */
262
+ export declare type GetAnswerResult<V, T extends string, Q extends GetAnswerOptions<V, T>["questionConfig"]> = Promise<Q extends undefined ? V | undefined : V>;
253
263
 
254
264
  /** 获取调用模式 */
255
265
  export declare const getCallMode: () => EnvConfigCallModeEnum;
@@ -665,6 +675,14 @@ export declare interface PackageJson {
665
675
  peerDependencies?: Record<string, string>;
666
676
  }
667
677
 
678
+ /**
679
+ * 参数转cli参数
680
+ * -----
681
+ * yargs 参数格式:
682
+ * --key=value
683
+ */
684
+ export declare const params2cliParams: (params: Record<string, any>) => string;
685
+
668
686
  /** 路径是否安全 */
669
687
  export declare const pathIsSafe: (path?: string) => boolean;
670
688