@done-coding/cli-utils 0.7.7 → 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 +146 -140
- package/package.json +2 -2
- package/types/index.d.ts +10 -1
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
|
|
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
|
|
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
|
|
18
|
-
import { default as
|
|
19
|
-
import { default as
|
|
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
|
|
21
|
+
const f = Object.assign(
|
|
22
22
|
(t, ...r) => console.log(...r.map((e) => p[t](e))),
|
|
23
23
|
{
|
|
24
24
|
/** 成功 */
|
|
25
|
-
success: (...t) =>
|
|
25
|
+
success: (...t) => f("green", ...t),
|
|
26
26
|
/** /步骤 */
|
|
27
|
-
stage: (...t) =>
|
|
27
|
+
stage: (...t) => f("blue", ...t),
|
|
28
28
|
/** 提示信息 */
|
|
29
|
-
info: (...t) =>
|
|
29
|
+
info: (...t) => f("cyan", ...t),
|
|
30
30
|
/** 警告 */
|
|
31
|
-
warn: (...t) =>
|
|
31
|
+
warn: (...t) => f("yellow", ...t),
|
|
32
32
|
/** 错误 */
|
|
33
|
-
error: (...t) =>
|
|
33
|
+
error: (...t) => f("red", ...t),
|
|
34
34
|
/** 跳过 */
|
|
35
|
-
skip: (...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
|
|
44
|
-
for (;
|
|
45
|
-
const
|
|
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
|
|
47
|
+
return o;
|
|
48
48
|
}
|
|
49
|
-
},
|
|
50
|
-
function
|
|
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 =
|
|
68
|
-
let n =
|
|
69
|
-
n = Buffer.concat([n,
|
|
70
|
-
const c =
|
|
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
|
|
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 =
|
|
86
|
-
if (
|
|
85
|
+
const e = F(r), [s, o] = t.split(w);
|
|
86
|
+
if (s.length !== N * 2)
|
|
87
87
|
return "";
|
|
88
|
-
const n = Buffer.from(
|
|
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
|
|
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(
|
|
101
|
-
return
|
|
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 ?
|
|
107
|
-
},
|
|
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:
|
|
118
|
+
const { bin: e, name: s } = r;
|
|
119
119
|
if (e) {
|
|
120
120
|
if (typeof e == "string")
|
|
121
|
-
return
|
|
121
|
+
return s.includes("/") ? void 0 : s;
|
|
122
122
|
if (typeof e == "object") {
|
|
123
|
-
const
|
|
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
|
-
},
|
|
130
|
+
}, U = (t, {
|
|
131
131
|
usage: r,
|
|
132
132
|
version: e,
|
|
133
|
-
demandCommandCount:
|
|
134
|
-
options:
|
|
133
|
+
demandCommandCount: s,
|
|
134
|
+
options: o,
|
|
135
135
|
positionals: n,
|
|
136
136
|
subcommands: c,
|
|
137
137
|
rootScriptName: i
|
|
138
138
|
}, a) => {
|
|
139
|
-
let
|
|
140
|
-
r && (
|
|
139
|
+
let l = t.strict();
|
|
140
|
+
r && (l = l.usage(`Usage: ${r}`)), s && (l = l.demandCommand(s));
|
|
141
141
|
const h = "help";
|
|
142
|
-
return
|
|
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
|
|
144
|
+
const e = await U(st(), r, !0).fail(
|
|
145
145
|
rt
|
|
146
146
|
).argv;
|
|
147
147
|
return t ? t(e) : e;
|
|
148
|
-
},
|
|
149
|
-
const { command: r, describe: e, handler:
|
|
150
|
-
}, ...
|
|
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
|
|
155
|
+
return U(n, o, !1);
|
|
156
156
|
},
|
|
157
|
-
handler:
|
|
157
|
+
handler: s
|
|
158
158
|
};
|
|
159
159
|
};
|
|
160
|
-
var
|
|
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 = (
|
|
190
|
-
${
|
|
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
|
|
196
|
-
ct(
|
|
197
|
-
e(`${
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
213
|
+
}), Nt = ({
|
|
214
214
|
configPathDefault: t,
|
|
215
215
|
rootDirDefault: r
|
|
216
216
|
}) => ({
|
|
217
217
|
/** 必须保留 */
|
|
218
|
-
...
|
|
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
|
-
}),
|
|
228
|
-
const { configPath: e, rootDir:
|
|
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
|
-
}),
|
|
232
|
-
},
|
|
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:
|
|
234
|
+
edit: s = !1
|
|
235
235
|
} = {}) => {
|
|
236
|
-
const
|
|
237
|
-
if (e == null || e(
|
|
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:
|
|
243
|
-
if (!y(
|
|
242
|
+
const { configPath: e, rootDir: s } = t, o = g.resolve(s, e);
|
|
243
|
+
if (!y(o)) {
|
|
244
244
|
if (r)
|
|
245
|
-
return
|
|
246
|
-
const n = `配置文件不存在 ${
|
|
245
|
+
return f.info("配置文件不存在,使用onNotExists返回值"), r();
|
|
246
|
+
const n = `配置文件不存在 ${o}`;
|
|
247
247
|
throw new Error(n);
|
|
248
248
|
}
|
|
249
|
-
return
|
|
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
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
|
-
},
|
|
258
|
+
}, J = "package.json", T = ({
|
|
259
259
|
rootDir: t
|
|
260
260
|
}) => {
|
|
261
|
-
const r = g.resolve(t,
|
|
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:
|
|
270
|
+
isDevPkg: s
|
|
271
271
|
}) => {
|
|
272
|
-
const
|
|
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 =
|
|
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
|
-
`${
|
|
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
|
-
},
|
|
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 }),
|
|
291
|
-
D(
|
|
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
|
-
|
|
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,
|
|
317
|
+
const [, e, s] = r;
|
|
318
318
|
return {
|
|
319
319
|
fromBranch: e.trim(),
|
|
320
|
-
toBranch:
|
|
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
|
|
329
|
-
m.chmodSync(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
|
|
342
|
-
return tt.satisfies(
|
|
343
|
-
. "$(dirname -- "$0")/_/husky.sh"`) : (console.log(p.cyan(`${
|
|
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
|
|
353
|
-
m.existsSync(
|
|
354
|
-
const n = g.resolve(
|
|
355
|
-
let i = e(
|
|
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} ${
|
|
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} 添加 ${
|
|
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} 添加 ${
|
|
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),
|
|
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
|
|
393
|
-
if (y(
|
|
394
|
-
return v(
|
|
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(),
|
|
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
|
-
|
|
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:
|
|
417
|
-
lastCommitMsg:
|
|
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
|
|
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
|
|
443
|
-
if (
|
|
444
|
-
const [, i, a] =
|
|
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
|
|
474
|
-
if (
|
|
475
|
-
const [, , n] =
|
|
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, ...
|
|
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 ||
|
|
559
|
+
k || f.warn(
|
|
560
560
|
`${i.hash} 是合并提交 但是未从提交信息(${C})中检测到合并分支信息,推测手动更改了提交内容`
|
|
561
561
|
), b = k;
|
|
562
562
|
}
|
|
563
563
|
return {
|
|
564
|
-
...
|
|
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"),
|
|
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
|
-
},
|
|
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),
|
|
599
|
+
const e = St(t), s = g.resolve(
|
|
597
600
|
et(),
|
|
598
601
|
e
|
|
599
602
|
);
|
|
600
|
-
if (y(
|
|
603
|
+
if (y(s))
|
|
601
604
|
return console.log(
|
|
602
|
-
p.red(`${
|
|
605
|
+
p.red(`${s} 已存在,请手动删除该目录再试`)
|
|
603
606
|
), process.exit(1);
|
|
604
|
-
const
|
|
605
|
-
X(
|
|
607
|
+
const o = () => {
|
|
608
|
+
X(s, { recursive: !0, force: !0 });
|
|
606
609
|
};
|
|
607
610
|
let n;
|
|
608
611
|
try {
|
|
609
|
-
u(`git clone ${x} ${
|
|
612
|
+
u(`git clone ${x} ${s} --depth=1`);
|
|
610
613
|
const c = Ct(t), i = Y(t), a = g.resolve(
|
|
611
|
-
|
|
614
|
+
s,
|
|
612
615
|
c
|
|
613
616
|
);
|
|
614
617
|
n = JSON.parse(m.readFileSync(a, "utf-8")), process.once("exit", () => {
|
|
615
|
-
y(
|
|
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:
|
|
624
|
+
configTemporaryDir: s
|
|
622
625
|
});
|
|
623
626
|
} finally {
|
|
624
|
-
|
|
627
|
+
o();
|
|
625
628
|
}
|
|
626
629
|
return n;
|
|
627
630
|
};
|
|
628
631
|
export {
|
|
629
|
-
|
|
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
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
+
de as _curry,
|
|
637
|
+
ue as _get,
|
|
638
|
+
pe as _set,
|
|
636
639
|
Yt as addHuskyHooks,
|
|
637
|
-
|
|
638
|
-
|
|
640
|
+
Jt as addPackageConfig,
|
|
641
|
+
ce as chalk,
|
|
639
642
|
Zt as checkCurrentIsRebasing,
|
|
640
643
|
Ht as createMainCommand,
|
|
641
|
-
|
|
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
|
-
|
|
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
|
-
|
|
658
|
+
lt as getRootDirOptions,
|
|
656
659
|
xt as getRootScriptName,
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "0.7.8",
|
|
4
4
|
"description": "cli utils",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"semver": "^7.5.4",
|
|
69
69
|
"yargs": "^17.7.2"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
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<
|
|
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
|
|