@done-coding/cli-utils 0.7.1 → 0.7.3-alpha.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 +267 -243
- package/package.json +2 -2
- package/types/index.d.ts +8 -0
package/es/index.mjs
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import { default as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import p from "chalk";
|
|
3
|
+
import { default as se } from "chalk";
|
|
4
|
+
import g from "node:path";
|
|
5
|
+
import m, { existsSync as y, mkdirSync as W, writeFileSync as w, readFileSync as v, rmSync as X } from "node:fs";
|
|
6
6
|
import _ from "crypto";
|
|
7
7
|
import q from "prompts";
|
|
8
8
|
import z from "yargs";
|
|
9
9
|
import { hideBin as Q } from "yargs/helpers";
|
|
10
|
-
import { execSync as
|
|
11
|
-
import
|
|
10
|
+
import { execSync as u } from "node:child_process";
|
|
11
|
+
import H from "json5";
|
|
12
12
|
export * from "json5";
|
|
13
|
-
import { default as
|
|
13
|
+
import { default as ce } 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 fe } from "lodash.get";
|
|
18
|
+
import { default as ge } from "lodash.set";
|
|
19
|
+
import { default as me } from "lodash.curry";
|
|
20
20
|
import E from "pinyin";
|
|
21
21
|
const l = Object.assign(
|
|
22
|
-
(t, ...
|
|
22
|
+
(t, ...r) => console.log(...r.map((e) => p[t](e))),
|
|
23
23
|
{
|
|
24
24
|
/** 成功 */
|
|
25
25
|
success: (...t) => l("green", ...t),
|
|
@@ -36,18 +36,18 @@ const l = Object.assign(
|
|
|
36
36
|
}
|
|
37
37
|
), Bt = (t, {
|
|
38
38
|
/** 当前目录 */
|
|
39
|
-
currentDir:
|
|
39
|
+
currentDir: r = process.cwd(),
|
|
40
40
|
/** 优先找最远的父目录 */
|
|
41
|
-
isFindFarthest:
|
|
41
|
+
isFindFarthest: e = !0
|
|
42
42
|
} = {}) => {
|
|
43
|
-
const o =
|
|
43
|
+
const o = g.resolve(r).split(g.sep).map((s, n, c) => n ? g.join(c.slice(0, n).join(g.sep), s) : s);
|
|
44
44
|
for (; o.length; ) {
|
|
45
|
-
const s =
|
|
46
|
-
if (
|
|
45
|
+
const s = e ? o.shift() : o.pop(), n = g.join(s, t);
|
|
46
|
+
if (m.existsSync(n))
|
|
47
47
|
return s;
|
|
48
48
|
}
|
|
49
|
-
},
|
|
50
|
-
function
|
|
49
|
+
}, N = "aes-256-cbc", F = 16, M = "hex", A = ":";
|
|
50
|
+
function G(t) {
|
|
51
51
|
return _.pbkdf2Sync(
|
|
52
52
|
t,
|
|
53
53
|
"done-coding-cli-salt",
|
|
@@ -61,82 +61,105 @@ function N(t) {
|
|
|
61
61
|
}
|
|
62
62
|
function kt({
|
|
63
63
|
text: t,
|
|
64
|
-
secretKey:
|
|
64
|
+
secretKey: r
|
|
65
65
|
}) {
|
|
66
66
|
try {
|
|
67
|
-
const
|
|
67
|
+
const e = G(r), o = _.randomBytes(F), s = _.createCipheriv(N, e, o);
|
|
68
68
|
let n = s.update(t);
|
|
69
69
|
n = Buffer.concat([n, s.final()]);
|
|
70
70
|
const c = o.toString(M), i = n.toString(M);
|
|
71
71
|
return `${c}${A}${i}`;
|
|
72
|
-
} catch (
|
|
72
|
+
} catch (e) {
|
|
73
73
|
return l.error(
|
|
74
|
-
`加密失败: ${
|
|
74
|
+
`加密失败: ${e instanceof Error ? e.message : String(e)}`
|
|
75
75
|
), "";
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function jt({
|
|
79
79
|
encryptedText: t,
|
|
80
|
-
secretKey:
|
|
80
|
+
secretKey: r
|
|
81
81
|
}) {
|
|
82
82
|
try {
|
|
83
83
|
if (!t.includes(A))
|
|
84
84
|
return "";
|
|
85
|
-
const
|
|
85
|
+
const e = G(r), [o, s] = t.split(A);
|
|
86
86
|
if (o.length !== F * 2)
|
|
87
87
|
return "";
|
|
88
|
-
const n = Buffer.from(o, M), c = Buffer.from(s, M), i = _.createDecipheriv(
|
|
88
|
+
const n = Buffer.from(o, M), c = Buffer.from(s, M), i = _.createDecipheriv(N, e, n);
|
|
89
89
|
let a = i.update(c);
|
|
90
90
|
return a = Buffer.concat([a, i.final()]), a.toString();
|
|
91
|
-
} catch (
|
|
91
|
+
} catch (e) {
|
|
92
92
|
return l.error(
|
|
93
|
-
`解密失败: ${
|
|
93
|
+
`解密失败: ${e instanceof Error ? e.message : String(e)}`
|
|
94
94
|
), "";
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
const
|
|
98
|
-
const [
|
|
99
|
-
return q(
|
|
97
|
+
const L = (...t) => {
|
|
98
|
+
const [r, e = {}] = t;
|
|
99
|
+
return q(r, {
|
|
100
100
|
onCancel(o) {
|
|
101
101
|
return l.error(`退出${o == null ? void 0 : o.name}输入`), process.exit(1);
|
|
102
102
|
},
|
|
103
|
-
...
|
|
103
|
+
...e
|
|
104
104
|
});
|
|
105
|
-
}, rt = (t,
|
|
106
|
-
t ? l.error(t) : l.error(
|
|
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
107
|
}, ot = () => {
|
|
108
108
|
const t = Q(process.argv);
|
|
109
109
|
return z(t);
|
|
110
|
+
}, xt = ({
|
|
111
|
+
rootScriptName: t,
|
|
112
|
+
packageJson: r
|
|
113
|
+
}) => {
|
|
114
|
+
if (t)
|
|
115
|
+
return t;
|
|
116
|
+
if (!r)
|
|
117
|
+
return;
|
|
118
|
+
const { bin: e, name: o } = r;
|
|
119
|
+
if (e) {
|
|
120
|
+
if (typeof e == "string")
|
|
121
|
+
return o.includes("/") ? void 0 : o;
|
|
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));
|
|
124
|
+
if (c.length !== 1)
|
|
125
|
+
return;
|
|
126
|
+
const [i] = c[0];
|
|
127
|
+
return process.platform === "win32" ? i.toLowerCase() : i;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
110
130
|
}, J = (t, {
|
|
111
|
-
usage:
|
|
112
|
-
version:
|
|
131
|
+
usage: r,
|
|
132
|
+
version: e,
|
|
113
133
|
demandCommandCount: o,
|
|
114
134
|
options: s,
|
|
115
135
|
positionals: n,
|
|
116
|
-
subcommands: c
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
subcommands: c,
|
|
137
|
+
rootScriptName: i
|
|
138
|
+
}, a) => {
|
|
139
|
+
let f = t.strict();
|
|
140
|
+
r && (f = f.usage(`Usage: ${r}`)), o && (f = f.demandCommand(o));
|
|
141
|
+
const d = "help";
|
|
142
|
+
return f = f.help(d), e ? f = f.version(e).alias("h", d).alias("v", "version") : f = f.alias("h", d), s && (f = f.options(s)), n && (f = Object.entries(n).reduce((S, [P, h]) => S.positional(P, h), f)), c && (f = f.command(c)), a && i && (f = f.scriptName(i)), f;
|
|
143
|
+
}, Ht = async ({ handler: t, ...r }) => {
|
|
144
|
+
const e = await J(ot(), r, !0).fail(
|
|
145
|
+
rt
|
|
146
|
+
).argv;
|
|
147
|
+
return t ? t(e) : e;
|
|
148
|
+
}, Nt = (t) => {
|
|
149
|
+
const { command: r, describe: e, handler: o = () => {
|
|
127
150
|
}, ...s } = t;
|
|
128
151
|
return {
|
|
129
|
-
command:
|
|
130
|
-
describe:
|
|
152
|
+
command: r,
|
|
153
|
+
describe: e,
|
|
131
154
|
builder(n) {
|
|
132
|
-
return J(n, s);
|
|
155
|
+
return J(n, s, !1);
|
|
133
156
|
},
|
|
134
157
|
handler: o
|
|
135
158
|
};
|
|
136
159
|
};
|
|
137
160
|
var st = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(st || {});
|
|
138
161
|
const nt = async () => {
|
|
139
|
-
const { editorType: t } = await
|
|
162
|
+
const { editorType: t } = await L([
|
|
140
163
|
{
|
|
141
164
|
name: "editorType",
|
|
142
165
|
type: "select",
|
|
@@ -146,9 +169,9 @@ const nt = async () => {
|
|
|
146
169
|
"VsCode",
|
|
147
170
|
"其他"
|
|
148
171
|
/* OTHER */
|
|
149
|
-
].map((
|
|
150
|
-
title:
|
|
151
|
-
value:
|
|
172
|
+
].map((r) => ({
|
|
173
|
+
title: r,
|
|
174
|
+
value: r
|
|
152
175
|
}))
|
|
153
176
|
}
|
|
154
177
|
]);
|
|
@@ -156,29 +179,29 @@ const nt = async () => {
|
|
|
156
179
|
}, it = {
|
|
157
180
|
Cursor: "cursor",
|
|
158
181
|
VsCode: "code"
|
|
159
|
-
}, ct = (t,
|
|
182
|
+
}, ct = (t, r, e) => {
|
|
160
183
|
try {
|
|
161
|
-
|
|
184
|
+
u(`${t} -v`, { stdio: "ignore" }), u(`${t} ${r}`);
|
|
162
185
|
} catch {
|
|
163
|
-
|
|
186
|
+
e();
|
|
164
187
|
}
|
|
165
|
-
}, at = (t,
|
|
166
|
-
const
|
|
188
|
+
}, at = (t, r) => {
|
|
189
|
+
const e = (o) => l.info(`
|
|
167
190
|
${o}, 请用编辑器打开 ${t} 进行编辑
|
|
168
191
|
`);
|
|
169
|
-
switch (
|
|
192
|
+
switch (r) {
|
|
170
193
|
case "Cursor":
|
|
171
194
|
case "VsCode": {
|
|
172
|
-
const o = it[
|
|
195
|
+
const o = it[r];
|
|
173
196
|
ct(o, t, () => {
|
|
174
|
-
|
|
197
|
+
e(`${o}命令未安装`);
|
|
175
198
|
});
|
|
176
199
|
break;
|
|
177
200
|
}
|
|
178
201
|
default:
|
|
179
|
-
|
|
202
|
+
e("其他编辑器");
|
|
180
203
|
}
|
|
181
|
-
},
|
|
204
|
+
}, ft = (t = process.cwd()) => ({
|
|
182
205
|
/** 必须保留 */
|
|
183
206
|
rootDir: {
|
|
184
207
|
type: "string",
|
|
@@ -189,10 +212,10 @@ const nt = async () => {
|
|
|
189
212
|
}
|
|
190
213
|
}), Ft = ({
|
|
191
214
|
configPathDefault: t,
|
|
192
|
-
rootDirDefault:
|
|
215
|
+
rootDirDefault: r
|
|
193
216
|
}) => ({
|
|
194
217
|
/** 必须保留 */
|
|
195
|
-
...
|
|
218
|
+
...ft(r),
|
|
196
219
|
/** 必须保留 */
|
|
197
220
|
configPath: {
|
|
198
221
|
type: "string",
|
|
@@ -201,192 +224,192 @@ const nt = async () => {
|
|
|
201
224
|
/** 必须设置默认值 */
|
|
202
225
|
default: t
|
|
203
226
|
}
|
|
204
|
-
}),
|
|
205
|
-
const { configPath:
|
|
206
|
-
return
|
|
227
|
+
}), lt = async (t, r) => {
|
|
228
|
+
const { configPath: e, rootDir: o } = r, s = g.resolve(o, e), n = g.dirname(s);
|
|
229
|
+
return y(n) || W(n, {
|
|
207
230
|
recursive: !0
|
|
208
|
-
}), s.endsWith(".json5") ? (l.info(`json5模式写入 ${s}`),
|
|
209
|
-
},
|
|
210
|
-
onFileGenerated:
|
|
231
|
+
}), s.endsWith(".json5") ? (l.info(`json5模式写入 ${s}`), w(s, H.stringify(t, null, 2)), s) : (l.info(`json模式写入 ${s}`), w(s, JSON.stringify(t, null, 2)), s);
|
|
232
|
+
}, Gt = async (t, r, {
|
|
233
|
+
onFileGenerated: e,
|
|
211
234
|
edit: o = !1
|
|
212
235
|
} = {}) => {
|
|
213
|
-
const s = await
|
|
214
|
-
if (
|
|
236
|
+
const s = await lt(t, r);
|
|
237
|
+
if (e == null || e(s), o) {
|
|
215
238
|
const n = await nt();
|
|
216
|
-
at(
|
|
239
|
+
at(r.configPath, n);
|
|
217
240
|
}
|
|
218
|
-
},
|
|
219
|
-
const { configPath:
|
|
220
|
-
if (!
|
|
221
|
-
if (
|
|
222
|
-
return l.info("配置文件不存在,使用onNotExists返回值"),
|
|
241
|
+
}, Lt = async (t, r) => {
|
|
242
|
+
const { configPath: e, rootDir: o } = t, s = g.resolve(o, e);
|
|
243
|
+
if (!y(s)) {
|
|
244
|
+
if (r)
|
|
245
|
+
return l.info("配置文件不存在,使用onNotExists返回值"), r();
|
|
223
246
|
const n = `配置文件不存在 ${s}`;
|
|
224
247
|
throw new Error(n);
|
|
225
248
|
}
|
|
226
|
-
return s.endsWith(".json5") ? (l.info(`json5模式解析 ${s}`),
|
|
249
|
+
return s.endsWith(".json5") ? (l.info(`json5模式解析 ${s}`), H.parse(v(s, "utf8"))) : (l.info(`json模式解析 ${s}`), JSON.parse(v(s, "utf8")));
|
|
227
250
|
}, Jt = async () => {
|
|
228
|
-
const { useDefaultConfig: t } = await
|
|
251
|
+
const { useDefaultConfig: t } = await L({
|
|
229
252
|
name: "useDefaultConfig",
|
|
230
253
|
type: "confirm",
|
|
231
254
|
message: "使用默认模板配置",
|
|
232
255
|
initial: !0
|
|
233
256
|
});
|
|
234
257
|
return t;
|
|
235
|
-
},
|
|
258
|
+
}, U = "package.json", D = ({
|
|
236
259
|
rootDir: t
|
|
237
260
|
}) => {
|
|
238
|
-
const
|
|
239
|
-
if (!
|
|
261
|
+
const r = g.resolve(t, U);
|
|
262
|
+
if (!y(r))
|
|
240
263
|
throw new Error(`${t}未找到package.json文件`);
|
|
241
|
-
const
|
|
242
|
-
return JSON.parse(
|
|
264
|
+
const e = v(r, "utf-8");
|
|
265
|
+
return JSON.parse(e);
|
|
243
266
|
}, gt = ({
|
|
244
267
|
rootDir: t,
|
|
245
|
-
pkgJson:
|
|
246
|
-
pkgName:
|
|
268
|
+
pkgJson: r,
|
|
269
|
+
pkgName: e,
|
|
247
270
|
isDevPkg: o
|
|
248
271
|
}) => {
|
|
249
|
-
const s =
|
|
250
|
-
let c = n == null ? void 0 : n[
|
|
272
|
+
const s = r || D({ rootDir: t }), n = o ? s.devDependencies : s.dependencies;
|
|
273
|
+
let c = n == null ? void 0 : n[e];
|
|
251
274
|
if (!c) {
|
|
252
275
|
const i = o ? s.dependencies : s.devDependencies;
|
|
253
|
-
c = i == null ? void 0 : i[
|
|
254
|
-
|
|
255
|
-
`${o ? "开发" : "生产"}依赖包${
|
|
276
|
+
c = i == null ? void 0 : i[e], c && console.log(
|
|
277
|
+
p.yellow(
|
|
278
|
+
`${o ? "开发" : "生产"}依赖包${e}可能错误的安装在${o ? "dependencies" : "devDependencies"}`
|
|
256
279
|
)
|
|
257
280
|
);
|
|
258
281
|
return;
|
|
259
282
|
}
|
|
260
|
-
return c || console.log(
|
|
261
|
-
},
|
|
283
|
+
return c || console.log(p.cyan(`依赖包${e}未安装`)), c;
|
|
284
|
+
}, Ut = ({
|
|
262
285
|
patchConfig: t,
|
|
263
|
-
rootDir:
|
|
286
|
+
rootDir: r
|
|
264
287
|
}) => {
|
|
265
288
|
if (!t)
|
|
266
289
|
return;
|
|
267
|
-
const
|
|
268
|
-
|
|
290
|
+
const e = D({ rootDir: r }), o = Z(e, t), s = g.resolve(r, U);
|
|
291
|
+
w(s, JSON.stringify(o, null, 2), "utf-8");
|
|
269
292
|
}, O = (t) => {
|
|
270
|
-
const
|
|
293
|
+
const e = u("git rev-parse --show-toplevel", {
|
|
271
294
|
cwd: t
|
|
272
295
|
}).toString();
|
|
273
|
-
if (!
|
|
296
|
+
if (!e)
|
|
274
297
|
throw new Error("获取git根目录失败");
|
|
275
|
-
return
|
|
276
|
-
},
|
|
298
|
+
return e.trim();
|
|
299
|
+
}, Kt = () => {
|
|
277
300
|
var t;
|
|
278
301
|
try {
|
|
279
|
-
const
|
|
302
|
+
const r = u("git symbolic-ref --short HEAD", {
|
|
280
303
|
stdio: "ignore"
|
|
281
304
|
});
|
|
282
|
-
return (t =
|
|
305
|
+
return (t = r == null ? void 0 : r.toString()) == null ? void 0 : t.trim();
|
|
283
306
|
} catch {
|
|
284
307
|
try {
|
|
285
|
-
const
|
|
286
|
-
l.skip(`当前未指向具体某个分支, 当前commit hash: ${
|
|
308
|
+
const e = u("git rev-parse --short HEAD").toString().trim();
|
|
309
|
+
l.skip(`当前未指向具体某个分支, 当前commit hash: ${e}`);
|
|
287
310
|
} finally {
|
|
288
311
|
return;
|
|
289
312
|
}
|
|
290
313
|
}
|
|
291
314
|
}, ut = (t) => {
|
|
292
|
-
const
|
|
293
|
-
if (
|
|
294
|
-
const [,
|
|
315
|
+
const r = t.match(/moving\s+from\s+(.*)\s+to\s+(.*)/);
|
|
316
|
+
if (r) {
|
|
317
|
+
const [, e, o] = r;
|
|
295
318
|
return {
|
|
296
|
-
fromBranch:
|
|
319
|
+
fromBranch: e.trim(),
|
|
297
320
|
toBranch: o.trim()
|
|
298
321
|
};
|
|
299
322
|
}
|
|
300
323
|
}, I = 73, mt = (t) => {
|
|
301
|
-
const
|
|
302
|
-
if ((
|
|
324
|
+
const e = m.statSync(t).mode;
|
|
325
|
+
if ((e & I) === I)
|
|
303
326
|
return;
|
|
304
|
-
console.log(
|
|
305
|
-
const o =
|
|
306
|
-
|
|
327
|
+
console.log(p.blue(`${t} 没有执行权限 添加... `));
|
|
328
|
+
const o = e | I;
|
|
329
|
+
m.chmodSync(t, o), console.log(p.green(`${t} 添加执行权限成功`));
|
|
307
330
|
};
|
|
308
|
-
var
|
|
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 || {});
|
|
309
332
|
const pt = "husky", ht = ".husky", dt = ({ rootDir: t }) => {
|
|
310
|
-
const
|
|
311
|
-
rootDir:
|
|
312
|
-
pkgJson:
|
|
333
|
+
const r = O(t), e = gt({
|
|
334
|
+
rootDir: r,
|
|
335
|
+
pkgJson: D({ rootDir: r }),
|
|
313
336
|
pkgName: pt,
|
|
314
337
|
isDevPkg: !0
|
|
315
338
|
});
|
|
316
|
-
if (!
|
|
339
|
+
if (!e)
|
|
317
340
|
throw new Error("husky版本获取失败, 可能husky未安装");
|
|
318
|
-
const o =
|
|
319
|
-
return tt.satisfies(o, s) ? (console.log(
|
|
320
|
-
. "$(dirname -- "$0")/_/husky.sh"`) : (console.log(
|
|
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}`)), "");
|
|
321
344
|
}, yt = ({ rootDir: t }) => {
|
|
322
|
-
const
|
|
323
|
-
return
|
|
324
|
-
},
|
|
345
|
+
const r = O(t);
|
|
346
|
+
return g.resolve(r, ht);
|
|
347
|
+
}, Yt = ({
|
|
325
348
|
hookNames: t,
|
|
326
|
-
rootDir:
|
|
327
|
-
getCode:
|
|
349
|
+
rootDir: r,
|
|
350
|
+
getCode: e
|
|
328
351
|
}) => {
|
|
329
|
-
const o = yt({ rootDir:
|
|
330
|
-
|
|
331
|
-
const n =
|
|
332
|
-
let i =
|
|
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);
|
|
333
356
|
if (c)
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
) : (
|
|
357
|
+
m.readFileSync(n, "utf-8").includes(i) ? console.log(
|
|
358
|
+
p.gray(`${n} ${s}相关调用 ${i} 已存在 跳过`)
|
|
359
|
+
) : (m.appendFileSync(
|
|
337
360
|
n,
|
|
338
361
|
`
|
|
339
362
|
${i}
|
|
340
363
|
`
|
|
341
|
-
), console.log(
|
|
364
|
+
), console.log(p.green(`${n} 添加 ${s}相关调用成功`)));
|
|
342
365
|
else {
|
|
343
366
|
const a = dt({
|
|
344
|
-
rootDir:
|
|
367
|
+
rootDir: r
|
|
345
368
|
});
|
|
346
|
-
|
|
369
|
+
m.writeFileSync(
|
|
347
370
|
n,
|
|
348
371
|
`${a}
|
|
349
372
|
|
|
350
373
|
${i}
|
|
351
374
|
`,
|
|
352
375
|
"utf-8"
|
|
353
|
-
), console.log(
|
|
376
|
+
), console.log(p.green(`${n} 添加 ${s}相关调用成功`));
|
|
354
377
|
}
|
|
355
378
|
mt(n);
|
|
356
379
|
});
|
|
357
|
-
},
|
|
380
|
+
}, Vt = [
|
|
358
381
|
// HooksNameEnum.PRE_MERGE_COMMIT,
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
],
|
|
382
|
+
R.PREPARE_COMMIT_MSG,
|
|
383
|
+
R.COMMIT_MSG
|
|
384
|
+
], Wt = ({
|
|
362
385
|
hookName: t,
|
|
363
|
-
rootDir:
|
|
386
|
+
rootDir: r
|
|
364
387
|
}) => {
|
|
365
|
-
const
|
|
388
|
+
const e = O(r), o = g.resolve(e, ".git");
|
|
366
389
|
switch (t) {
|
|
367
|
-
case
|
|
368
|
-
case
|
|
369
|
-
const s =
|
|
370
|
-
if (
|
|
390
|
+
case R.PREPARE_COMMIT_MSG:
|
|
391
|
+
case R.COMMIT_MSG: {
|
|
392
|
+
const s = g.resolve(o, "MERGE_MSG");
|
|
393
|
+
if (y(s))
|
|
371
394
|
return v(s, "utf-8");
|
|
372
395
|
}
|
|
373
396
|
}
|
|
374
397
|
return "";
|
|
375
|
-
},
|
|
376
|
-
remoteAlias: t
|
|
398
|
+
}, Xt = ({
|
|
399
|
+
remoteAlias: t = "origin"
|
|
377
400
|
} = {}) => {
|
|
378
401
|
try {
|
|
379
|
-
const
|
|
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();
|
|
380
403
|
let a = "";
|
|
381
404
|
try {
|
|
382
|
-
a =
|
|
405
|
+
a = u(`git config --get remote.${t}.url`).toString().trim();
|
|
383
406
|
} catch {
|
|
384
407
|
l.warn("git远程仓库地址获取失败或者不存在");
|
|
385
408
|
}
|
|
386
409
|
return {
|
|
387
|
-
lastHash:
|
|
388
|
-
lastCommitter:
|
|
389
|
-
lastCommitterPinYin: E(
|
|
410
|
+
lastHash: r,
|
|
411
|
+
lastCommitter: e,
|
|
412
|
+
lastCommitterPinYin: E(e, {
|
|
390
413
|
style: E.STYLE_NORMAL,
|
|
391
414
|
heteronym: !1
|
|
392
415
|
}).join(""),
|
|
@@ -404,13 +427,13 @@ ${i}
|
|
|
404
427
|
url: a
|
|
405
428
|
} : void 0
|
|
406
429
|
};
|
|
407
|
-
} catch (
|
|
408
|
-
throw l.error("获取git最后提交信息失败"),
|
|
430
|
+
} catch (r) {
|
|
431
|
+
throw l.error("获取git最后提交信息失败"), r;
|
|
409
432
|
}
|
|
410
|
-
},
|
|
411
|
-
const
|
|
412
|
-
if (
|
|
413
|
-
const [, i, a] =
|
|
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;
|
|
414
437
|
return {
|
|
415
438
|
fromBranch: i,
|
|
416
439
|
toBranch: a
|
|
@@ -436,13 +459,13 @@ ${i}
|
|
|
436
459
|
return {
|
|
437
460
|
fromBranch: t.replace(T.MERGE, "").trim()
|
|
438
461
|
};
|
|
439
|
-
},
|
|
462
|
+
}, qt = () => {
|
|
440
463
|
const t = process.env.GIT_REFLOG_ACTION || "";
|
|
441
464
|
if (!t)
|
|
442
465
|
return;
|
|
443
|
-
const
|
|
444
|
-
if (
|
|
445
|
-
const [, n] =
|
|
466
|
+
const r = /merge\s+([^\s]+)\s*/i, e = t.match(r);
|
|
467
|
+
if (e) {
|
|
468
|
+
const [, n] = e;
|
|
446
469
|
return {
|
|
447
470
|
fromBranch: n
|
|
448
471
|
};
|
|
@@ -456,19 +479,19 @@ ${i}
|
|
|
456
479
|
}
|
|
457
480
|
};
|
|
458
481
|
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 || {});
|
|
459
|
-
const
|
|
482
|
+
const j = "__GIT_REPLACE_MARK__", $ = {
|
|
460
483
|
stringify(t) {
|
|
461
|
-
return JSON.stringify(t).replace(/"/g,
|
|
484
|
+
return JSON.stringify(t).replace(/"/g, j);
|
|
462
485
|
},
|
|
463
486
|
parse(t) {
|
|
464
|
-
return JSON.parse(t.replace(new RegExp(
|
|
487
|
+
return JSON.parse(t.replace(new RegExp(j, "g"), '"'));
|
|
465
488
|
}
|
|
466
|
-
},
|
|
489
|
+
}, zt = ({
|
|
467
490
|
count: t = 100
|
|
468
491
|
} = {}) => {
|
|
469
492
|
if (t <= 0)
|
|
470
493
|
return [];
|
|
471
|
-
const
|
|
494
|
+
const r = {
|
|
472
495
|
hash: "%H",
|
|
473
496
|
/** 提交信息 */
|
|
474
497
|
message: "%s",
|
|
@@ -485,112 +508,112 @@ const k = "__GIT_REPLACE_MARK__", $ = {
|
|
|
485
508
|
/** 提交日期 */
|
|
486
509
|
commitTime: "%ci"
|
|
487
510
|
};
|
|
488
|
-
return
|
|
511
|
+
return u(
|
|
489
512
|
`git --no-pager log --oneline -n ${t} --pretty=format:"${$.stringify(
|
|
490
|
-
|
|
513
|
+
r
|
|
491
514
|
)}"`
|
|
492
515
|
).toString().split(`
|
|
493
516
|
`).map((n) => {
|
|
494
517
|
const c = $.parse(n);
|
|
495
518
|
return {
|
|
496
519
|
...c,
|
|
497
|
-
mergeInfo:
|
|
520
|
+
mergeInfo: K(c.message)
|
|
498
521
|
};
|
|
499
522
|
});
|
|
500
|
-
},
|
|
523
|
+
}, Qt = ({
|
|
501
524
|
count: t = 100,
|
|
502
|
-
filterItem:
|
|
525
|
+
filterItem: r = () => !0
|
|
503
526
|
} = {}) => {
|
|
504
527
|
if (t <= 0)
|
|
505
528
|
return [];
|
|
506
|
-
const
|
|
529
|
+
const e = {
|
|
507
530
|
hash: "%H",
|
|
508
531
|
fullMessage: "%gs",
|
|
509
532
|
committer: "%cn",
|
|
510
533
|
committerEmail: "%ce",
|
|
511
534
|
commitTime: "%ci"
|
|
512
535
|
};
|
|
513
|
-
return
|
|
536
|
+
return u(
|
|
514
537
|
`git --no-pager reflog -n ${t} --pretty=format:"${$.stringify(
|
|
515
|
-
|
|
538
|
+
e
|
|
516
539
|
)}"`
|
|
517
540
|
).toString().split(`
|
|
518
|
-
`).map((i) => $.parse(i)).filter(
|
|
519
|
-
const { fullMessage: a, ...
|
|
520
|
-
let
|
|
541
|
+
`).map((i) => $.parse(i)).filter(r).map((i) => {
|
|
542
|
+
const { fullMessage: a, ...f } = i, d = ":", [S] = a.split(d, 1), P = a.slice(`${S}${d}`.length), h = S.trim(), C = P.trim();
|
|
543
|
+
let b, B, V;
|
|
521
544
|
if (h.startsWith(
|
|
522
545
|
"checkout"
|
|
523
546
|
/* CHECKOUT */
|
|
524
547
|
))
|
|
525
|
-
|
|
548
|
+
B = ut(C);
|
|
526
549
|
else if (h.startsWith(
|
|
527
550
|
"merge"
|
|
528
551
|
/* MERGE */
|
|
529
552
|
))
|
|
530
|
-
|
|
553
|
+
b = Rt(h);
|
|
531
554
|
else if (h.startsWith(
|
|
532
555
|
"commit (merge)"
|
|
533
556
|
/* COMMIT_MERGE */
|
|
534
557
|
)) {
|
|
535
|
-
const
|
|
536
|
-
|
|
558
|
+
const k = K(C);
|
|
559
|
+
k || l.warn(
|
|
537
560
|
`${i.hash} 是合并提交 但是未从提交信息(${C})中检测到合并分支信息,推测手动更改了提交内容`
|
|
538
|
-
),
|
|
561
|
+
), b = k;
|
|
539
562
|
}
|
|
540
563
|
return {
|
|
541
|
-
...
|
|
564
|
+
...f,
|
|
542
565
|
type: h,
|
|
543
566
|
message: C,
|
|
544
|
-
mergeInfo:
|
|
545
|
-
checkoutInfo:
|
|
567
|
+
mergeInfo: b,
|
|
568
|
+
checkoutInfo: B,
|
|
546
569
|
rebaseInfo: V
|
|
547
570
|
};
|
|
548
571
|
});
|
|
549
|
-
},
|
|
550
|
-
const
|
|
551
|
-
if (
|
|
572
|
+
}, Zt = (t) => {
|
|
573
|
+
const r = O(t), e = g.resolve(r, ".git"), o = g.resolve(e, "rebase-merge");
|
|
574
|
+
if (m.existsSync(o))
|
|
552
575
|
return !0;
|
|
553
|
-
const s =
|
|
554
|
-
if (
|
|
576
|
+
const s = g.resolve(e, "rebase-apply");
|
|
577
|
+
if (m.existsSync(s))
|
|
555
578
|
return !0;
|
|
556
|
-
const n =
|
|
557
|
-
return !!
|
|
558
|
-
},
|
|
579
|
+
const n = g.resolve(e, "REBASE_HEAD");
|
|
580
|
+
return !!m.existsSync(n);
|
|
581
|
+
}, te = ({
|
|
559
582
|
branchName: t,
|
|
560
|
-
version:
|
|
561
|
-
remoteInfo:
|
|
583
|
+
version: r,
|
|
584
|
+
remoteInfo: e
|
|
562
585
|
}) => {
|
|
563
|
-
|
|
586
|
+
e && (u(`git push ${e.alias} v${r}`, {
|
|
564
587
|
stdio: "inherit"
|
|
565
|
-
}),
|
|
588
|
+
}), u(`git push ${e.alias} ${t}`, {
|
|
566
589
|
stdio: "inherit"
|
|
567
590
|
}));
|
|
568
|
-
}, x = "git@gitee.com:justsosu/done-coding-cli-assets-config.git", St = (t) => `./.DONE_CODING_CLI/CONFIG_TEMP_DIR_FOR_${t}`,
|
|
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 ({
|
|
569
592
|
moduleName: t,
|
|
570
|
-
onSuccess:
|
|
593
|
+
onSuccess: r
|
|
571
594
|
}) => {
|
|
572
|
-
console.log(
|
|
573
|
-
const
|
|
595
|
+
console.log(p.blue(`拉取${t}配置,请稍等...`));
|
|
596
|
+
const e = St(t), o = g.resolve(
|
|
574
597
|
et(),
|
|
575
|
-
|
|
598
|
+
e
|
|
576
599
|
);
|
|
577
|
-
if (
|
|
600
|
+
if (y(o))
|
|
578
601
|
return console.log(
|
|
579
|
-
|
|
602
|
+
p.red(`${o} 已存在,请手动删除该目录再试`)
|
|
580
603
|
), process.exit(1);
|
|
581
604
|
const s = () => {
|
|
582
605
|
X(o, { recursive: !0, force: !0 });
|
|
583
606
|
};
|
|
584
607
|
let n;
|
|
585
608
|
try {
|
|
586
|
-
|
|
587
|
-
const c = Ct(t), i =
|
|
609
|
+
u(`git clone ${x} ${o} --depth=1`);
|
|
610
|
+
const c = Ct(t), i = Y(t), a = g.resolve(
|
|
588
611
|
o,
|
|
589
612
|
c
|
|
590
613
|
);
|
|
591
|
-
n = JSON.parse(
|
|
592
|
-
|
|
593
|
-
}), await
|
|
614
|
+
n = JSON.parse(m.readFileSync(a, "utf-8")), process.once("exit", () => {
|
|
615
|
+
y(o) && (console.log("发现进程退出,正在清理临时目录..."), s());
|
|
616
|
+
}), await r({
|
|
594
617
|
repoUrl: x,
|
|
595
618
|
config: n,
|
|
596
619
|
cliConfigFileRelativePath: c,
|
|
@@ -605,44 +628,45 @@ const k = "__GIT_REPLACE_MARK__", $ = {
|
|
|
605
628
|
export {
|
|
606
629
|
st as EditorTypeEnum,
|
|
607
630
|
T as GitRefLogTypeEnum,
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
631
|
+
R as HooksNameEnum,
|
|
632
|
+
Vt as SUPPORT_GET_COMMIT_BY_HOOKS_NAMES,
|
|
633
|
+
me as _curry,
|
|
634
|
+
fe as _get,
|
|
635
|
+
ge as _set,
|
|
636
|
+
Yt as addHuskyHooks,
|
|
637
|
+
Ut as addPackageConfig,
|
|
638
|
+
se as chalk,
|
|
639
|
+
Zt as checkCurrentIsRebasing,
|
|
640
|
+
Ht as createMainCommand,
|
|
641
|
+
Nt as createSubcommand,
|
|
642
|
+
jt as decryptAES,
|
|
620
643
|
kt as encryptAES,
|
|
621
644
|
mt as fileAddX,
|
|
622
|
-
|
|
645
|
+
Wt as getCommitByHookName,
|
|
623
646
|
Ft as getConfigFileCommonOptions,
|
|
624
|
-
|
|
625
|
-
|
|
647
|
+
zt as getCurrentBranchLastCommitList,
|
|
648
|
+
Kt as getCurrentBranchName,
|
|
626
649
|
nt as getEditorType,
|
|
627
|
-
|
|
650
|
+
Xt as getGitLastCommitInfo,
|
|
628
651
|
O as getGitProjectDir,
|
|
629
|
-
|
|
630
|
-
|
|
652
|
+
Qt as getLastReflogList,
|
|
653
|
+
D as getPackageJson,
|
|
631
654
|
gt as getRelyPkgVersion,
|
|
632
|
-
|
|
655
|
+
ft as getRootDirOptions,
|
|
656
|
+
xt as getRootScriptName,
|
|
633
657
|
Jt as getUseDefaultConfig,
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
658
|
+
lt as initConfigFile,
|
|
659
|
+
Gt as initHandlerCommon,
|
|
660
|
+
ce as json5,
|
|
637
661
|
l as log,
|
|
638
662
|
Bt as lookForParentTarget,
|
|
639
663
|
at as openFileInEditor,
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
664
|
+
te as pushGitPublishInfoToRemote,
|
|
665
|
+
ee as readCliConfig,
|
|
666
|
+
Lt as readConfigFile,
|
|
643
667
|
ut as resolveCheckoutInfoByRefInfo,
|
|
644
|
-
|
|
645
|
-
|
|
668
|
+
K as resolveMergeInfoByCommitMsg,
|
|
669
|
+
qt as resolveMergeInfoByGitReflogAction,
|
|
646
670
|
Rt as resolveMergeInfoByRefType,
|
|
647
|
-
|
|
671
|
+
L as xPrompts
|
|
648
672
|
};
|
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.3-alpha.0",
|
|
4
4
|
"description": "cli utils",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"semver": "^7.5.4",
|
|
68
68
|
"yargs": "^17.7.2"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "9d9a2e60f255038a0f065e3a4e6d6d35488408ae"
|
|
71
71
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -68,6 +68,8 @@ export declare interface CliInfo {
|
|
|
68
68
|
};
|
|
69
69
|
/** 处理函数 */
|
|
70
70
|
handler?: CommandModule["handler"];
|
|
71
|
+
/** 根命令 */
|
|
72
|
+
rootScriptName?: string;
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
export { CommandModule }
|
|
@@ -192,6 +194,12 @@ export declare const getRootDirOptions: (rootDirDefault?: string) => {
|
|
|
192
194
|
rootDir: YargsOptions;
|
|
193
195
|
};
|
|
194
196
|
|
|
197
|
+
/** 获取根命令名称 */
|
|
198
|
+
export declare const getRootScriptName: ({ rootScriptName, packageJson, }: {
|
|
199
|
+
rootScriptName?: string | undefined;
|
|
200
|
+
packageJson?: Pick<PackageJson, "name" | "bin"> | undefined;
|
|
201
|
+
}) => string | undefined;
|
|
202
|
+
|
|
195
203
|
/** 获取是否使用默认配置 */
|
|
196
204
|
export declare const getUseDefaultConfig: () => Promise<any>;
|
|
197
205
|
|