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

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