@done-coding/cli-utils 0.7.6 → 0.7.8

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,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import p from "chalk";
3
- import { default as se } from "chalk";
3
+ import { default as ce } from "chalk";
4
4
  import g from "node:path";
5
5
  import m, { existsSync as y, mkdirSync as W, writeFileSync as D, readFileSync as v, rmSync as X } from "node:fs";
6
6
  import _ from "crypto";
@@ -10,29 +10,29 @@ import { hideBin as Q } from "yargs/helpers";
10
10
  import { execSync as u } from "node:child_process";
11
11
  import H from "json5";
12
12
  export * from "json5";
13
- import { default as ce } from "json5";
13
+ import { default as fe } from "json5";
14
14
  import Z from "lodash.merge";
15
15
  import tt from "semver";
16
16
  import { tmpdir as et } from "node:os";
17
- import { default as fe } from "lodash.get";
18
- import { default as ge } from "lodash.set";
19
- import { default as me } from "lodash.curry";
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
20
  import E from "pinyin";
21
- const l = Object.assign(
21
+ const f = Object.assign(
22
22
  (t, ...r) => console.log(...r.map((e) => p[t](e))),
23
23
  {
24
24
  /** 成功 */
25
- success: (...t) => l("green", ...t),
25
+ success: (...t) => f("green", ...t),
26
26
  /** /步骤 */
27
- stage: (...t) => l("blue", ...t),
27
+ stage: (...t) => f("blue", ...t),
28
28
  /** 提示信息 */
29
- info: (...t) => l("cyan", ...t),
29
+ info: (...t) => f("cyan", ...t),
30
30
  /** 警告 */
31
- warn: (...t) => l("yellow", ...t),
31
+ warn: (...t) => f("yellow", ...t),
32
32
  /** 错误 */
33
- error: (...t) => l("red", ...t),
33
+ error: (...t) => f("red", ...t),
34
34
  /** 跳过 */
35
- skip: (...t) => l("gray", ...t)
35
+ skip: (...t) => f("gray", ...t)
36
36
  }
37
37
  ), Bt = (t, {
38
38
  /** 当前目录 */
@@ -40,14 +40,14 @@ const l = Object.assign(
40
40
  /** 优先找最远的父目录 */
41
41
  isFindFarthest: e = !0
42
42
  } = {}) => {
43
- const o = g.resolve(r).split(g.sep).map((s, n, c) => c.slice(0, n).concat(s).join(g.sep) || g.sep);
44
- for (; o.length; ) {
45
- const s = e ? o.shift() : o.pop(), n = g.join(s, t);
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);
46
46
  if (m.existsSync(n))
47
- return s;
47
+ return o;
48
48
  }
49
- }, N = "aes-256-cbc", F = 16, M = "hex", w = ":";
50
- function G(t) {
49
+ }, G = "aes-256-cbc", N = 16, M = "hex", w = ":";
50
+ function F(t) {
51
51
  return _.pbkdf2Sync(
52
52
  t,
53
53
  "done-coding-cli-salt",
@@ -64,13 +64,13 @@ function kt({
64
64
  secretKey: r
65
65
  }) {
66
66
  try {
67
- const e = G(r), o = _.randomBytes(F), s = _.createCipheriv(N, e, o);
68
- let n = s.update(t);
69
- n = Buffer.concat([n, s.final()]);
70
- const c = o.toString(M), i = n.toString(M);
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);
71
71
  return `${c}${w}${i}`;
72
72
  } catch (e) {
73
- return l.error(
73
+ return f.error(
74
74
  `加密失败: ${e instanceof Error ? e.message : String(e)}`
75
75
  ), "";
76
76
  }
@@ -82,14 +82,14 @@ function jt({
82
82
  try {
83
83
  if (!t.includes(w))
84
84
  return "";
85
- const e = G(r), [o, s] = t.split(w);
86
- if (o.length !== F * 2)
85
+ const e = F(r), [s, o] = t.split(w);
86
+ if (s.length !== N * 2)
87
87
  return "";
88
- const n = Buffer.from(o, M), c = Buffer.from(s, M), i = _.createDecipheriv(N, e, n);
88
+ const n = Buffer.from(s, M), c = Buffer.from(o, M), i = _.createDecipheriv(G, e, n);
89
89
  let a = i.update(c);
90
90
  return a = Buffer.concat([a, i.final()]), a.toString();
91
91
  } catch (e) {
92
- return l.error(
92
+ return f.error(
93
93
  `解密失败: ${e instanceof Error ? e.message : String(e)}`
94
94
  ), "";
95
95
  }
@@ -97,14 +97,14 @@ function jt({
97
97
  const L = (...t) => {
98
98
  const [r, e = {}] = t;
99
99
  return q(r, {
100
- onCancel(o) {
101
- return l.error(`退出${o == null ? void 0 : o.name}输入`), process.exit(1);
100
+ onCancel(s) {
101
+ return f.error(`退出${s == null ? void 0 : s.name}输入`), process.exit(1);
102
102
  },
103
103
  ...e
104
104
  });
105
105
  }, rt = (t, r) => {
106
- t ? l.error(t) : l.error(r.message), r != null && r.stack && l.error(r.stack), process.exit(1);
107
- }, ot = () => {
106
+ t ? f.error(t) : f.error(r.message), r != null && r.stack && f.error(r.stack), process.exit(1);
107
+ }, st = () => {
108
108
  const t = Q(process.argv);
109
109
  return z(t);
110
110
  }, xt = ({
@@ -115,49 +115,49 @@ const L = (...t) => {
115
115
  return t;
116
116
  if (!r)
117
117
  return;
118
- const { bin: e, name: o } = r;
118
+ const { bin: e, name: s } = r;
119
119
  if (e) {
120
120
  if (typeof e == "string")
121
- return o.includes("/") ? void 0 : o;
121
+ return s.includes("/") ? void 0 : s;
122
122
  if (typeof e == "object") {
123
- const s = Object.entries(e), n = process.argv[1], c = s.filter(([, a]) => n == null ? void 0 : n.endsWith(a));
123
+ const o = Object.entries(e), n = process.argv[1], c = o.filter(([, a]) => n == null ? void 0 : n.endsWith(a));
124
124
  if (c.length !== 1)
125
125
  return;
126
126
  const [i] = c[0];
127
127
  return process.platform === "win32" ? i.toLowerCase() : i;
128
128
  }
129
129
  }
130
- }, J = (t, {
130
+ }, U = (t, {
131
131
  usage: r,
132
132
  version: e,
133
- demandCommandCount: o,
134
- options: s,
133
+ demandCommandCount: s,
134
+ options: o,
135
135
  positionals: n,
136
136
  subcommands: c,
137
137
  rootScriptName: i
138
138
  }, a) => {
139
- let f = t.strict();
140
- r && (f = f.usage(`Usage: ${r}`)), o && (f = f.demandCommand(o));
139
+ let l = t.strict();
140
+ r && (l = l.usage(`Usage: ${r}`)), s && (l = l.demandCommand(s));
141
141
  const h = "help";
142
- return f = f.help(h), e ? f = f.version(e).alias("h", h).alias("v", "version") : f = f.alias("h", h), s && (f = f.options(s)), n && (f = Object.entries(n).reduce((S, [P, d]) => S.positional(P, d), f)), c && (f = f.command(c)), a && i && (f = f.scriptName(i)), f;
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
143
  }, Ht = async ({ handler: t, ...r }) => {
144
- const e = await J(ot(), r, !0).fail(
144
+ const e = await U(st(), r, !0).fail(
145
145
  rt
146
146
  ).argv;
147
147
  return t ? t(e) : e;
148
- }, Nt = (t) => {
149
- const { command: r, describe: e, handler: o = () => {
150
- }, ...s } = t;
148
+ }, Gt = (t) => {
149
+ const { command: r, describe: e, handler: s = () => {
150
+ }, ...o } = t;
151
151
  return {
152
152
  command: r,
153
153
  describe: e,
154
154
  builder(n) {
155
- return J(n, s, !1);
155
+ return U(n, o, !1);
156
156
  },
157
- handler: o
157
+ handler: s
158
158
  };
159
159
  };
160
- var st = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(st || {});
160
+ var ot = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(ot || {});
161
161
  const nt = async () => {
162
162
  const { editorType: t } = await L([
163
163
  {
@@ -186,22 +186,22 @@ const nt = async () => {
186
186
  e();
187
187
  }
188
188
  }, at = (t, r) => {
189
- const e = (o) => l.info(`
190
- ${o}, 请用编辑器打开 ${t} 进行编辑
189
+ const e = (s) => f.info(`
190
+ ${s}, 请用编辑器打开 ${t} 进行编辑
191
191
  `);
192
192
  switch (r) {
193
193
  case "Cursor":
194
194
  case "VsCode": {
195
- const o = it[r];
196
- ct(o, t, () => {
197
- e(`${o}命令未安装`);
195
+ const s = it[r];
196
+ ct(s, t, () => {
197
+ e(`${s}命令未安装`);
198
198
  });
199
199
  break;
200
200
  }
201
201
  default:
202
202
  e("其他编辑器");
203
203
  }
204
- }, ft = (t = process.cwd()) => ({
204
+ }, lt = (t = process.cwd()) => ({
205
205
  /** 必须保留 */
206
206
  rootDir: {
207
207
  type: "string",
@@ -210,12 +210,12 @@ const nt = async () => {
210
210
  /** 必须设置默认值 */
211
211
  default: t
212
212
  }
213
- }), Ft = ({
213
+ }), Nt = ({
214
214
  configPathDefault: t,
215
215
  rootDirDefault: r
216
216
  }) => ({
217
217
  /** 必须保留 */
218
- ...ft(r),
218
+ ...lt(r),
219
219
  /** 必须保留 */
220
220
  configPath: {
221
221
  type: "string",
@@ -224,30 +224,30 @@ const nt = async () => {
224
224
  /** 必须设置默认值 */
225
225
  default: t
226
226
  }
227
- }), lt = async (t, r) => {
228
- const { configPath: e, rootDir: o } = r, s = g.resolve(o, e), n = g.dirname(s);
227
+ }), ft = async (t, r) => {
228
+ const { configPath: e, rootDir: s } = r, o = g.resolve(s, e), n = g.dirname(o);
229
229
  return y(n) || W(n, {
230
230
  recursive: !0
231
- }), s.endsWith(".json5") ? (l.info(`json5模式写入 ${s}`), D(s, H.stringify(t, null, 2)), s) : (l.info(`json模式写入 ${s}`), D(s, JSON.stringify(t, null, 2)), s);
232
- }, Gt = async (t, r, {
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
233
  onFileGenerated: e,
234
- edit: o = !1
234
+ edit: s = !1
235
235
  } = {}) => {
236
- const s = await lt(t, r);
237
- if (e == null || e(s), o) {
236
+ const o = await ft(t, r);
237
+ if (e == null || e(o), s) {
238
238
  const n = await nt();
239
239
  at(r.configPath, n);
240
240
  }
241
241
  }, Lt = async (t, r) => {
242
- const { configPath: e, rootDir: o } = t, s = g.resolve(o, e);
243
- if (!y(s)) {
242
+ const { configPath: e, rootDir: s } = t, o = g.resolve(s, e);
243
+ if (!y(o)) {
244
244
  if (r)
245
- return l.info("配置文件不存在,使用onNotExists返回值"), r();
246
- const n = `配置文件不存在 ${s}`;
245
+ return f.info("配置文件不存在,使用onNotExists返回值"), r();
246
+ const n = `配置文件不存在 ${o}`;
247
247
  throw new Error(n);
248
248
  }
249
- return s.endsWith(".json5") ? (l.info(`json5模式解析 ${s}`), H.parse(v(s, "utf8"))) : (l.info(`json模式解析 ${s}`), JSON.parse(v(s, "utf8")));
250
- }, Jt = async () => {
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
251
  const { useDefaultConfig: t } = await L({
252
252
  name: "useDefaultConfig",
253
253
  type: "confirm",
@@ -255,10 +255,10 @@ const nt = async () => {
255
255
  initial: !0
256
256
  });
257
257
  return t;
258
- }, U = "package.json", T = ({
258
+ }, J = "package.json", T = ({
259
259
  rootDir: t
260
260
  }) => {
261
- const r = g.resolve(t, U);
261
+ const r = g.resolve(t, J);
262
262
  if (!y(r))
263
263
  throw new Error(`${t}未找到package.json文件`);
264
264
  const e = v(r, "utf-8");
@@ -267,28 +267,28 @@ const nt = async () => {
267
267
  rootDir: t,
268
268
  pkgJson: r,
269
269
  pkgName: e,
270
- isDevPkg: o
270
+ isDevPkg: s
271
271
  }) => {
272
- const s = r || T({ rootDir: t }), n = o ? s.devDependencies : s.dependencies;
272
+ const o = r || T({ rootDir: t }), n = s ? o.devDependencies : o.dependencies;
273
273
  let c = n == null ? void 0 : n[e];
274
274
  if (!c) {
275
- const i = o ? s.dependencies : s.devDependencies;
275
+ const i = s ? o.dependencies : o.devDependencies;
276
276
  c = i == null ? void 0 : i[e], c && console.log(
277
277
  p.yellow(
278
- `${o ? "开发" : "生产"}依赖包${e}可能错误的安装在${o ? "dependencies" : "devDependencies"}`
278
+ `${s ? "开发" : "生产"}依赖包${e}可能错误的安装在${s ? "dependencies" : "devDependencies"}`
279
279
  )
280
280
  );
281
281
  return;
282
282
  }
283
283
  return c || console.log(p.cyan(`依赖包${e}未安装`)), c;
284
- }, Ut = ({
284
+ }, Jt = ({
285
285
  patchConfig: t,
286
286
  rootDir: r
287
287
  }) => {
288
288
  if (!t)
289
289
  return;
290
- const e = T({ rootDir: r }), o = Z(e, t), s = g.resolve(r, U);
291
- D(s, JSON.stringify(o, null, 2), "utf-8");
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
292
  }, O = (t) => {
293
293
  const e = u("git rev-parse --show-toplevel", {
294
294
  cwd: t
@@ -306,7 +306,7 @@ const nt = async () => {
306
306
  } catch {
307
307
  try {
308
308
  const e = u("git rev-parse --short HEAD").toString().trim();
309
- l.skip(`当前未指向具体某个分支, 当前commit hash: ${e}`);
309
+ f.skip(`当前未指向具体某个分支, 当前commit hash: ${e}`);
310
310
  } finally {
311
311
  return;
312
312
  }
@@ -314,10 +314,10 @@ const nt = async () => {
314
314
  }, ut = (t) => {
315
315
  const r = t.match(/moving\s+from\s+(.*)\s+to\s+(.*)/);
316
316
  if (r) {
317
- const [, e, o] = r;
317
+ const [, e, s] = r;
318
318
  return {
319
319
  fromBranch: e.trim(),
320
- toBranch: o.trim()
320
+ toBranch: s.trim()
321
321
  };
322
322
  }
323
323
  }, I = 73, mt = (t) => {
@@ -325,8 +325,8 @@ const nt = async () => {
325
325
  if ((e & I) === I)
326
326
  return;
327
327
  console.log(p.blue(`${t} 没有执行权限 添加... `));
328
- const o = e | I;
329
- m.chmodSync(t, o), console.log(p.green(`${t} 添加执行权限成功`));
328
+ const s = e | I;
329
+ m.chmodSync(t, s), console.log(p.green(`${t} 添加执行权限成功`));
330
330
  };
331
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
332
  const pt = "husky", ht = ".husky", dt = ({ rootDir: t }) => {
@@ -338,9 +338,9 @@ const pt = "husky", ht = ".husky", dt = ({ rootDir: t }) => {
338
338
  });
339
339
  if (!e)
340
340
  throw new Error("husky版本获取失败, 可能husky未安装");
341
- const o = e.replace(/^(\^|~)/, ""), s = "<9.0.0";
342
- return tt.satisfies(o, s) ? (console.log(p.cyan(`${o}符合${s}`)), `#!/usr/bin/env sh
343
- . "$(dirname -- "$0")/_/husky.sh"`) : (console.log(p.cyan(`${o}不符合${s}`)), "");
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
344
  }, yt = ({ rootDir: t }) => {
345
345
  const r = O(t);
346
346
  return g.resolve(r, ht);
@@ -349,19 +349,19 @@ const pt = "husky", ht = ".husky", dt = ({ rootDir: t }) => {
349
349
  rootDir: r,
350
350
  getCode: e
351
351
  }) => {
352
- const o = yt({ rootDir: r });
353
- m.existsSync(o) || m.mkdirSync(o, { recursive: !0 }), t.forEach((s) => {
354
- const n = g.resolve(o, s), c = m.existsSync(n);
355
- let i = e(s);
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);
356
356
  if (c)
357
357
  m.readFileSync(n, "utf-8").includes(i) ? console.log(
358
- p.gray(`${n} ${s}相关调用 ${i} 已存在 跳过`)
358
+ p.gray(`${n} ${o}相关调用 ${i} 已存在 跳过`)
359
359
  ) : (m.appendFileSync(
360
360
  n,
361
361
  `
362
362
  ${i}
363
363
  `
364
- ), console.log(p.green(`${n} 添加 ${s}相关调用成功`)));
364
+ ), console.log(p.green(`${n} 添加 ${o}相关调用成功`)));
365
365
  else {
366
366
  const a = dt({
367
367
  rootDir: r
@@ -373,7 +373,7 @@ ${i}
373
373
  ${i}
374
374
  `,
375
375
  "utf-8"
376
- ), console.log(p.green(`${n} 添加 ${s}相关调用成功`));
376
+ ), console.log(p.green(`${n} 添加 ${o}相关调用成功`));
377
377
  }
378
378
  mt(n);
379
379
  });
@@ -385,13 +385,13 @@ ${i}
385
385
  hookName: t,
386
386
  rootDir: r
387
387
  }) => {
388
- const e = O(r), o = g.resolve(e, ".git");
388
+ const e = O(r), s = g.resolve(e, ".git");
389
389
  switch (t) {
390
390
  case R.PREPARE_COMMIT_MSG:
391
391
  case R.COMMIT_MSG: {
392
- const s = g.resolve(o, "MERGE_MSG");
393
- if (y(s))
394
- return v(s, "utf-8");
392
+ const o = g.resolve(s, "MERGE_MSG");
393
+ if (y(o))
394
+ return v(o, "utf-8");
395
395
  }
396
396
  }
397
397
  return "";
@@ -399,12 +399,12 @@ ${i}
399
399
  remoteAlias: t = "origin"
400
400
  } = {}) => {
401
401
  try {
402
- const r = u("git rev-parse HEAD").toString().trim(), e = 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();
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
403
  let a = "";
404
404
  try {
405
405
  a = u(`git config --get remote.${t}.url`).toString().trim();
406
406
  } catch {
407
- l.warn("git远程仓库地址获取失败或者不存在");
407
+ f.warn("git远程仓库地址获取失败或者不存在");
408
408
  }
409
409
  return {
410
410
  lastHash: r,
@@ -413,8 +413,8 @@ ${i}
413
413
  style: E.STYLE_NORMAL,
414
414
  heteronym: !1
415
415
  }).join(""),
416
- lastCommitEmail: o,
417
- lastCommitMsg: s,
416
+ lastCommitEmail: s,
417
+ lastCommitMsg: o,
418
418
  userName: n,
419
419
  userNamePinYin: E(n, {
420
420
  style: E.STYLE_NORMAL,
@@ -428,7 +428,7 @@ ${i}
428
428
  } : void 0
429
429
  };
430
430
  } catch (r) {
431
- throw l.error("获取git最后提交信息失败"), r;
431
+ throw f.error("获取git最后提交信息失败"), r;
432
432
  }
433
433
  }, K = (t = "") => {
434
434
  const r = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+into\s+['|"](.+)['|"]\s*/i, e = t.match(r);
@@ -439,9 +439,9 @@ ${i}
439
439
  toBranch: a
440
440
  };
441
441
  }
442
- const o = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+of\s+.+\s+into\s+['|"](.+)['|"]\s*/i, s = t.match(o);
443
- if (s) {
444
- const [, i, a] = s;
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;
445
445
  return {
446
446
  fromBranch: i,
447
447
  toBranch: a
@@ -470,9 +470,9 @@ ${i}
470
470
  fromBranch: n
471
471
  };
472
472
  }
473
- const o = /pull\s+([^\s]+)\s+([^\s]+)/, s = t.match(o);
474
- if (s) {
475
- const [, , n] = s;
473
+ const s = /pull\s+([^\s]+)\s+([^\s]+)/, o = t.match(s);
474
+ if (o) {
475
+ const [, , n] = o;
476
476
  return {
477
477
  fromBranch: n
478
478
  };
@@ -539,7 +539,7 @@ const j = "__GIT_REPLACE_MARK__", $ = {
539
539
  )}"`
540
540
  ).toString().split(`
541
541
  `).map((i) => $.parse(i)).filter(r).map((i) => {
542
- const { fullMessage: a, ...f } = i, h = ":", [S] = a.split(h, 1), P = a.slice(`${S}${h}`.length), d = S.trim(), C = P.trim();
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
543
  let b, B, V;
544
544
  if (d.startsWith(
545
545
  "checkout"
@@ -556,12 +556,12 @@ const j = "__GIT_REPLACE_MARK__", $ = {
556
556
  /* COMMIT_MERGE */
557
557
  )) {
558
558
  const k = K(C);
559
- k || l.warn(
559
+ k || f.warn(
560
560
  `${i.hash} 是合并提交 但是未从提交信息(${C})中检测到合并分支信息,推测手动更改了提交内容`
561
561
  ), b = k;
562
562
  }
563
563
  return {
564
- ...f,
564
+ ...l,
565
565
  type: d,
566
566
  message: C,
567
567
  mergeInfo: b,
@@ -570,12 +570,12 @@ const j = "__GIT_REPLACE_MARK__", $ = {
570
570
  };
571
571
  });
572
572
  }, Zt = (t) => {
573
- const r = O(t), e = g.resolve(r, ".git"), o = g.resolve(e, "rebase-merge");
574
- if (m.existsSync(o))
575
- return !0;
576
- const s = g.resolve(e, "rebase-apply");
573
+ const r = O(t), e = g.resolve(r, ".git"), s = g.resolve(e, "rebase-merge");
577
574
  if (m.existsSync(s))
578
575
  return !0;
576
+ const o = g.resolve(e, "rebase-apply");
577
+ if (m.existsSync(o))
578
+ return !0;
579
579
  const n = g.resolve(e, "REBASE_HEAD");
580
580
  return !!m.existsSync(n);
581
581
  }, te = ({
@@ -588,62 +588,65 @@ const j = "__GIT_REPLACE_MARK__", $ = {
588
588
  }), u(`git push ${e.alias} ${t}`, {
589
589
  stdio: "inherit"
590
590
  }));
591
- }, 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`, ee = async ({
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 ({
592
595
  moduleName: t,
593
596
  onSuccess: r
594
597
  }) => {
595
598
  console.log(p.blue(`拉取${t}配置,请稍等...`));
596
- const e = St(t), o = g.resolve(
599
+ const e = St(t), s = g.resolve(
597
600
  et(),
598
601
  e
599
602
  );
600
- if (y(o))
603
+ if (y(s))
601
604
  return console.log(
602
- p.red(`${o} 已存在,请手动删除该目录再试`)
605
+ p.red(`${s} 已存在,请手动删除该目录再试`)
603
606
  ), process.exit(1);
604
- const s = () => {
605
- X(o, { recursive: !0, force: !0 });
607
+ const o = () => {
608
+ X(s, { recursive: !0, force: !0 });
606
609
  };
607
610
  let n;
608
611
  try {
609
- u(`git clone ${x} ${o} --depth=1`);
612
+ u(`git clone ${x} ${s} --depth=1`);
610
613
  const c = Ct(t), i = Y(t), a = g.resolve(
611
- o,
614
+ s,
612
615
  c
613
616
  );
614
617
  n = JSON.parse(m.readFileSync(a, "utf-8")), process.once("exit", () => {
615
- y(o) && (console.log("发现进程退出,正在清理临时目录..."), s());
618
+ y(s) && (console.log("发现进程退出,正在清理临时目录..."), o());
616
619
  }), await r({
617
620
  repoUrl: x,
618
621
  config: n,
619
622
  cliConfigFileRelativePath: c,
620
623
  cliConfigDirRelativePath: i,
621
- configTemporaryDir: o
624
+ configTemporaryDir: s
622
625
  });
623
626
  } finally {
624
- s();
627
+ o();
625
628
  }
626
629
  return n;
627
630
  };
628
631
  export {
629
- st as EditorTypeEnum,
632
+ ot as EditorTypeEnum,
630
633
  A as GitRefLogTypeEnum,
631
634
  R as HooksNameEnum,
632
635
  Vt as SUPPORT_GET_COMMIT_BY_HOOKS_NAMES,
633
- me as _curry,
634
- fe as _get,
635
- ge as _set,
636
+ de as _curry,
637
+ ue as _get,
638
+ pe as _set,
636
639
  Yt as addHuskyHooks,
637
- Ut as addPackageConfig,
638
- se as chalk,
640
+ Jt as addPackageConfig,
641
+ ce as chalk,
639
642
  Zt as checkCurrentIsRebasing,
640
643
  Ht as createMainCommand,
641
- Nt as createSubcommand,
644
+ Gt as createSubcommand,
642
645
  jt as decryptAES,
643
646
  kt as encryptAES,
644
647
  mt as fileAddX,
645
648
  Wt as getCommitByHookName,
646
- Ft as getConfigFileCommonOptions,
649
+ Nt as getConfigFileCommonOptions,
647
650
  zt as getCurrentBranchLastCommitList,
648
651
  Kt as getCurrentBranchName,
649
652
  nt as getEditorType,
@@ -652,17 +655,20 @@ export {
652
655
  Qt as getLastReflogList,
653
656
  T as getPackageJson,
654
657
  gt as getRelyPkgVersion,
655
- ft as getRootDirOptions,
658
+ lt as getRootDirOptions,
656
659
  xt as getRootScriptName,
657
- Jt as getUseDefaultConfig,
658
- lt as initConfigFile,
659
- Gt as initHandlerCommon,
660
- ce as json5,
661
- l as log,
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,
662
668
  Bt as lookForParentTarget,
663
669
  at as openFileInEditor,
664
670
  te as pushGitPublishInfoToRemote,
665
- ee as readCliConfig,
671
+ oe as readCliConfig,
666
672
  Lt as readConfigFile,
667
673
  ut as resolveCheckoutInfoByRefInfo,
668
674
  K as resolveMergeInfoByCommitMsg,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-utils",
3
- "version": "0.7.6",
3
+ "version": "0.7.8",
4
4
  "description": "cli utils",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "https://gitee.com/justsosu/done-coding-cli.git",
30
+ "url": "https://gitee.com/done-coding/done-coding-cli.git",
31
31
  "directory": "packages/utils"
32
32
  },
33
33
  "publishConfig": {
@@ -68,5 +68,5 @@
68
68
  "semver": "^7.5.4",
69
69
  "yargs": "^17.7.2"
70
70
  },
71
- "gitHead": "30721548bad7e10aaf8bf46762925954f40c5fd3"
71
+ "gitHead": "67d4fc202427c5b2f387b856cfe9507127a5b26c"
72
72
  }
package/types/index.d.ts CHANGED
@@ -366,6 +366,9 @@ export declare enum HooksNameEnum {
366
366
  PRE_PUSH = "pre-push"
367
367
  }
368
368
 
369
+ /** http 地址 转换为 ssh 地址 */
370
+ export declare const http2sshGitUrl: (httpUrl: string) => string;
371
+
369
372
  /** 初始化配置文件 */
370
373
  export declare const initConfigFile: <T>(content: T, argv: CliHandlerArgv<InitConfigFileOptions>) => Promise<string>;
371
374
 
@@ -379,6 +382,12 @@ export declare const initHandlerCommon: <T>(content: T, argv: CliHandlerArgv<Ini
379
382
  edit?: boolean | undefined;
380
383
  }) => Promise<void>;
381
384
 
385
+ /** 是http git地址 */
386
+ export declare const isHttpGitUrl: (url: string) => boolean;
387
+
388
+ /** 是 ssh git地址 */
389
+ export declare const isSshGitUrl: (url: string) => boolean;
390
+
382
391
  export { json5 }
383
392
 
384
393
  /** 日志 */
@@ -512,7 +521,7 @@ export declare const SUPPORT_GET_COMMIT_BY_HOOKS_NAMES: readonly [HooksNameEnum.
512
521
  export declare type SupportGetCommitByHookName = (typeof SUPPORT_GET_COMMIT_BY_HOOKS_NAMES)[number];
513
522
 
514
523
  /** prompts 拓展 */
515
- export declare const xPrompts: (questions: prompts.PromptObject<string> | prompts.PromptObject<string>[], options?: prompts.Options | undefined) => Promise<prompts.Answers<string>>;
524
+ export declare const xPrompts: <T extends string = string>(questions: prompts.PromptObject<T> | prompts.PromptObject<T>[], options?: prompts.Options | undefined) => Promise<prompts.Answers<T>>;
516
525
 
517
526
  export { YargsArgv }
518
527