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