@done-coding/cli-utils 0.7.8 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/index.mjs CHANGED
@@ -1,54 +1,56 @@
1
1
  #!/usr/bin/env node
2
2
  import p from "chalk";
3
- import { default as ce } from "chalk";
4
- import g from "node:path";
5
- import m, { existsSync as y, mkdirSync as W, writeFileSync as D, readFileSync as v, rmSync as X } from "node:fs";
6
- import _ from "crypto";
7
- import q from "prompts";
8
- import z from "yargs";
9
- import { hideBin as Q } from "yargs/helpers";
3
+ import { default as Ie } from "chalk";
4
+ import l from "node:path";
5
+ import m, { existsSync as I, mkdirSync as q, writeFileSync as b, readFileSync as R } from "node:fs";
6
+ import C from "crypto";
7
+ import z from "prompts";
8
+ import Q from "yargs";
9
+ import { hideBin as Z } from "yargs/helpers";
10
10
  import { execSync as u } from "node:child_process";
11
- import H from "json5";
11
+ import F from "json5";
12
12
  export * from "json5";
13
- import { default as fe } from "json5";
14
- import Z from "lodash.merge";
15
- import tt from "semver";
16
- import { tmpdir as et } from "node:os";
17
- import { default as ue } from "lodash.get";
18
- import { default as pe } from "lodash.set";
19
- import { default as de } from "lodash.curry";
20
- import E from "pinyin";
21
- const f = Object.assign(
22
- (t, ...r) => console.log(...r.map((e) => p[t](e))),
13
+ import { default as Ae } from "json5";
14
+ import tt from "lodash.merge";
15
+ import et from "semver";
16
+ import { tmpdir as rt, homedir as st } from "node:os";
17
+ import { v4 as ot } from "uuid";
18
+ import { v4 as be } from "uuid";
19
+ import { default as Te } from "lodash.get";
20
+ import { default as Ne } from "lodash.set";
21
+ import { default as Ge } from "lodash.curry";
22
+ import _ from "pinyin";
23
+ const g = Object.assign(
24
+ (t, ...e) => console.log(...e.map((r) => p[t](r))),
23
25
  {
24
26
  /** 成功 */
25
- success: (...t) => f("green", ...t),
27
+ success: (...t) => g("green", ...t),
26
28
  /** /步骤 */
27
- stage: (...t) => f("blue", ...t),
29
+ stage: (...t) => g("blue", ...t),
28
30
  /** 提示信息 */
29
- info: (...t) => f("cyan", ...t),
31
+ info: (...t) => g("cyan", ...t),
30
32
  /** 警告 */
31
- warn: (...t) => f("yellow", ...t),
33
+ warn: (...t) => g("yellow", ...t),
32
34
  /** 错误 */
33
- error: (...t) => f("red", ...t),
35
+ error: (...t) => g("red", ...t),
34
36
  /** 跳过 */
35
- skip: (...t) => f("gray", ...t)
37
+ skip: (...t) => g("gray", ...t)
36
38
  }
37
- ), Bt = (t, {
39
+ ), Qt = (t, {
38
40
  /** 当前目录 */
39
- currentDir: r = process.cwd(),
41
+ currentDir: e = process.cwd(),
40
42
  /** 优先找最远的父目录 */
41
- isFindFarthest: e = !0
43
+ isFindFarthest: r = !0
42
44
  } = {}) => {
43
- const s = g.resolve(r).split(g.sep).map((o, n, c) => c.slice(0, n).concat(o).join(g.sep) || g.sep);
44
- for (; s.length; ) {
45
- const o = e ? s.shift() : s.pop(), n = g.join(o, t);
45
+ const o = l.resolve(e).split(l.sep).map((s, n, c) => c.slice(0, n).concat(s).join(l.sep) || l.sep);
46
+ for (; o.length; ) {
47
+ const s = r ? o.shift() : o.pop(), n = l.join(s, t);
46
48
  if (m.existsSync(n))
47
- return o;
49
+ return s;
48
50
  }
49
- }, G = "aes-256-cbc", N = 16, M = "hex", w = ":";
50
- function F(t) {
51
- return _.pbkdf2Sync(
51
+ }, x = "aes-256-cbc", j = 16, O = "hex", w = ":";
52
+ function k(t) {
53
+ return C.pbkdf2Sync(
52
54
  t,
53
55
  "done-coding-cli-salt",
54
56
  // 使用固定的盐值
@@ -59,68 +61,68 @@ function F(t) {
59
61
  "sha256"
60
62
  );
61
63
  }
62
- function kt({
64
+ function Zt({
63
65
  text: t,
64
- secretKey: r
66
+ secretKey: e
65
67
  }) {
66
68
  try {
67
- const e = F(r), s = _.randomBytes(N), o = _.createCipheriv(G, e, s);
68
- let n = o.update(t);
69
- n = Buffer.concat([n, o.final()]);
70
- const c = s.toString(M), i = n.toString(M);
69
+ const r = k(e), o = C.randomBytes(j), s = C.createCipheriv(x, r, o);
70
+ let n = s.update(t);
71
+ n = Buffer.concat([n, s.final()]);
72
+ const c = o.toString(O), i = n.toString(O);
71
73
  return `${c}${w}${i}`;
72
- } catch (e) {
73
- return f.error(
74
- `加密失败: ${e instanceof Error ? e.message : String(e)}`
74
+ } catch (r) {
75
+ return g.error(
76
+ `加密失败: ${r instanceof Error ? r.message : String(r)}`
75
77
  ), "";
76
78
  }
77
79
  }
78
- function jt({
80
+ function te({
79
81
  encryptedText: t,
80
- secretKey: r
82
+ secretKey: e
81
83
  }) {
82
84
  try {
83
85
  if (!t.includes(w))
84
86
  return "";
85
- const e = F(r), [s, o] = t.split(w);
86
- if (s.length !== N * 2)
87
+ const r = k(e), [o, s] = t.split(w);
88
+ if (o.length !== j * 2)
87
89
  return "";
88
- const n = Buffer.from(s, M), c = Buffer.from(o, M), i = _.createDecipheriv(G, e, n);
89
- let a = i.update(c);
90
- return a = Buffer.concat([a, i.final()]), a.toString();
91
- } catch (e) {
92
- return f.error(
93
- `解密失败: ${e instanceof Error ? e.message : String(e)}`
90
+ const n = Buffer.from(o, O), c = Buffer.from(s, O), i = C.createDecipheriv(x, r, n);
91
+ let f = i.update(c);
92
+ return f = Buffer.concat([f, i.final()]), f.toString();
93
+ } catch (r) {
94
+ return g.error(
95
+ `解密失败: ${r instanceof Error ? r.message : String(r)}`
94
96
  ), "";
95
97
  }
96
98
  }
97
- const L = (...t) => {
98
- const [r, e = {}] = t;
99
- return q(r, {
100
- onCancel(s) {
101
- return f.error(`退出${s == null ? void 0 : s.name}输入`), process.exit(1);
99
+ const H = (...t) => {
100
+ const [e, r = {}] = t;
101
+ return z(e, {
102
+ onCancel(o) {
103
+ return g.error(`退出${o == null ? void 0 : o.name}输入`), process.exit(1);
102
104
  },
103
- ...e
105
+ ...r
104
106
  });
105
- }, rt = (t, r) => {
106
- t ? f.error(t) : f.error(r.message), r != null && r.stack && f.error(r.stack), process.exit(1);
107
- }, st = () => {
108
- const t = Q(process.argv);
109
- return z(t);
110
- }, xt = ({
107
+ }, nt = (t, e) => {
108
+ t ? g.error(t) : g.error(e.message), e != null && e.stack && g.error(e.stack), process.exit(1);
109
+ }, it = () => {
110
+ const t = Z(process.argv);
111
+ return Q(t);
112
+ }, ee = ({
111
113
  rootScriptName: t,
112
- packageJson: r
114
+ packageJson: e
113
115
  }) => {
114
116
  if (t)
115
117
  return t;
116
- if (!r)
118
+ if (!e)
117
119
  return;
118
- const { bin: e, name: s } = r;
119
- if (e) {
120
- if (typeof e == "string")
121
- return s.includes("/") ? void 0 : s;
122
- if (typeof e == "object") {
123
- const o = Object.entries(e), n = process.argv[1], c = o.filter(([, a]) => n == null ? void 0 : n.endsWith(a));
120
+ const { bin: r, name: o } = e;
121
+ if (r) {
122
+ if (typeof r == "string")
123
+ return o.includes("/") ? void 0 : o;
124
+ if (typeof r == "object") {
125
+ const s = Object.entries(r), n = process.argv[1], c = s.filter(([, f]) => n == null ? void 0 : n.endsWith(f));
124
126
  if (c.length !== 1)
125
127
  return;
126
128
  const [i] = c[0];
@@ -128,38 +130,38 @@ const L = (...t) => {
128
130
  }
129
131
  }
130
132
  }, U = (t, {
131
- usage: r,
132
- version: e,
133
- demandCommandCount: s,
134
- options: o,
133
+ usage: e,
134
+ version: r,
135
+ demandCommandCount: o,
136
+ options: s,
135
137
  positionals: n,
136
138
  subcommands: c,
137
139
  rootScriptName: i
138
- }, a) => {
139
- let l = t.strict();
140
- r && (l = l.usage(`Usage: ${r}`)), s && (l = l.demandCommand(s));
140
+ }, f) => {
141
+ let a = t.strict();
142
+ e && (a = a.usage(`Usage: ${e}`)), o && (a = a.demandCommand(o));
141
143
  const h = "help";
142
- return l = l.help(h), e ? l = l.version(e).alias("h", h).alias("v", "version") : l = l.alias("h", h), o && (l = l.options(o)), n && (l = Object.entries(n).reduce((S, [P, d]) => S.positional(P, d), l)), c && (l = l.command(c)), a && i && (l = l.scriptName(i)), l;
143
- }, Ht = async ({ handler: t, ...r }) => {
144
- const e = await U(st(), r, !0).fail(
145
- rt
144
+ return a = a.help(h), r ? a = a.version(r).alias("h", h).alias("v", "version") : a = a.alias("h", h), s && (a = a.options(s)), n && (a = Object.entries(n).reduce((y, [M, d]) => y.positional(M, d), a)), c && (a = a.command(c)), f && i && (a = a.scriptName(i)), a;
145
+ }, re = async ({ handler: t, ...e }) => {
146
+ const r = await U(it(), e, !0).fail(
147
+ nt
146
148
  ).argv;
147
- return t ? t(e) : e;
148
- }, Gt = (t) => {
149
- const { command: r, describe: e, handler: s = () => {
150
- }, ...o } = t;
149
+ return t ? t(r) : r;
150
+ }, se = (t) => {
151
+ const { command: e, describe: r, handler: o = () => {
152
+ }, ...s } = t;
151
153
  return {
152
- command: r,
153
- describe: e,
154
+ command: e,
155
+ describe: r,
154
156
  builder(n) {
155
- return U(n, o, !1);
157
+ return U(n, s, !1);
156
158
  },
157
- handler: s
159
+ handler: o
158
160
  };
159
161
  };
160
- var ot = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(ot || {});
161
- const nt = async () => {
162
- const { editorType: t } = await L([
162
+ var ct = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(ct || {});
163
+ const at = async () => {
164
+ const { editorType: t } = await H([
163
165
  {
164
166
  name: "editorType",
165
167
  type: "select",
@@ -169,39 +171,39 @@ const nt = async () => {
169
171
  "VsCode",
170
172
  "其他"
171
173
  /* OTHER */
172
- ].map((r) => ({
173
- title: r,
174
- value: r
174
+ ].map((e) => ({
175
+ title: e,
176
+ value: e
175
177
  }))
176
178
  }
177
179
  ]);
178
180
  return t;
179
- }, it = {
181
+ }, lt = {
180
182
  Cursor: "cursor",
181
183
  VsCode: "code"
182
- }, ct = (t, r, e) => {
184
+ }, ft = (t, e, r) => {
183
185
  try {
184
- u(`${t} -v`, { stdio: "ignore" }), u(`${t} ${r}`);
186
+ u(`${t} -v`, { stdio: "ignore" }), u(`${t} ${e}`);
185
187
  } catch {
186
- e();
188
+ r();
187
189
  }
188
- }, at = (t, r) => {
189
- const e = (s) => f.info(`
190
- ${s}, 请用编辑器打开 ${t} 进行编辑
190
+ }, gt = (t, e) => {
191
+ const r = (o) => g.info(`
192
+ ${o}, 请用编辑器打开 ${t} 进行编辑
191
193
  `);
192
- switch (r) {
194
+ switch (e) {
193
195
  case "Cursor":
194
196
  case "VsCode": {
195
- const s = it[r];
196
- ct(s, t, () => {
197
- e(`${s}命令未安装`);
197
+ const o = lt[e];
198
+ ft(o, t, () => {
199
+ r(`${o}命令未安装`);
198
200
  });
199
201
  break;
200
202
  }
201
203
  default:
202
- e("其他编辑器");
204
+ r("其他编辑器");
203
205
  }
204
- }, lt = (t = process.cwd()) => ({
206
+ }, ut = (t = process.cwd()) => ({
205
207
  /** 必须保留 */
206
208
  rootDir: {
207
209
  type: "string",
@@ -210,12 +212,12 @@ const nt = async () => {
210
212
  /** 必须设置默认值 */
211
213
  default: t
212
214
  }
213
- }), Nt = ({
215
+ }), oe = ({
214
216
  configPathDefault: t,
215
- rootDirDefault: r
217
+ rootDirDefault: e
216
218
  }) => ({
217
219
  /** 必须保留 */
218
- ...lt(r),
220
+ ...ut(e),
219
221
  /** 必须保留 */
220
222
  configPath: {
221
223
  type: "string",
@@ -224,227 +226,237 @@ const nt = async () => {
224
226
  /** 必须设置默认值 */
225
227
  default: t
226
228
  }
227
- }), ft = async (t, r) => {
228
- const { configPath: e, rootDir: s } = r, o = g.resolve(s, e), n = g.dirname(o);
229
- return y(n) || W(n, {
229
+ }), mt = async (t, e) => {
230
+ const { configPath: r, rootDir: o } = e, s = l.resolve(o, r), n = l.dirname(s);
231
+ return I(n) || q(n, {
230
232
  recursive: !0
231
- }), o.endsWith(".json5") ? (f.info(`json5模式写入 ${o}`), D(o, H.stringify(t, null, 2)), o) : (f.info(`json模式写入 ${o}`), D(o, JSON.stringify(t, null, 2)), o);
232
- }, Ft = async (t, r, {
233
- onFileGenerated: e,
234
- edit: s = !1
233
+ }), s.endsWith(".json5") ? (g.info(`json5模式写入 ${s}`), b(s, F.stringify(t, null, 2)), s) : (g.info(`json模式写入 ${s}`), b(s, JSON.stringify(t, null, 2)), s);
234
+ }, ne = async (t, e, {
235
+ onFileGenerated: r,
236
+ edit: o = !1
235
237
  } = {}) => {
236
- const o = await ft(t, r);
237
- if (e == null || e(o), s) {
238
- const n = await nt();
239
- at(r.configPath, n);
238
+ const s = await mt(t, e);
239
+ if (r == null || r(s), o) {
240
+ const n = await at();
241
+ gt(e.configPath, n);
240
242
  }
241
- }, Lt = async (t, r) => {
242
- const { configPath: e, rootDir: s } = t, o = g.resolve(s, e);
243
- if (!y(o)) {
244
- if (r)
245
- return f.info("配置文件不存在,使用onNotExists返回值"), r();
246
- const n = `配置文件不存在 ${o}`;
243
+ }, ie = async (t, e) => {
244
+ const { configPath: r, rootDir: o } = t, s = l.resolve(o, r);
245
+ if (!I(s)) {
246
+ if (e)
247
+ return g.info("配置文件不存在,使用onNotExists返回值"), e();
248
+ const n = `配置文件不存在 ${s}`;
247
249
  throw new Error(n);
248
250
  }
249
- return o.endsWith(".json5") ? (f.info(`json5模式解析 ${o}`), H.parse(v(o, "utf8"))) : (f.info(`json模式解析 ${o}`), JSON.parse(v(o, "utf8")));
250
- }, Ut = async () => {
251
- const { useDefaultConfig: t } = await L({
251
+ return s.endsWith(".json5") ? (g.info(`json5模式解析 ${s}`), F.parse(R(s, "utf8"))) : (g.info(`json模式解析 ${s}`), JSON.parse(R(s, "utf8")));
252
+ }, ce = async () => {
253
+ const { useDefaultConfig: t } = await H({
252
254
  name: "useDefaultConfig",
253
255
  type: "confirm",
254
256
  message: "使用默认模板配置",
255
257
  initial: !0
256
258
  });
257
259
  return t;
258
- }, J = "package.json", T = ({
260
+ }, J = "package.json", D = ({
259
261
  rootDir: t
260
262
  }) => {
261
- const r = g.resolve(t, J);
262
- if (!y(r))
263
+ const e = l.resolve(t, J);
264
+ if (!I(e))
263
265
  throw new Error(`${t}未找到package.json文件`);
264
- const e = v(r, "utf-8");
265
- return JSON.parse(e);
266
- }, gt = ({
266
+ const r = R(e, "utf-8");
267
+ return JSON.parse(r);
268
+ }, pt = ({
267
269
  rootDir: t,
268
- pkgJson: r,
269
- pkgName: e,
270
- isDevPkg: s
270
+ pkgJson: e,
271
+ pkgName: r,
272
+ isDevPkg: o
271
273
  }) => {
272
- const o = r || T({ rootDir: t }), n = s ? o.devDependencies : o.dependencies;
273
- let c = n == null ? void 0 : n[e];
274
+ const s = e || D({ rootDir: t }), n = o ? s.devDependencies : s.dependencies;
275
+ let c = n == null ? void 0 : n[r];
274
276
  if (!c) {
275
- const i = s ? o.dependencies : o.devDependencies;
276
- c = i == null ? void 0 : i[e], c && console.log(
277
+ const i = o ? s.dependencies : s.devDependencies;
278
+ c = i == null ? void 0 : i[r], c && console.log(
277
279
  p.yellow(
278
- `${s ? "开发" : "生产"}依赖包${e}可能错误的安装在${s ? "dependencies" : "devDependencies"}`
280
+ `${o ? "开发" : "生产"}依赖包${r}可能错误的安装在${o ? "dependencies" : "devDependencies"}`
279
281
  )
280
282
  );
281
283
  return;
282
284
  }
283
- return c || console.log(p.cyan(`依赖包${e}未安装`)), c;
284
- }, Jt = ({
285
+ return c || console.log(p.cyan(`依赖包${r}未安装`)), c;
286
+ }, ae = ({
285
287
  patchConfig: t,
286
- rootDir: r
288
+ rootDir: e
287
289
  }) => {
288
290
  if (!t)
289
291
  return;
290
- const e = T({ rootDir: r }), s = Z(e, t), o = g.resolve(r, J);
291
- D(o, JSON.stringify(s, null, 2), "utf-8");
292
- }, O = (t) => {
293
- const e = u("git rev-parse --show-toplevel", {
292
+ const r = D({ rootDir: e }), o = tt(r, t), s = l.resolve(e, J);
293
+ b(s, JSON.stringify(o, null, 2), "utf-8");
294
+ }, $ = (t) => {
295
+ const r = u("git rev-parse --show-toplevel", {
294
296
  cwd: t
295
297
  }).toString();
296
- if (!e)
298
+ if (!r)
297
299
  throw new Error("获取git根目录失败");
298
- return e.trim();
299
- }, Kt = () => {
300
+ return r.trim();
301
+ }, le = () => {
300
302
  var t;
301
303
  try {
302
- const r = u("git symbolic-ref --short HEAD", {
304
+ const e = u("git symbolic-ref --short HEAD", {
303
305
  stdio: "ignore"
304
306
  });
305
- return (t = r == null ? void 0 : r.toString()) == null ? void 0 : t.trim();
307
+ return (t = e == null ? void 0 : e.toString()) == null ? void 0 : t.trim();
306
308
  } catch {
307
309
  try {
308
- const e = u("git rev-parse --short HEAD").toString().trim();
309
- f.skip(`当前未指向具体某个分支, 当前commit hash: ${e}`);
310
+ const r = u("git rev-parse --short HEAD").toString().trim();
311
+ g.skip(`当前未指向具体某个分支, 当前commit hash: ${r}`);
310
312
  } finally {
311
313
  return;
312
314
  }
313
315
  }
314
- }, ut = (t) => {
315
- const r = t.match(/moving\s+from\s+(.*)\s+to\s+(.*)/);
316
- if (r) {
317
- const [, e, s] = r;
316
+ }, ht = (t) => {
317
+ const e = t.match(/moving\s+from\s+(.*)\s+to\s+(.*)/);
318
+ if (e) {
319
+ const [, r, o] = e;
318
320
  return {
319
- fromBranch: e.trim(),
320
- toBranch: s.trim()
321
+ fromBranch: r.trim(),
322
+ toBranch: o.trim()
321
323
  };
322
324
  }
323
- }, I = 73, mt = (t) => {
324
- const e = m.statSync(t).mode;
325
- if ((e & I) === I)
325
+ }, P = 73, dt = (t) => {
326
+ const r = m.statSync(t).mode;
327
+ if ((r & P) === P)
326
328
  return;
327
329
  console.log(p.blue(`${t} 没有执行权限 添加... `));
328
- const s = e | I;
329
- m.chmodSync(t, s), console.log(p.green(`${t} 添加执行权限成功`));
330
- };
331
- var R = /* @__PURE__ */ ((t) => (t.PRE_COMMIT = "pre-commit", t.PRE_MERGE_COMMIT = "pre-merge-commit", t.PREPARE_COMMIT_MSG = "prepare-commit-msg", t.COMMIT_MSG = "commit-msg", t.PRE_REBASE = "pre-rebase", t.POST_COMMIT = "post-commit", t.POST_MERGE = "post-merge", t.PRE_PUSH = "pre-push", t))(R || {});
332
- const pt = "husky", ht = ".husky", dt = ({ rootDir: t }) => {
333
- const r = O(t), e = gt({
334
- rootDir: r,
335
- pkgJson: T({ rootDir: r }),
336
- pkgName: pt,
330
+ const o = r | P;
331
+ m.chmodSync(t, o), console.log(p.green(`${t} 添加执行权限成功`));
332
+ }, V = (t) => m.existsSync(t), N = async (t) => {
333
+ try {
334
+ return await m.promises.lstat(t), !0;
335
+ } catch (e) {
336
+ return e.code !== "ENOENT";
337
+ }
338
+ }, St = (t, e = !1) => {
339
+ V(t) && m.rmSync(t, { recursive: !0, force: e });
340
+ }, fe = async (t, e = !1) => {
341
+ await N(t) && await m.promises.rm(t, { recursive: !0, force: e });
342
+ }, yt = (t) => m.readFileSync(t, "utf-8"), Et = (t) => m.promises.readFile(t, "utf-8"), ge = (t, e) => JSON.parse(yt(t)) || e, K = async (t, e) => JSON.parse(await Et(t)) || e;
343
+ var S = /* @__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))(S || {});
344
+ const _t = "husky", Rt = ".husky", Ct = ({ rootDir: t }) => {
345
+ const e = $(t), r = pt({
346
+ rootDir: e,
347
+ pkgJson: D({ rootDir: e }),
348
+ pkgName: _t,
337
349
  isDevPkg: !0
338
350
  });
339
- if (!e)
351
+ if (!r)
340
352
  throw new Error("husky版本获取失败, 可能husky未安装");
341
- const s = e.replace(/^(\^|~)/, ""), o = "<9.0.0";
342
- return tt.satisfies(s, o) ? (console.log(p.cyan(`${s}符合${o}`)), `#!/usr/bin/env sh
343
- . "$(dirname -- "$0")/_/husky.sh"`) : (console.log(p.cyan(`${s}不符合${o}`)), "");
344
- }, yt = ({ rootDir: t }) => {
345
- const r = O(t);
346
- return g.resolve(r, ht);
347
- }, Yt = ({
353
+ const o = r.replace(/^(\^|~)/, ""), s = "<9.0.0";
354
+ return et.satisfies(o, s) ? (console.log(p.cyan(`${o}符合${s}`)), `#!/usr/bin/env sh
355
+ . "$(dirname -- "$0")/_/husky.sh"`) : (console.log(p.cyan(`${o}不符合${s}`)), "");
356
+ }, Ot = ({ rootDir: t }) => {
357
+ const e = $(t);
358
+ return l.resolve(e, Rt);
359
+ }, ue = ({
348
360
  hookNames: t,
349
- rootDir: r,
350
- getCode: e
361
+ rootDir: e,
362
+ getCode: r
351
363
  }) => {
352
- const s = yt({ rootDir: r });
353
- m.existsSync(s) || m.mkdirSync(s, { recursive: !0 }), t.forEach((o) => {
354
- const n = g.resolve(s, o), c = m.existsSync(n);
355
- let i = e(o);
364
+ const o = Ot({ rootDir: e });
365
+ m.existsSync(o) || m.mkdirSync(o, { recursive: !0 }), t.forEach((s) => {
366
+ const n = l.resolve(o, s), c = m.existsSync(n);
367
+ let i = r(s);
356
368
  if (c)
357
369
  m.readFileSync(n, "utf-8").includes(i) ? console.log(
358
- p.gray(`${n} ${o}相关调用 ${i} 已存在 跳过`)
370
+ p.gray(`${n} ${s}相关调用 ${i} 已存在 跳过`)
359
371
  ) : (m.appendFileSync(
360
372
  n,
361
373
  `
362
374
  ${i}
363
375
  `
364
- ), console.log(p.green(`${n} 添加 ${o}相关调用成功`)));
376
+ ), console.log(p.green(`${n} 添加 ${s}相关调用成功`)));
365
377
  else {
366
- const a = dt({
367
- rootDir: r
378
+ const f = Ct({
379
+ rootDir: e
368
380
  });
369
381
  m.writeFileSync(
370
382
  n,
371
- `${a}
383
+ `${f}
372
384
 
373
385
  ${i}
374
386
  `,
375
387
  "utf-8"
376
- ), console.log(p.green(`${n} 添加 ${o}相关调用成功`));
388
+ ), console.log(p.green(`${n} 添加 ${s}相关调用成功`));
377
389
  }
378
- mt(n);
390
+ dt(n);
379
391
  });
380
- }, Vt = [
392
+ }, me = [
381
393
  // HooksNameEnum.PRE_MERGE_COMMIT,
382
- R.PREPARE_COMMIT_MSG,
383
- R.COMMIT_MSG
384
- ], Wt = ({
394
+ S.PREPARE_COMMIT_MSG,
395
+ S.COMMIT_MSG
396
+ ], pe = ({
385
397
  hookName: t,
386
- rootDir: r
398
+ rootDir: e
387
399
  }) => {
388
- const e = O(r), s = g.resolve(e, ".git");
400
+ const r = $(e), o = l.resolve(r, ".git");
389
401
  switch (t) {
390
- case R.PREPARE_COMMIT_MSG:
391
- case R.COMMIT_MSG: {
392
- const o = g.resolve(s, "MERGE_MSG");
393
- if (y(o))
394
- return v(o, "utf-8");
402
+ case S.PREPARE_COMMIT_MSG:
403
+ case S.COMMIT_MSG: {
404
+ const s = l.resolve(o, "MERGE_MSG");
405
+ if (I(s))
406
+ return R(s, "utf-8");
395
407
  }
396
408
  }
397
409
  return "";
398
- }, Xt = ({
410
+ }, he = ({
399
411
  remoteAlias: t = "origin"
400
412
  } = {}) => {
401
413
  try {
402
- const r = u("git rev-parse HEAD").toString().trim(), e = u('git log -1 --pretty=format:"%an"').toString().trim(), s = u('git log -1 --pretty=format:"%ae"').toString().trim(), o = u('git log -1 --pretty=format:"%s"').toString().trim(), n = u("git config user.name").toString().trim(), c = u("git config user.email").toString().trim(), i = u("git rev-parse --abbrev-ref HEAD").toString().trim();
403
- let a = "";
414
+ const e = u("git rev-parse HEAD").toString().trim(), r = u('git log -1 --pretty=format:"%an"').toString().trim(), o = u('git log -1 --pretty=format:"%ae"').toString().trim(), s = u('git log -1 --pretty=format:"%s"').toString().trim(), n = u("git config user.name").toString().trim(), c = u("git config user.email").toString().trim(), i = u("git rev-parse --abbrev-ref HEAD").toString().trim();
415
+ let f = "";
404
416
  try {
405
- a = u(`git config --get remote.${t}.url`).toString().trim();
417
+ f = u(`git config --get remote.${t}.url`).toString().trim();
406
418
  } catch {
407
- f.warn("git远程仓库地址获取失败或者不存在");
419
+ g.warn("git远程仓库地址获取失败或者不存在");
408
420
  }
409
421
  return {
410
- lastHash: r,
411
- lastCommitter: e,
412
- lastCommitterPinYin: E(e, {
413
- style: E.STYLE_NORMAL,
422
+ lastHash: e,
423
+ lastCommitter: r,
424
+ lastCommitterPinYin: _(r, {
425
+ style: _.STYLE_NORMAL,
414
426
  heteronym: !1
415
427
  }).join(""),
416
- lastCommitEmail: s,
417
- lastCommitMsg: o,
428
+ lastCommitEmail: o,
429
+ lastCommitMsg: s,
418
430
  userName: n,
419
- userNamePinYin: E(n, {
420
- style: E.STYLE_NORMAL,
431
+ userNamePinYin: _(n, {
432
+ style: _.STYLE_NORMAL,
421
433
  heteronym: !1
422
434
  }).join(""),
423
435
  userEmail: c,
424
436
  branchName: i,
425
- remoteInfo: a ? {
437
+ remoteInfo: f ? {
426
438
  alias: t,
427
- url: a
439
+ url: f
428
440
  } : void 0
429
441
  };
430
- } catch (r) {
431
- throw f.error("获取git最后提交信息失败"), r;
442
+ } catch (e) {
443
+ throw g.error("获取git最后提交信息失败"), e;
432
444
  }
433
- }, K = (t = "") => {
434
- const r = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+into\s+['|"](.+)['|"]\s*/i, e = t.match(r);
435
- if (e) {
436
- const [, i, a] = e;
445
+ }, Y = (t = "") => {
446
+ const e = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+into\s+['|"](.+)['|"]\s*/i, r = t.match(e);
447
+ if (r) {
448
+ const [, i, f] = r;
437
449
  return {
438
450
  fromBranch: i,
439
- toBranch: a
451
+ toBranch: f
440
452
  };
441
453
  }
442
- const s = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+of\s+.+\s+into\s+['|"](.+)['|"]\s*/i, o = t.match(s);
443
- if (o) {
444
- const [, i, a] = o;
454
+ const o = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+of\s+.+\s+into\s+['|"](.+)['|"]\s*/i, s = t.match(o);
455
+ if (s) {
456
+ const [, i, f] = s;
445
457
  return {
446
458
  fromBranch: i,
447
- toBranch: a
459
+ toBranch: f
448
460
  };
449
461
  }
450
462
  const n = /\s*Merge\s+branch\s+['|"](.+)['|"](\s+of)?\s*/i, c = t.match(n);
@@ -454,44 +466,44 @@ ${i}
454
466
  fromBranch: i
455
467
  };
456
468
  }
457
- }, Rt = (t) => {
458
- if (t.startsWith(A.MERGE))
469
+ }, vt = (t) => {
470
+ if (t.startsWith(T.MERGE))
459
471
  return {
460
- fromBranch: t.replace(A.MERGE, "").trim()
472
+ fromBranch: t.replace(T.MERGE, "").trim()
461
473
  };
462
- }, qt = () => {
474
+ }, de = () => {
463
475
  const t = process.env.GIT_REFLOG_ACTION || "";
464
476
  if (!t)
465
477
  return;
466
- const r = /merge\s+([^\s]+)\s*/i, e = t.match(r);
467
- if (e) {
468
- const [, n] = e;
478
+ const e = /merge\s+([^\s]+)\s*/i, r = t.match(e);
479
+ if (r) {
480
+ const [, n] = r;
469
481
  return {
470
482
  fromBranch: n
471
483
  };
472
484
  }
473
- const s = /pull\s+([^\s]+)\s+([^\s]+)/, o = t.match(s);
474
- if (o) {
475
- const [, , n] = o;
485
+ const o = /pull\s+([^\s]+)\s+([^\s]+)/, s = t.match(o);
486
+ if (s) {
487
+ const [, , n] = s;
476
488
  return {
477
489
  fromBranch: n
478
490
  };
479
491
  }
480
492
  };
481
- var A = /* @__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))(A || {});
482
- const j = "__GIT_REPLACE_MARK__", $ = {
493
+ var T = /* @__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))(T || {});
494
+ const L = "__GIT_REPLACE_MARK__", v = {
483
495
  stringify(t) {
484
- return JSON.stringify(t).replace(/"/g, j);
496
+ return JSON.stringify(t).replace(/"/g, L);
485
497
  },
486
498
  parse(t) {
487
- return JSON.parse(t.replace(new RegExp(j, "g"), '"'));
499
+ return JSON.parse(t.replace(new RegExp(L, "g"), '"'));
488
500
  }
489
- }, zt = ({
501
+ }, Se = ({
490
502
  count: t = 100
491
503
  } = {}) => {
492
504
  if (t <= 0)
493
505
  return [];
494
- const r = {
506
+ const e = {
495
507
  hash: "%H",
496
508
  /** 提交信息 */
497
509
  message: "%s",
@@ -509,24 +521,24 @@ const j = "__GIT_REPLACE_MARK__", $ = {
509
521
  commitTime: "%ci"
510
522
  };
511
523
  return u(
512
- `git --no-pager log --oneline -n ${t} --pretty=format:"${$.stringify(
513
- r
524
+ `git --no-pager log --oneline -n ${t} --pretty=format:"${v.stringify(
525
+ e
514
526
  )}"`
515
527
  ).toString().split(`
516
528
  `).map((n) => {
517
- const c = $.parse(n);
529
+ const c = v.parse(n);
518
530
  return {
519
531
  ...c,
520
- mergeInfo: K(c.message)
532
+ mergeInfo: Y(c.message)
521
533
  };
522
534
  });
523
- }, Qt = ({
535
+ }, ye = ({
524
536
  count: t = 100,
525
- filterItem: r = () => !0
537
+ filterItem: e = () => !0
526
538
  } = {}) => {
527
539
  if (t <= 0)
528
540
  return [];
529
- const e = {
541
+ const r = {
530
542
  hash: "%H",
531
543
  fullMessage: "%gs",
532
544
  committer: "%cn",
@@ -534,145 +546,200 @@ const j = "__GIT_REPLACE_MARK__", $ = {
534
546
  commitTime: "%ci"
535
547
  };
536
548
  return u(
537
- `git --no-pager reflog -n ${t} --pretty=format:"${$.stringify(
538
- e
549
+ `git --no-pager reflog -n ${t} --pretty=format:"${v.stringify(
550
+ r
539
551
  )}"`
540
552
  ).toString().split(`
541
- `).map((i) => $.parse(i)).filter(r).map((i) => {
542
- const { fullMessage: a, ...l } = i, h = ":", [S] = a.split(h, 1), P = a.slice(`${S}${h}`.length), d = S.trim(), C = P.trim();
543
- let b, B, V;
553
+ `).map((i) => v.parse(i)).filter(e).map((i) => {
554
+ const { fullMessage: f, ...a } = i, h = ":", [y] = f.split(h, 1), M = f.slice(`${y}${h}`.length), d = y.trim(), E = M.trim();
555
+ let A, B, X;
544
556
  if (d.startsWith(
545
557
  "checkout"
546
558
  /* CHECKOUT */
547
559
  ))
548
- B = ut(C);
560
+ B = ht(E);
549
561
  else if (d.startsWith(
550
562
  "merge"
551
563
  /* MERGE */
552
564
  ))
553
- b = Rt(d);
565
+ A = vt(d);
554
566
  else if (d.startsWith(
555
567
  "commit (merge)"
556
568
  /* COMMIT_MERGE */
557
569
  )) {
558
- const k = K(C);
559
- k || f.warn(
560
- `${i.hash} 是合并提交 但是未从提交信息(${C})中检测到合并分支信息,推测手动更改了提交内容`
561
- ), b = k;
570
+ const G = Y(E);
571
+ G || g.warn(
572
+ `${i.hash} 是合并提交 但是未从提交信息(${E})中检测到合并分支信息,推测手动更改了提交内容`
573
+ ), A = G;
562
574
  }
563
575
  return {
564
- ...l,
576
+ ...a,
565
577
  type: d,
566
- message: C,
567
- mergeInfo: b,
578
+ message: E,
579
+ mergeInfo: A,
568
580
  checkoutInfo: B,
569
- rebaseInfo: V
581
+ rebaseInfo: X
570
582
  };
571
583
  });
572
- }, Zt = (t) => {
573
- const r = O(t), e = g.resolve(r, ".git"), s = g.resolve(e, "rebase-merge");
574
- if (m.existsSync(s))
575
- return !0;
576
- const o = g.resolve(e, "rebase-apply");
584
+ }, Ee = (t) => {
585
+ const e = $(t), r = l.resolve(e, ".git"), o = l.resolve(r, "rebase-merge");
577
586
  if (m.existsSync(o))
578
587
  return !0;
579
- const n = g.resolve(e, "REBASE_HEAD");
588
+ const s = l.resolve(r, "rebase-apply");
589
+ if (m.existsSync(s))
590
+ return !0;
591
+ const n = l.resolve(r, "REBASE_HEAD");
580
592
  return !!m.existsSync(n);
581
- }, te = ({
593
+ }, _e = ({
582
594
  branchName: t,
583
- version: r,
584
- remoteInfo: e
595
+ version: e,
596
+ remoteInfo: r
585
597
  }) => {
586
- e && (u(`git push ${e.alias} v${r}`, {
598
+ r && (u(`git push ${r.alias} v${e}`, {
587
599
  stdio: "inherit"
588
- }), u(`git push ${e.alias} ${t}`, {
600
+ }), u(`git push ${r.alias} ${t}`, {
589
601
  stdio: "inherit"
590
602
  }));
591
- }, ee = (t) => /^https?:\/\//.test(t), re = (t) => /^git@/.test(t), se = (t) => {
592
- const { hostname: r, pathname: e } = new URL(t);
593
- return `git@${r}:${e.replace("/", "")}`;
594
- }, x = "git@gitee.com:justsosu/done-coding-cli-assets-config.git", St = (t) => `./.DONE_CODING_CLI/CONFIG_TEMP_DIR_FOR_${t}`, Y = (t) => `./assets/${t}`, Ct = (t) => `${Y(t)}/index.json`, oe = async ({
595
- moduleName: t,
596
- onSuccess: r
603
+ }, It = (t) => /^https?:\/\//.test(t), $t = (t) => /^git@/.test(t), Re = (t) => {
604
+ const { hostname: e, pathname: r } = new URL(t);
605
+ return `git@${e}:${r.replace("/", "")}`;
606
+ }, W = ".done-coding", Mt = `${W}/cli/assets-config`, At = "assets", Pt = "index.json", bt = `${W}/config.json`, wt = "https://gitee.com/justsosu/done-coding-cli-assets-config.git", Tt = ({
607
+ dir: t,
608
+ fn: e,
609
+ endClear: r = !0,
610
+ exitClear: o = !0
597
611
  }) => {
598
- console.log(p.blue(`拉取${t}配置,请稍等...`));
599
- const e = St(t), s = g.resolve(
600
- et(),
601
- e
602
- );
603
- if (y(s))
604
- return console.log(
605
- p.red(`${s} 已存在,请手动删除该目录再试`)
606
- ), process.exit(1);
607
- const o = () => {
608
- X(s, { recursive: !0, force: !0 });
612
+ if (V(t))
613
+ return console.log(p.red(`${t} 已存在,请手动删除该目录再试`)), process.exit(1);
614
+ const s = () => {
615
+ console.log("正在清理临时目录...", t), St(t);
609
616
  };
617
+ o && process.once("exit", () => {
618
+ console.log("发现进程退出,正在清理临时目录...", t), s();
619
+ });
610
620
  let n;
611
621
  try {
612
- u(`git clone ${x} ${s} --depth=1`);
613
- const c = Ct(t), i = Y(t), a = g.resolve(
614
- s,
615
- c
616
- );
617
- n = JSON.parse(m.readFileSync(a, "utf-8")), process.once("exit", () => {
618
- y(s) && (console.log("发现进程退出,正在清理临时目录..."), o());
619
- }), await r({
620
- repoUrl: x,
621
- config: n,
622
- cliConfigFileRelativePath: c,
623
- cliConfigDirRelativePath: i,
624
- configTemporaryDir: s
625
- });
626
- } finally {
627
- o();
622
+ n = e(t);
623
+ } catch (c) {
624
+ throw r && s(), c;
628
625
  }
629
- return n;
626
+ return r && (n instanceof Promise ? n.finally(s) : s()), n;
630
627
  };
628
+ var Dt = /* @__PURE__ */ ((t) => (t.ASSETS_CONFIG_REPO_URL = "ASSETS_CONFIG_REPO_URL", t))(Dt || {});
629
+ const Nt = (t) => l.resolve(
630
+ rt(),
631
+ Mt,
632
+ `${t}-${ot()}`
633
+ ), Bt = () => l.resolve(st(), bt), Gt = async () => {
634
+ const t = Bt();
635
+ console.log("读取全局配置:", t);
636
+ const e = {
637
+ ASSETS_CONFIG_REPO_URL: wt
638
+ };
639
+ try {
640
+ if (await N(t)) {
641
+ const r = await K(t, {});
642
+ Object.entries(r).forEach(([o, s]) => {
643
+ e[o] = s;
644
+ });
645
+ }
646
+ } catch {
647
+ }
648
+ return console.log("done-coding-cli 全局配置:", e), e;
649
+ }, Lt = async (t) => {
650
+ if (console.log("资产配置仓库临时目录:", t), await N(t))
651
+ return console.log(
652
+ p.red(`${t} 已存在,请手动删除该目录再试`)
653
+ ), process.exit(1);
654
+ const {
655
+ [
656
+ "ASSETS_CONFIG_REPO_URL"
657
+ /* ASSETS_CONFIG_REPO_URL */
658
+ ]: e
659
+ } = await Gt();
660
+ return $t(e) || It(e) ? (console.log("远程仓库拉取配置...", e), u(`git clone ${e} ${t} --depth=1`)) : (m.mkdirSync(t, { recursive: !0 }), u(`cp -r ${e}/ ${t}/`)), {
661
+ assetConfigRepoUrl: e
662
+ };
663
+ }, Ce = async ({
664
+ moduleName: t,
665
+ onSuccess: e
666
+ }) => (console.log(p.blue(`拉取${t}配置,请稍等...`)), Tt({
667
+ // 资源配置仓库临时文件夹
668
+ dir: Nt(t),
669
+ fn: async (r) => {
670
+ const { assetConfigRepoUrl: o } = await Lt(r), s = l.join(
671
+ At,
672
+ t
673
+ ), n = l.join(
674
+ s,
675
+ Pt
676
+ ), c = l.resolve(r, n), i = await K(c);
677
+ return await e({
678
+ repoUrl: o,
679
+ config: i,
680
+ moduleDirFileRelativePath: s,
681
+ moduleEntryFileRelativePath: n,
682
+ assetsConfigRepoTempDir: r
683
+ }), i;
684
+ }
685
+ }));
631
686
  export {
632
- ot as EditorTypeEnum,
633
- A as GitRefLogTypeEnum,
634
- R as HooksNameEnum,
635
- Vt as SUPPORT_GET_COMMIT_BY_HOOKS_NAMES,
636
- de as _curry,
637
- ue as _get,
638
- pe as _set,
639
- Yt as addHuskyHooks,
640
- Jt as addPackageConfig,
641
- ce as chalk,
642
- Zt as checkCurrentIsRebasing,
643
- Ht as createMainCommand,
644
- Gt as createSubcommand,
645
- jt as decryptAES,
646
- kt as encryptAES,
647
- mt as fileAddX,
648
- Wt as getCommitByHookName,
649
- Nt as getConfigFileCommonOptions,
650
- zt as getCurrentBranchLastCommitList,
651
- Kt as getCurrentBranchName,
652
- nt as getEditorType,
653
- Xt as getGitLastCommitInfo,
654
- O as getGitProjectDir,
655
- Qt as getLastReflogList,
656
- T as getPackageJson,
657
- gt as getRelyPkgVersion,
658
- lt as getRootDirOptions,
659
- xt as getRootScriptName,
660
- Ut as getUseDefaultConfig,
661
- se as http2sshGitUrl,
662
- ft as initConfigFile,
663
- Ft as initHandlerCommon,
664
- ee as isHttpGitUrl,
665
- re as isSshGitUrl,
666
- fe as json5,
667
- f as log,
668
- Bt as lookForParentTarget,
669
- at as openFileInEditor,
670
- te as pushGitPublishInfoToRemote,
671
- oe as readCliConfig,
672
- Lt as readConfigFile,
673
- ut as resolveCheckoutInfoByRefInfo,
674
- K as resolveMergeInfoByCommitMsg,
675
- qt as resolveMergeInfoByGitReflogAction,
676
- Rt as resolveMergeInfoByRefType,
677
- L as xPrompts
687
+ Dt as DoneCodingCliGlobalConfigKeyEnum,
688
+ ct as EditorTypeEnum,
689
+ T as GitRefLogTypeEnum,
690
+ S as HooksNameEnum,
691
+ me as SUPPORT_GET_COMMIT_BY_HOOKS_NAMES,
692
+ Ge as _curry,
693
+ Te as _get,
694
+ Ne as _set,
695
+ ue as addHuskyHooks,
696
+ ae as addPackageConfig,
697
+ Tt as applyUseTempDir,
698
+ V as assetIsExits,
699
+ N as assetIsExitsAsync,
700
+ Ie as chalk,
701
+ Ee as checkCurrentIsRebasing,
702
+ re as createMainCommand,
703
+ se as createSubcommand,
704
+ te as decryptAES,
705
+ Zt as encryptAES,
706
+ dt as fileAddX,
707
+ Nt as getCliModuleTempDir,
708
+ pe as getCommitByHookName,
709
+ oe as getConfigFileCommonOptions,
710
+ Se as getCurrentBranchLastCommitList,
711
+ le as getCurrentBranchName,
712
+ at as getEditorType,
713
+ he as getGitLastCommitInfo,
714
+ $ as getGitProjectDir,
715
+ ye as getLastReflogList,
716
+ D as getPackageJson,
717
+ pt as getRelyPkgVersion,
718
+ ut as getRootDirOptions,
719
+ ee as getRootScriptName,
720
+ ce as getUseDefaultConfig,
721
+ Re as http2sshGitUrl,
722
+ mt as initConfigFile,
723
+ ne as initHandlerCommon,
724
+ It as isHttpGitUrl,
725
+ $t as isSshGitUrl,
726
+ Ae as json5,
727
+ g as log,
728
+ Qt as lookForParentTarget,
729
+ gt as openFileInEditor,
730
+ _e as pushGitPublishInfoToRemote,
731
+ Ce as readCliModuleAssetsConfig,
732
+ ie as readConfigFile,
733
+ yt as readFile,
734
+ Et as readFileAsync,
735
+ ge as readJsonFile,
736
+ K as readJsonFileAsync,
737
+ St as removeAsset,
738
+ fe as removeAssetAsync,
739
+ ht as resolveCheckoutInfoByRefInfo,
740
+ Y as resolveMergeInfoByCommitMsg,
741
+ de as resolveMergeInfoByGitReflogAction,
742
+ vt as resolveMergeInfoByRefType,
743
+ be as uuidv4,
744
+ H as xPrompts
678
745
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-utils",
3
- "version": "0.7.8",
3
+ "version": "0.8.0",
4
4
  "description": "cli utils",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -47,6 +47,7 @@
47
47
  "@types/pinyin": "^2.10.0",
48
48
  "@types/prompts": "^2.4.6",
49
49
  "@types/semver": "^7.5.3",
50
+ "@types/uuid": "^10.0.0",
50
51
  "@types/yargs": "^17.0.28",
51
52
  "rimraf": "^6.0.1",
52
53
  "typescript": "^5.2.2",
@@ -66,7 +67,8 @@
66
67
  "pinyin": "^2.11.2",
67
68
  "prompts": "^2.4.2",
68
69
  "semver": "^7.5.4",
70
+ "uuid": "^11.1.0",
69
71
  "yargs": "^17.7.2"
70
72
  },
71
- "gitHead": "67d4fc202427c5b2f387b856cfe9507127a5b26c"
73
+ "gitHead": "e68f726aa899f75c4d294b11620f343c953a74c3"
72
74
  }
package/types/index.d.ts CHANGED
@@ -15,6 +15,7 @@ import prompts from 'prompts';
15
15
  import { PromptType } from 'prompts';
16
16
  import { ValueOrFunc as PromptValueOrFunc } from 'prompts';
17
17
  import _set from 'lodash.set';
18
+ import { v4 as uuidv4 } from 'uuid';
18
19
  import yargs from 'yargs';
19
20
  import type { Argv as YargsArgv } from 'yargs';
20
21
  import type { Options as YargsOptions } from 'yargs';
@@ -34,8 +35,31 @@ export declare const addPackageConfig: ({ patchConfig, rootDir, }: {
34
35
  rootDir: string;
35
36
  }) => void;
36
37
 
38
+ /**
39
+ * 申请使用临时目录
40
+ * ---
41
+ * !!! 临时目录 默认 执行完成及退出信号发出时 清理临时文件
42
+ */
43
+ export declare const applyUseTempDir: <T>({ dir, fn, endClear, exitClear, }: {
44
+ dir: string;
45
+ fn: (dir: string) => T;
46
+ /** 结束时移除临时目录 */
47
+ endClear?: boolean | undefined;
48
+ /** 退出信号是否移除临时目录 */
49
+ exitClear?: boolean | undefined;
50
+ }) => T;
51
+
37
52
  export { ArgumentsCamelCase }
38
53
 
54
+ /** 文件或文件夹是否存在(同步) */
55
+ export declare const assetIsExits: (assetPath: string) => boolean;
56
+
57
+ /**
58
+ * 检查路径是否存在(包括文件、目录、符号链接)
59
+ * 异步版本,行为与 fs.existsSync 一致
60
+ */
61
+ export declare const assetIsExitsAsync: (path: string) => Promise<boolean>;
62
+
39
63
  export { chalk }
40
64
 
41
65
  /** 检测当前正在变基 */
@@ -100,6 +124,22 @@ export declare function decryptAES({ encryptedText, secretKey, }: {
100
124
  secretKey: string;
101
125
  }): string;
102
126
 
127
+ /** done-coding-cli 全局配置 */
128
+ export declare type DoneCodingCliGlobalConfig = {
129
+ [K in DoneCodingCliGlobalConfigKeyEnum]: string;
130
+ };
131
+
132
+ /** done-coding-cli 全局配置 key 枚举 */
133
+ export declare enum DoneCodingCliGlobalConfigKeyEnum {
134
+ /**
135
+ * 资产配置仓库
136
+ * ---
137
+ * 1. http ssh则认为远程仓库 临时拉取到本地临时目录中
138
+ * 2. 若非上述 则认为本地【绝对】路径
139
+ */
140
+ ASSETS_CONFIG_REPO_URL = "ASSETS_CONFIG_REPO_URL"
141
+ }
142
+
103
143
  /** 编辑器类型枚举 */
104
144
  export declare enum EditorTypeEnum {
105
145
  /** vscode */
@@ -121,6 +161,9 @@ export declare const fileAddX: (filePath: string) => void;
121
161
 
122
162
  export { _get }
123
163
 
164
+ /** 获取cli模块【临时】目录[绝对路径] */
165
+ export declare const getCliModuleTempDir: (moduleName: string) => string;
166
+
124
167
  /** 根据hookName获取(将)提交的信息 */
125
168
  export declare const getCommitByHookName: ({ hookName, rootDir, }: {
126
169
  hookName: SupportGetCommitByHookName;
@@ -470,19 +513,24 @@ export declare const pushGitPublishInfoToRemote: ({ branchName, version, remoteI
470
513
  remoteInfo?: GitRemoteInfo | undefined;
471
514
  }) => void;
472
515
 
473
- /** 读取配置 */
474
- export declare const readCliConfig: <R>({ moduleName, onSuccess, }: {
516
+ /** 读取(某个模块)配置 */
517
+ export declare const readCliModuleAssetsConfig: <R>({ moduleName, onSuccess, }: {
475
518
  moduleName: string;
476
519
  onSuccess: (params: {
520
+ /**
521
+ * 资产配置仓库地址
522
+ * ----
523
+ * 可能是 http ssh 也可能是本地【绝对】文件路径
524
+ */
477
525
  repoUrl: string;
478
- /** 配置文件相对路径 */
479
- cliConfigFileRelativePath: string;
480
- /** 配置文件目录相对路径 */
481
- cliConfigDirRelativePath: string;
526
+ /** 资产配置文件临时目录[绝对路径] */
527
+ assetsConfigRepoTempDir: string;
528
+ /** 模块对应的资产配置仓库(相对路径) */
529
+ moduleDirFileRelativePath: string;
530
+ /** 模块对应的资产配置入口文件(相对路径) */
531
+ moduleEntryFileRelativePath: string;
482
532
  /** 配置文件内容 */
483
533
  config: R;
484
- /** 配置临时目录 */
485
- configTemporaryDir: string;
486
534
  }) => void | Promise<void>;
487
535
  }) => Promise<R>;
488
536
 
@@ -492,6 +540,32 @@ export declare const readConfigFile: <T>(options: ReadConfigFileOptions, onNotEx
492
540
  /** 读取配置文件选项 */
493
541
  export declare type ReadConfigFileOptions = ConfigFileCommonOptions;
494
542
 
543
+ /** 读取文件[同步] */
544
+ export declare const readFile: (assetPath: string) => string;
545
+
546
+ /** 读取文件[异步] */
547
+ export declare const readFileAsync: (assetPath: string) => Promise<string>;
548
+
549
+ /** 读取json文件[同步] */
550
+ export declare const readJsonFile: <T>(assetPath: string, defaultValue?: T | undefined) => T;
551
+
552
+ /** 读取json文件[异步] */
553
+ export declare const readJsonFileAsync: <T>(assetPath: string, defaultValue?: T | undefined) => Promise<T>;
554
+
555
+ /**
556
+ * 删除资源 (同步)
557
+ * ---
558
+ * 无论文件还是文件夹
559
+ */
560
+ export declare const removeAsset: (assetPath: string, force?: boolean) => void;
561
+
562
+ /**
563
+ * 删除资源 (异步)
564
+ * ---
565
+ * 无论文件还是文件夹
566
+ */
567
+ export declare const removeAssetAsync: (assetPath: string, force?: boolean) => Promise<void>;
568
+
495
569
  /** 解析checkoutInfo */
496
570
  export declare const resolveCheckoutInfoByRefInfo: (message: string) => {
497
571
  fromBranch: string;
@@ -520,6 +594,8 @@ export declare const SUPPORT_GET_COMMIT_BY_HOOKS_NAMES: readonly [HooksNameEnum.
520
594
 
521
595
  export declare type SupportGetCommitByHookName = (typeof SUPPORT_GET_COMMIT_BY_HOOKS_NAMES)[number];
522
596
 
597
+ export { uuidv4 }
598
+
523
599
  /** prompts 拓展 */
524
600
  export declare const xPrompts: <T extends string = string>(questions: prompts.PromptObject<T> | prompts.PromptObject<T>[], options?: prompts.Options | undefined) => Promise<prompts.Answers<T>>;
525
601