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