@done-coding/cli-utils 0.7.7 → 0.8.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 +403 -330
- package/package.json +4 -2
- package/types/index.d.ts +94 -9
package/es/index.mjs
CHANGED
|
@@ -1,54 +1,56 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import p from "chalk";
|
|
3
|
-
import { default as
|
|
4
|
-
import
|
|
5
|
-
import m, { existsSync as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { hideBin as
|
|
3
|
+
import { default as Ie } from "chalk";
|
|
4
|
+
import l from "node:path";
|
|
5
|
+
import m, { existsSync as I, mkdirSync as q, writeFileSync as b, readFileSync as R } from "node:fs";
|
|
6
|
+
import C from "crypto";
|
|
7
|
+
import z from "prompts";
|
|
8
|
+
import Q from "yargs";
|
|
9
|
+
import { hideBin as Z } from "yargs/helpers";
|
|
10
10
|
import { execSync as u } from "node:child_process";
|
|
11
|
-
import
|
|
11
|
+
import F from "json5";
|
|
12
12
|
export * from "json5";
|
|
13
|
-
import { default as
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import { tmpdir as
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { default as
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
import { default as Ae } from "json5";
|
|
14
|
+
import tt from "lodash.merge";
|
|
15
|
+
import et from "semver";
|
|
16
|
+
import { tmpdir as rt, homedir as st } from "node:os";
|
|
17
|
+
import { v4 as ot } from "uuid";
|
|
18
|
+
import { v4 as be } from "uuid";
|
|
19
|
+
import { default as Te } from "lodash.get";
|
|
20
|
+
import { default as Ne } from "lodash.set";
|
|
21
|
+
import { default as Ge } from "lodash.curry";
|
|
22
|
+
import _ from "pinyin";
|
|
23
|
+
const g = Object.assign(
|
|
24
|
+
(t, ...e) => console.log(...e.map((r) => p[t](r))),
|
|
23
25
|
{
|
|
24
26
|
/** 成功 */
|
|
25
|
-
success: (...t) =>
|
|
27
|
+
success: (...t) => g("green", ...t),
|
|
26
28
|
/** /步骤 */
|
|
27
|
-
stage: (...t) =>
|
|
29
|
+
stage: (...t) => g("blue", ...t),
|
|
28
30
|
/** 提示信息 */
|
|
29
|
-
info: (...t) =>
|
|
31
|
+
info: (...t) => g("cyan", ...t),
|
|
30
32
|
/** 警告 */
|
|
31
|
-
warn: (...t) =>
|
|
33
|
+
warn: (...t) => g("yellow", ...t),
|
|
32
34
|
/** 错误 */
|
|
33
|
-
error: (...t) =>
|
|
35
|
+
error: (...t) => g("red", ...t),
|
|
34
36
|
/** 跳过 */
|
|
35
|
-
skip: (...t) =>
|
|
37
|
+
skip: (...t) => g("gray", ...t)
|
|
36
38
|
}
|
|
37
|
-
),
|
|
39
|
+
), Qt = (t, {
|
|
38
40
|
/** 当前目录 */
|
|
39
|
-
currentDir:
|
|
41
|
+
currentDir: e = process.cwd(),
|
|
40
42
|
/** 优先找最远的父目录 */
|
|
41
|
-
isFindFarthest:
|
|
43
|
+
isFindFarthest: r = !0
|
|
42
44
|
} = {}) => {
|
|
43
|
-
const o =
|
|
45
|
+
const o = l.resolve(e).split(l.sep).map((s, n, c) => c.slice(0, n).concat(s).join(l.sep) || l.sep);
|
|
44
46
|
for (; o.length; ) {
|
|
45
|
-
const s =
|
|
47
|
+
const s = r ? o.shift() : o.pop(), n = l.join(s, t);
|
|
46
48
|
if (m.existsSync(n))
|
|
47
49
|
return s;
|
|
48
50
|
}
|
|
49
|
-
},
|
|
50
|
-
function
|
|
51
|
-
return
|
|
51
|
+
}, x = "aes-256-cbc", j = 16, O = "hex", w = ":";
|
|
52
|
+
function k(t) {
|
|
53
|
+
return C.pbkdf2Sync(
|
|
52
54
|
t,
|
|
53
55
|
"done-coding-cli-salt",
|
|
54
56
|
// 使用固定的盐值
|
|
@@ -59,107 +61,107 @@ function G(t) {
|
|
|
59
61
|
"sha256"
|
|
60
62
|
);
|
|
61
63
|
}
|
|
62
|
-
function
|
|
64
|
+
function Zt({
|
|
63
65
|
text: t,
|
|
64
|
-
secretKey:
|
|
66
|
+
secretKey: e
|
|
65
67
|
}) {
|
|
66
68
|
try {
|
|
67
|
-
const
|
|
69
|
+
const r = k(e), o = C.randomBytes(j), s = C.createCipheriv(x, r, o);
|
|
68
70
|
let n = s.update(t);
|
|
69
71
|
n = Buffer.concat([n, s.final()]);
|
|
70
|
-
const c = o.toString(
|
|
72
|
+
const c = o.toString(O), i = n.toString(O);
|
|
71
73
|
return `${c}${w}${i}`;
|
|
72
|
-
} catch (
|
|
73
|
-
return
|
|
74
|
-
`加密失败: ${
|
|
74
|
+
} catch (r) {
|
|
75
|
+
return g.error(
|
|
76
|
+
`加密失败: ${r instanceof Error ? r.message : String(r)}`
|
|
75
77
|
), "";
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
|
-
function
|
|
80
|
+
function te({
|
|
79
81
|
encryptedText: t,
|
|
80
|
-
secretKey:
|
|
82
|
+
secretKey: e
|
|
81
83
|
}) {
|
|
82
84
|
try {
|
|
83
85
|
if (!t.includes(w))
|
|
84
86
|
return "";
|
|
85
|
-
const
|
|
86
|
-
if (o.length !==
|
|
87
|
+
const r = k(e), [o, s] = t.split(w);
|
|
88
|
+
if (o.length !== j * 2)
|
|
87
89
|
return "";
|
|
88
|
-
const n = Buffer.from(o,
|
|
89
|
-
let
|
|
90
|
-
return
|
|
91
|
-
} catch (
|
|
92
|
-
return
|
|
93
|
-
`解密失败: ${
|
|
90
|
+
const n = Buffer.from(o, O), c = Buffer.from(s, O), i = C.createDecipheriv(x, r, n);
|
|
91
|
+
let f = i.update(c);
|
|
92
|
+
return f = Buffer.concat([f, i.final()]), f.toString();
|
|
93
|
+
} catch (r) {
|
|
94
|
+
return g.error(
|
|
95
|
+
`解密失败: ${r instanceof Error ? r.message : String(r)}`
|
|
94
96
|
), "";
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
|
-
const
|
|
98
|
-
const [
|
|
99
|
-
return
|
|
99
|
+
const H = (...t) => {
|
|
100
|
+
const [e, r = {}] = t;
|
|
101
|
+
return z(e, {
|
|
100
102
|
onCancel(o) {
|
|
101
|
-
return
|
|
103
|
+
return g.error(`退出${o == null ? void 0 : o.name}输入`), process.exit(1);
|
|
102
104
|
},
|
|
103
|
-
...
|
|
105
|
+
...r
|
|
104
106
|
});
|
|
105
|
-
},
|
|
106
|
-
t ?
|
|
107
|
-
},
|
|
108
|
-
const t =
|
|
109
|
-
return
|
|
110
|
-
},
|
|
107
|
+
}, nt = (t, e) => {
|
|
108
|
+
t ? g.error(t) : g.error(e.message), e != null && e.stack && g.error(e.stack), process.exit(1);
|
|
109
|
+
}, it = () => {
|
|
110
|
+
const t = Z(process.argv);
|
|
111
|
+
return Q(t);
|
|
112
|
+
}, ee = ({
|
|
111
113
|
rootScriptName: t,
|
|
112
|
-
packageJson:
|
|
114
|
+
packageJson: e
|
|
113
115
|
}) => {
|
|
114
116
|
if (t)
|
|
115
117
|
return t;
|
|
116
|
-
if (!
|
|
118
|
+
if (!e)
|
|
117
119
|
return;
|
|
118
|
-
const { bin:
|
|
119
|
-
if (
|
|
120
|
-
if (typeof
|
|
120
|
+
const { bin: r, name: o } = e;
|
|
121
|
+
if (r) {
|
|
122
|
+
if (typeof r == "string")
|
|
121
123
|
return o.includes("/") ? void 0 : o;
|
|
122
|
-
if (typeof
|
|
123
|
-
const s = Object.entries(
|
|
124
|
+
if (typeof r == "object") {
|
|
125
|
+
const s = Object.entries(r), n = process.argv[1], c = s.filter(([, f]) => n == null ? void 0 : n.endsWith(f));
|
|
124
126
|
if (c.length !== 1)
|
|
125
127
|
return;
|
|
126
128
|
const [i] = c[0];
|
|
127
129
|
return process.platform === "win32" ? i.toLowerCase() : i;
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
|
-
},
|
|
131
|
-
usage:
|
|
132
|
-
version:
|
|
132
|
+
}, U = (t, {
|
|
133
|
+
usage: e,
|
|
134
|
+
version: r,
|
|
133
135
|
demandCommandCount: o,
|
|
134
136
|
options: s,
|
|
135
137
|
positionals: n,
|
|
136
138
|
subcommands: c,
|
|
137
139
|
rootScriptName: i
|
|
138
|
-
},
|
|
139
|
-
let
|
|
140
|
-
|
|
140
|
+
}, f) => {
|
|
141
|
+
let a = t.strict();
|
|
142
|
+
e && (a = a.usage(`Usage: ${e}`)), o && (a = a.demandCommand(o));
|
|
141
143
|
const h = "help";
|
|
142
|
-
return
|
|
143
|
-
},
|
|
144
|
-
const
|
|
145
|
-
|
|
144
|
+
return a = a.help(h), r ? a = a.version(r).alias("h", h).alias("v", "version") : a = a.alias("h", h), s && (a = a.options(s)), n && (a = Object.entries(n).reduce((y, [M, d]) => y.positional(M, d), a)), c && (a = a.command(c)), f && i && (a = a.scriptName(i)), a;
|
|
145
|
+
}, re = async ({ handler: t, ...e }) => {
|
|
146
|
+
const r = await U(it(), e, !0).fail(
|
|
147
|
+
nt
|
|
146
148
|
).argv;
|
|
147
|
-
return t ? t(
|
|
148
|
-
},
|
|
149
|
-
const { command:
|
|
149
|
+
return t ? t(r) : r;
|
|
150
|
+
}, se = (t) => {
|
|
151
|
+
const { command: e, describe: r, handler: o = () => {
|
|
150
152
|
}, ...s } = t;
|
|
151
153
|
return {
|
|
152
|
-
command:
|
|
153
|
-
describe:
|
|
154
|
+
command: e,
|
|
155
|
+
describe: r,
|
|
154
156
|
builder(n) {
|
|
155
|
-
return
|
|
157
|
+
return U(n, s, !1);
|
|
156
158
|
},
|
|
157
159
|
handler: o
|
|
158
160
|
};
|
|
159
161
|
};
|
|
160
|
-
var
|
|
161
|
-
const
|
|
162
|
-
const { editorType: t } = await
|
|
162
|
+
var ct = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(ct || {});
|
|
163
|
+
const at = async () => {
|
|
164
|
+
const { editorType: t } = await H([
|
|
163
165
|
{
|
|
164
166
|
name: "editorType",
|
|
165
167
|
type: "select",
|
|
@@ -169,39 +171,39 @@ const nt = async () => {
|
|
|
169
171
|
"VsCode",
|
|
170
172
|
"其他"
|
|
171
173
|
/* OTHER */
|
|
172
|
-
].map((
|
|
173
|
-
title:
|
|
174
|
-
value:
|
|
174
|
+
].map((e) => ({
|
|
175
|
+
title: e,
|
|
176
|
+
value: e
|
|
175
177
|
}))
|
|
176
178
|
}
|
|
177
179
|
]);
|
|
178
180
|
return t;
|
|
179
|
-
},
|
|
181
|
+
}, lt = {
|
|
180
182
|
Cursor: "cursor",
|
|
181
183
|
VsCode: "code"
|
|
182
|
-
},
|
|
184
|
+
}, ft = (t, e, r) => {
|
|
183
185
|
try {
|
|
184
|
-
u(`${t} -v`, { stdio: "ignore" }), u(`${t} ${
|
|
186
|
+
u(`${t} -v`, { stdio: "ignore" }), u(`${t} ${e}`);
|
|
185
187
|
} catch {
|
|
186
|
-
|
|
188
|
+
r();
|
|
187
189
|
}
|
|
188
|
-
},
|
|
189
|
-
const
|
|
190
|
+
}, gt = (t, e) => {
|
|
191
|
+
const r = (o) => g.info(`
|
|
190
192
|
${o}, 请用编辑器打开 ${t} 进行编辑
|
|
191
193
|
`);
|
|
192
|
-
switch (
|
|
194
|
+
switch (e) {
|
|
193
195
|
case "Cursor":
|
|
194
196
|
case "VsCode": {
|
|
195
|
-
const o =
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
const o = lt[e];
|
|
198
|
+
ft(o, t, () => {
|
|
199
|
+
r(`${o}命令未安装`);
|
|
198
200
|
});
|
|
199
201
|
break;
|
|
200
202
|
}
|
|
201
203
|
default:
|
|
202
|
-
|
|
204
|
+
r("其他编辑器");
|
|
203
205
|
}
|
|
204
|
-
},
|
|
206
|
+
}, ut = (t = process.cwd()) => ({
|
|
205
207
|
/** 必须保留 */
|
|
206
208
|
rootDir: {
|
|
207
209
|
type: "string",
|
|
@@ -210,12 +212,12 @@ const nt = async () => {
|
|
|
210
212
|
/** 必须设置默认值 */
|
|
211
213
|
default: t
|
|
212
214
|
}
|
|
213
|
-
}),
|
|
215
|
+
}), oe = ({
|
|
214
216
|
configPathDefault: t,
|
|
215
|
-
rootDirDefault:
|
|
217
|
+
rootDirDefault: e
|
|
216
218
|
}) => ({
|
|
217
219
|
/** 必须保留 */
|
|
218
|
-
...
|
|
220
|
+
...ut(e),
|
|
219
221
|
/** 必须保留 */
|
|
220
222
|
configPath: {
|
|
221
223
|
type: "string",
|
|
@@ -224,135 +226,145 @@ const nt = async () => {
|
|
|
224
226
|
/** 必须设置默认值 */
|
|
225
227
|
default: t
|
|
226
228
|
}
|
|
227
|
-
}),
|
|
228
|
-
const { configPath:
|
|
229
|
-
return
|
|
229
|
+
}), mt = async (t, e) => {
|
|
230
|
+
const { configPath: r, rootDir: o } = e, s = l.resolve(o, r), n = l.dirname(s);
|
|
231
|
+
return I(n) || q(n, {
|
|
230
232
|
recursive: !0
|
|
231
|
-
}), s.endsWith(".json5") ? (
|
|
232
|
-
},
|
|
233
|
-
onFileGenerated:
|
|
233
|
+
}), s.endsWith(".json5") ? (g.info(`json5模式写入 ${s}`), b(s, F.stringify(t, null, 2)), s) : (g.info(`json模式写入 ${s}`), b(s, JSON.stringify(t, null, 2)), s);
|
|
234
|
+
}, ne = async (t, e, {
|
|
235
|
+
onFileGenerated: r,
|
|
234
236
|
edit: o = !1
|
|
235
237
|
} = {}) => {
|
|
236
|
-
const s = await
|
|
237
|
-
if (
|
|
238
|
-
const n = await
|
|
239
|
-
|
|
238
|
+
const s = await mt(t, e);
|
|
239
|
+
if (r == null || r(s), o) {
|
|
240
|
+
const n = await at();
|
|
241
|
+
gt(e.configPath, n);
|
|
240
242
|
}
|
|
241
|
-
},
|
|
242
|
-
const { configPath:
|
|
243
|
-
if (!
|
|
244
|
-
if (
|
|
245
|
-
return
|
|
243
|
+
}, ie = async (t, e) => {
|
|
244
|
+
const { configPath: r, rootDir: o } = t, s = l.resolve(o, r);
|
|
245
|
+
if (!I(s)) {
|
|
246
|
+
if (e)
|
|
247
|
+
return g.info("配置文件不存在,使用onNotExists返回值"), e();
|
|
246
248
|
const n = `配置文件不存在 ${s}`;
|
|
247
249
|
throw new Error(n);
|
|
248
250
|
}
|
|
249
|
-
return s.endsWith(".json5") ? (
|
|
250
|
-
},
|
|
251
|
-
const { useDefaultConfig: t } = await
|
|
251
|
+
return s.endsWith(".json5") ? (g.info(`json5模式解析 ${s}`), F.parse(R(s, "utf8"))) : (g.info(`json模式解析 ${s}`), JSON.parse(R(s, "utf8")));
|
|
252
|
+
}, ce = async () => {
|
|
253
|
+
const { useDefaultConfig: t } = await H({
|
|
252
254
|
name: "useDefaultConfig",
|
|
253
255
|
type: "confirm",
|
|
254
256
|
message: "使用默认模板配置",
|
|
255
257
|
initial: !0
|
|
256
258
|
});
|
|
257
259
|
return t;
|
|
258
|
-
},
|
|
260
|
+
}, J = "package.json", D = ({
|
|
259
261
|
rootDir: t
|
|
260
262
|
}) => {
|
|
261
|
-
const
|
|
262
|
-
if (!
|
|
263
|
+
const e = l.resolve(t, J);
|
|
264
|
+
if (!I(e))
|
|
263
265
|
throw new Error(`${t}未找到package.json文件`);
|
|
264
|
-
const
|
|
265
|
-
return JSON.parse(
|
|
266
|
-
},
|
|
266
|
+
const r = R(e, "utf-8");
|
|
267
|
+
return JSON.parse(r);
|
|
268
|
+
}, pt = ({
|
|
267
269
|
rootDir: t,
|
|
268
|
-
pkgJson:
|
|
269
|
-
pkgName:
|
|
270
|
+
pkgJson: e,
|
|
271
|
+
pkgName: r,
|
|
270
272
|
isDevPkg: o
|
|
271
273
|
}) => {
|
|
272
|
-
const s =
|
|
273
|
-
let c = n == null ? void 0 : n[
|
|
274
|
+
const s = e || D({ rootDir: t }), n = o ? s.devDependencies : s.dependencies;
|
|
275
|
+
let c = n == null ? void 0 : n[r];
|
|
274
276
|
if (!c) {
|
|
275
277
|
const i = o ? s.dependencies : s.devDependencies;
|
|
276
|
-
c = i == null ? void 0 : i[
|
|
278
|
+
c = i == null ? void 0 : i[r], c && console.log(
|
|
277
279
|
p.yellow(
|
|
278
|
-
`${o ? "开发" : "生产"}依赖包${
|
|
280
|
+
`${o ? "开发" : "生产"}依赖包${r}可能错误的安装在${o ? "dependencies" : "devDependencies"}`
|
|
279
281
|
)
|
|
280
282
|
);
|
|
281
283
|
return;
|
|
282
284
|
}
|
|
283
|
-
return c || console.log(p.cyan(`依赖包${
|
|
284
|
-
},
|
|
285
|
+
return c || console.log(p.cyan(`依赖包${r}未安装`)), c;
|
|
286
|
+
}, ae = ({
|
|
285
287
|
patchConfig: t,
|
|
286
|
-
rootDir:
|
|
288
|
+
rootDir: e
|
|
287
289
|
}) => {
|
|
288
290
|
if (!t)
|
|
289
291
|
return;
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
},
|
|
293
|
-
const
|
|
292
|
+
const r = D({ rootDir: e }), o = tt(r, t), s = l.resolve(e, J);
|
|
293
|
+
b(s, JSON.stringify(o, null, 2), "utf-8");
|
|
294
|
+
}, $ = (t) => {
|
|
295
|
+
const r = u("git rev-parse --show-toplevel", {
|
|
294
296
|
cwd: t
|
|
295
297
|
}).toString();
|
|
296
|
-
if (!
|
|
298
|
+
if (!r)
|
|
297
299
|
throw new Error("获取git根目录失败");
|
|
298
|
-
return
|
|
299
|
-
},
|
|
300
|
+
return r.trim();
|
|
301
|
+
}, le = () => {
|
|
300
302
|
var t;
|
|
301
303
|
try {
|
|
302
|
-
const
|
|
304
|
+
const e = u("git symbolic-ref --short HEAD", {
|
|
303
305
|
stdio: "ignore"
|
|
304
306
|
});
|
|
305
|
-
return (t =
|
|
307
|
+
return (t = e == null ? void 0 : e.toString()) == null ? void 0 : t.trim();
|
|
306
308
|
} catch {
|
|
307
309
|
try {
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
+
const r = u("git rev-parse --short HEAD").toString().trim();
|
|
311
|
+
g.skip(`当前未指向具体某个分支, 当前commit hash: ${r}`);
|
|
310
312
|
} finally {
|
|
311
313
|
return;
|
|
312
314
|
}
|
|
313
315
|
}
|
|
314
|
-
},
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
317
|
-
const [,
|
|
316
|
+
}, ht = (t) => {
|
|
317
|
+
const e = t.match(/moving\s+from\s+(.*)\s+to\s+(.*)/);
|
|
318
|
+
if (e) {
|
|
319
|
+
const [, r, o] = e;
|
|
318
320
|
return {
|
|
319
|
-
fromBranch:
|
|
321
|
+
fromBranch: r.trim(),
|
|
320
322
|
toBranch: o.trim()
|
|
321
323
|
};
|
|
322
324
|
}
|
|
323
|
-
},
|
|
324
|
-
const
|
|
325
|
-
if ((
|
|
325
|
+
}, P = 73, dt = (t) => {
|
|
326
|
+
const r = m.statSync(t).mode;
|
|
327
|
+
if ((r & P) === P)
|
|
326
328
|
return;
|
|
327
329
|
console.log(p.blue(`${t} 没有执行权限 添加... `));
|
|
328
|
-
const o =
|
|
330
|
+
const o = r | P;
|
|
329
331
|
m.chmodSync(t, o), console.log(p.green(`${t} 添加执行权限成功`));
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
332
|
+
}, V = (t) => m.existsSync(t), N = async (t) => {
|
|
333
|
+
try {
|
|
334
|
+
return await m.promises.lstat(t), !0;
|
|
335
|
+
} catch (e) {
|
|
336
|
+
return e.code !== "ENOENT";
|
|
337
|
+
}
|
|
338
|
+
}, St = (t, e = !1) => {
|
|
339
|
+
V(t) && m.rmSync(t, { recursive: !0, force: e });
|
|
340
|
+
}, fe = async (t, e = !1) => {
|
|
341
|
+
await N(t) && await m.promises.rm(t, { recursive: !0, force: e });
|
|
342
|
+
}, yt = (t) => m.readFileSync(t, "utf-8"), Et = (t) => m.promises.readFile(t, "utf-8"), ge = (t, e) => JSON.parse(yt(t)) || e, K = async (t, e) => JSON.parse(await Et(t)) || e;
|
|
343
|
+
var S = /* @__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))(S || {});
|
|
344
|
+
const _t = "husky", Rt = ".husky", Ct = ({ rootDir: t }) => {
|
|
345
|
+
const e = $(t), r = pt({
|
|
346
|
+
rootDir: e,
|
|
347
|
+
pkgJson: D({ rootDir: e }),
|
|
348
|
+
pkgName: _t,
|
|
337
349
|
isDevPkg: !0
|
|
338
350
|
});
|
|
339
|
-
if (!
|
|
351
|
+
if (!r)
|
|
340
352
|
throw new Error("husky版本获取失败, 可能husky未安装");
|
|
341
|
-
const o =
|
|
342
|
-
return
|
|
353
|
+
const o = r.replace(/^(\^|~)/, ""), s = "<9.0.0";
|
|
354
|
+
return et.satisfies(o, s) ? (console.log(p.cyan(`${o}符合${s}`)), `#!/usr/bin/env sh
|
|
343
355
|
. "$(dirname -- "$0")/_/husky.sh"`) : (console.log(p.cyan(`${o}不符合${s}`)), "");
|
|
344
|
-
},
|
|
345
|
-
const
|
|
346
|
-
return
|
|
347
|
-
},
|
|
356
|
+
}, Ot = ({ rootDir: t }) => {
|
|
357
|
+
const e = $(t);
|
|
358
|
+
return l.resolve(e, Rt);
|
|
359
|
+
}, ue = ({
|
|
348
360
|
hookNames: t,
|
|
349
|
-
rootDir:
|
|
350
|
-
getCode:
|
|
361
|
+
rootDir: e,
|
|
362
|
+
getCode: r
|
|
351
363
|
}) => {
|
|
352
|
-
const o =
|
|
364
|
+
const o = Ot({ rootDir: e });
|
|
353
365
|
m.existsSync(o) || m.mkdirSync(o, { recursive: !0 }), t.forEach((s) => {
|
|
354
|
-
const n =
|
|
355
|
-
let i =
|
|
366
|
+
const n = l.resolve(o, s), c = m.existsSync(n);
|
|
367
|
+
let i = r(s);
|
|
356
368
|
if (c)
|
|
357
369
|
m.readFileSync(n, "utf-8").includes(i) ? console.log(
|
|
358
370
|
p.gray(`${n} ${s}相关调用 ${i} 已存在 跳过`)
|
|
@@ -363,88 +375,88 @@ ${i}
|
|
|
363
375
|
`
|
|
364
376
|
), console.log(p.green(`${n} 添加 ${s}相关调用成功`)));
|
|
365
377
|
else {
|
|
366
|
-
const
|
|
367
|
-
rootDir:
|
|
378
|
+
const f = Ct({
|
|
379
|
+
rootDir: e
|
|
368
380
|
});
|
|
369
381
|
m.writeFileSync(
|
|
370
382
|
n,
|
|
371
|
-
`${
|
|
383
|
+
`${f}
|
|
372
384
|
|
|
373
385
|
${i}
|
|
374
386
|
`,
|
|
375
387
|
"utf-8"
|
|
376
388
|
), console.log(p.green(`${n} 添加 ${s}相关调用成功`));
|
|
377
389
|
}
|
|
378
|
-
|
|
390
|
+
dt(n);
|
|
379
391
|
});
|
|
380
|
-
},
|
|
392
|
+
}, me = [
|
|
381
393
|
// HooksNameEnum.PRE_MERGE_COMMIT,
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
],
|
|
394
|
+
S.PREPARE_COMMIT_MSG,
|
|
395
|
+
S.COMMIT_MSG
|
|
396
|
+
], pe = ({
|
|
385
397
|
hookName: t,
|
|
386
|
-
rootDir:
|
|
398
|
+
rootDir: e
|
|
387
399
|
}) => {
|
|
388
|
-
const
|
|
400
|
+
const r = $(e), o = l.resolve(r, ".git");
|
|
389
401
|
switch (t) {
|
|
390
|
-
case
|
|
391
|
-
case
|
|
392
|
-
const s =
|
|
393
|
-
if (
|
|
394
|
-
return
|
|
402
|
+
case S.PREPARE_COMMIT_MSG:
|
|
403
|
+
case S.COMMIT_MSG: {
|
|
404
|
+
const s = l.resolve(o, "MERGE_MSG");
|
|
405
|
+
if (I(s))
|
|
406
|
+
return R(s, "utf-8");
|
|
395
407
|
}
|
|
396
408
|
}
|
|
397
409
|
return "";
|
|
398
|
-
},
|
|
410
|
+
}, he = ({
|
|
399
411
|
remoteAlias: t = "origin"
|
|
400
412
|
} = {}) => {
|
|
401
413
|
try {
|
|
402
|
-
const
|
|
403
|
-
let
|
|
414
|
+
const e = u("git rev-parse HEAD").toString().trim(), r = 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();
|
|
415
|
+
let f = "";
|
|
404
416
|
try {
|
|
405
|
-
|
|
417
|
+
f = u(`git config --get remote.${t}.url`).toString().trim();
|
|
406
418
|
} catch {
|
|
407
|
-
|
|
419
|
+
g.warn("git远程仓库地址获取失败或者不存在");
|
|
408
420
|
}
|
|
409
421
|
return {
|
|
410
|
-
lastHash:
|
|
411
|
-
lastCommitter:
|
|
412
|
-
lastCommitterPinYin:
|
|
413
|
-
style:
|
|
422
|
+
lastHash: e,
|
|
423
|
+
lastCommitter: r,
|
|
424
|
+
lastCommitterPinYin: _(r, {
|
|
425
|
+
style: _.STYLE_NORMAL,
|
|
414
426
|
heteronym: !1
|
|
415
427
|
}).join(""),
|
|
416
428
|
lastCommitEmail: o,
|
|
417
429
|
lastCommitMsg: s,
|
|
418
430
|
userName: n,
|
|
419
|
-
userNamePinYin:
|
|
420
|
-
style:
|
|
431
|
+
userNamePinYin: _(n, {
|
|
432
|
+
style: _.STYLE_NORMAL,
|
|
421
433
|
heteronym: !1
|
|
422
434
|
}).join(""),
|
|
423
435
|
userEmail: c,
|
|
424
436
|
branchName: i,
|
|
425
|
-
remoteInfo:
|
|
437
|
+
remoteInfo: f ? {
|
|
426
438
|
alias: t,
|
|
427
|
-
url:
|
|
439
|
+
url: f
|
|
428
440
|
} : void 0
|
|
429
441
|
};
|
|
430
|
-
} catch (
|
|
431
|
-
throw
|
|
442
|
+
} catch (e) {
|
|
443
|
+
throw g.error("获取git最后提交信息失败"), e;
|
|
432
444
|
}
|
|
433
|
-
},
|
|
434
|
-
const
|
|
435
|
-
if (
|
|
436
|
-
const [, i,
|
|
445
|
+
}, Y = (t = "") => {
|
|
446
|
+
const e = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+into\s+['|"](.+)['|"]\s*/i, r = t.match(e);
|
|
447
|
+
if (r) {
|
|
448
|
+
const [, i, f] = r;
|
|
437
449
|
return {
|
|
438
450
|
fromBranch: i,
|
|
439
|
-
toBranch:
|
|
451
|
+
toBranch: f
|
|
440
452
|
};
|
|
441
453
|
}
|
|
442
454
|
const o = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+of\s+.+\s+into\s+['|"](.+)['|"]\s*/i, s = t.match(o);
|
|
443
455
|
if (s) {
|
|
444
|
-
const [, i,
|
|
456
|
+
const [, i, f] = s;
|
|
445
457
|
return {
|
|
446
458
|
fromBranch: i,
|
|
447
|
-
toBranch:
|
|
459
|
+
toBranch: f
|
|
448
460
|
};
|
|
449
461
|
}
|
|
450
462
|
const n = /\s*Merge\s+branch\s+['|"](.+)['|"](\s+of)?\s*/i, c = t.match(n);
|
|
@@ -454,18 +466,18 @@ ${i}
|
|
|
454
466
|
fromBranch: i
|
|
455
467
|
};
|
|
456
468
|
}
|
|
457
|
-
},
|
|
458
|
-
if (t.startsWith(
|
|
469
|
+
}, vt = (t) => {
|
|
470
|
+
if (t.startsWith(T.MERGE))
|
|
459
471
|
return {
|
|
460
|
-
fromBranch: t.replace(
|
|
472
|
+
fromBranch: t.replace(T.MERGE, "").trim()
|
|
461
473
|
};
|
|
462
|
-
},
|
|
474
|
+
}, de = () => {
|
|
463
475
|
const t = process.env.GIT_REFLOG_ACTION || "";
|
|
464
476
|
if (!t)
|
|
465
477
|
return;
|
|
466
|
-
const
|
|
467
|
-
if (
|
|
468
|
-
const [, n] =
|
|
478
|
+
const e = /merge\s+([^\s]+)\s*/i, r = t.match(e);
|
|
479
|
+
if (r) {
|
|
480
|
+
const [, n] = r;
|
|
469
481
|
return {
|
|
470
482
|
fromBranch: n
|
|
471
483
|
};
|
|
@@ -478,20 +490,20 @@ ${i}
|
|
|
478
490
|
};
|
|
479
491
|
}
|
|
480
492
|
};
|
|
481
|
-
var
|
|
482
|
-
const
|
|
493
|
+
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 || {});
|
|
494
|
+
const L = "__GIT_REPLACE_MARK__", v = {
|
|
483
495
|
stringify(t) {
|
|
484
|
-
return JSON.stringify(t).replace(/"/g,
|
|
496
|
+
return JSON.stringify(t).replace(/"/g, L);
|
|
485
497
|
},
|
|
486
498
|
parse(t) {
|
|
487
|
-
return JSON.parse(t.replace(new RegExp(
|
|
499
|
+
return JSON.parse(t.replace(new RegExp(L, "g"), '"'));
|
|
488
500
|
}
|
|
489
|
-
},
|
|
501
|
+
}, Se = ({
|
|
490
502
|
count: t = 100
|
|
491
503
|
} = {}) => {
|
|
492
504
|
if (t <= 0)
|
|
493
505
|
return [];
|
|
494
|
-
const
|
|
506
|
+
const e = {
|
|
495
507
|
hash: "%H",
|
|
496
508
|
/** 提交信息 */
|
|
497
509
|
message: "%s",
|
|
@@ -509,24 +521,24 @@ const j = "__GIT_REPLACE_MARK__", $ = {
|
|
|
509
521
|
commitTime: "%ci"
|
|
510
522
|
};
|
|
511
523
|
return u(
|
|
512
|
-
`git --no-pager log --oneline -n ${t} --pretty=format:"${
|
|
513
|
-
|
|
524
|
+
`git --no-pager log --oneline -n ${t} --pretty=format:"${v.stringify(
|
|
525
|
+
e
|
|
514
526
|
)}"`
|
|
515
527
|
).toString().split(`
|
|
516
528
|
`).map((n) => {
|
|
517
|
-
const c =
|
|
529
|
+
const c = v.parse(n);
|
|
518
530
|
return {
|
|
519
531
|
...c,
|
|
520
|
-
mergeInfo:
|
|
532
|
+
mergeInfo: Y(c.message)
|
|
521
533
|
};
|
|
522
534
|
});
|
|
523
|
-
},
|
|
535
|
+
}, ye = ({
|
|
524
536
|
count: t = 100,
|
|
525
|
-
filterItem:
|
|
537
|
+
filterItem: e = () => !0
|
|
526
538
|
} = {}) => {
|
|
527
539
|
if (t <= 0)
|
|
528
540
|
return [];
|
|
529
|
-
const
|
|
541
|
+
const r = {
|
|
530
542
|
hash: "%H",
|
|
531
543
|
fullMessage: "%gs",
|
|
532
544
|
committer: "%cn",
|
|
@@ -534,139 +546,200 @@ const j = "__GIT_REPLACE_MARK__", $ = {
|
|
|
534
546
|
commitTime: "%ci"
|
|
535
547
|
};
|
|
536
548
|
return u(
|
|
537
|
-
`git --no-pager reflog -n ${t} --pretty=format:"${
|
|
538
|
-
|
|
549
|
+
`git --no-pager reflog -n ${t} --pretty=format:"${v.stringify(
|
|
550
|
+
r
|
|
539
551
|
)}"`
|
|
540
552
|
).toString().split(`
|
|
541
|
-
`).map((i) =>
|
|
542
|
-
const { fullMessage:
|
|
543
|
-
let
|
|
553
|
+
`).map((i) => v.parse(i)).filter(e).map((i) => {
|
|
554
|
+
const { fullMessage: f, ...a } = i, h = ":", [y] = f.split(h, 1), M = f.slice(`${y}${h}`.length), d = y.trim(), E = M.trim();
|
|
555
|
+
let A, B, X;
|
|
544
556
|
if (d.startsWith(
|
|
545
557
|
"checkout"
|
|
546
558
|
/* CHECKOUT */
|
|
547
559
|
))
|
|
548
|
-
B =
|
|
560
|
+
B = ht(E);
|
|
549
561
|
else if (d.startsWith(
|
|
550
562
|
"merge"
|
|
551
563
|
/* MERGE */
|
|
552
564
|
))
|
|
553
|
-
|
|
565
|
+
A = vt(d);
|
|
554
566
|
else if (d.startsWith(
|
|
555
567
|
"commit (merge)"
|
|
556
568
|
/* COMMIT_MERGE */
|
|
557
569
|
)) {
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
`${i.hash} 是合并提交 但是未从提交信息(${
|
|
561
|
-
),
|
|
570
|
+
const G = Y(E);
|
|
571
|
+
G || g.warn(
|
|
572
|
+
`${i.hash} 是合并提交 但是未从提交信息(${E})中检测到合并分支信息,推测手动更改了提交内容`
|
|
573
|
+
), A = G;
|
|
562
574
|
}
|
|
563
575
|
return {
|
|
564
|
-
...
|
|
576
|
+
...a,
|
|
565
577
|
type: d,
|
|
566
|
-
message:
|
|
567
|
-
mergeInfo:
|
|
578
|
+
message: E,
|
|
579
|
+
mergeInfo: A,
|
|
568
580
|
checkoutInfo: B,
|
|
569
|
-
rebaseInfo:
|
|
581
|
+
rebaseInfo: X
|
|
570
582
|
};
|
|
571
583
|
});
|
|
572
|
-
},
|
|
573
|
-
const
|
|
584
|
+
}, Ee = (t) => {
|
|
585
|
+
const e = $(t), r = l.resolve(e, ".git"), o = l.resolve(r, "rebase-merge");
|
|
574
586
|
if (m.existsSync(o))
|
|
575
587
|
return !0;
|
|
576
|
-
const s =
|
|
588
|
+
const s = l.resolve(r, "rebase-apply");
|
|
577
589
|
if (m.existsSync(s))
|
|
578
590
|
return !0;
|
|
579
|
-
const n =
|
|
591
|
+
const n = l.resolve(r, "REBASE_HEAD");
|
|
580
592
|
return !!m.existsSync(n);
|
|
581
|
-
},
|
|
593
|
+
}, _e = ({
|
|
582
594
|
branchName: t,
|
|
583
|
-
version:
|
|
584
|
-
remoteInfo:
|
|
595
|
+
version: e,
|
|
596
|
+
remoteInfo: r
|
|
585
597
|
}) => {
|
|
586
|
-
|
|
598
|
+
r && (u(`git push ${r.alias} v${e}`, {
|
|
587
599
|
stdio: "inherit"
|
|
588
|
-
}), u(`git push ${
|
|
600
|
+
}), u(`git push ${r.alias} ${t}`, {
|
|
589
601
|
stdio: "inherit"
|
|
590
602
|
}));
|
|
591
|
-
},
|
|
592
|
-
|
|
593
|
-
|
|
603
|
+
}, It = (t) => /^https?:\/\//.test(t), $t = (t) => /^git@/.test(t), Re = (t) => {
|
|
604
|
+
const { hostname: e, pathname: r } = new URL(t);
|
|
605
|
+
return `git@${e}:${r.replace("/", "")}`;
|
|
606
|
+
}, W = ".done-coding", Mt = `${W}/cli/assets-config`, At = "assets", Pt = "index.json", bt = `${W}/config.json`, wt = "https://gitee.com/justsosu/done-coding-cli-assets-config.git", Tt = ({
|
|
607
|
+
dir: t,
|
|
608
|
+
fn: e,
|
|
609
|
+
endClear: r = !0,
|
|
610
|
+
exitClear: o = !0
|
|
594
611
|
}) => {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
et(),
|
|
598
|
-
e
|
|
599
|
-
);
|
|
600
|
-
if (y(o))
|
|
601
|
-
return console.log(
|
|
602
|
-
p.red(`${o} 已存在,请手动删除该目录再试`)
|
|
603
|
-
), process.exit(1);
|
|
612
|
+
if (V(t))
|
|
613
|
+
return console.log(p.red(`${t} 已存在,请手动删除该目录再试`)), process.exit(1);
|
|
604
614
|
const s = () => {
|
|
605
|
-
|
|
615
|
+
console.log("正在清理临时目录...", t), St(t);
|
|
606
616
|
};
|
|
617
|
+
o && process.once("exit", () => {
|
|
618
|
+
console.log("发现进程退出,正在清理临时目录...", t), s();
|
|
619
|
+
});
|
|
607
620
|
let n;
|
|
608
621
|
try {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
c
|
|
613
|
-
);
|
|
614
|
-
n = JSON.parse(m.readFileSync(a, "utf-8")), process.once("exit", () => {
|
|
615
|
-
y(o) && (console.log("发现进程退出,正在清理临时目录..."), s());
|
|
616
|
-
}), await r({
|
|
617
|
-
repoUrl: x,
|
|
618
|
-
config: n,
|
|
619
|
-
cliConfigFileRelativePath: c,
|
|
620
|
-
cliConfigDirRelativePath: i,
|
|
621
|
-
configTemporaryDir: o
|
|
622
|
-
});
|
|
623
|
-
} finally {
|
|
624
|
-
s();
|
|
622
|
+
n = e(t);
|
|
623
|
+
} catch (c) {
|
|
624
|
+
throw r && s(), c;
|
|
625
625
|
}
|
|
626
|
-
return n;
|
|
626
|
+
return r && (n instanceof Promise ? n.finally(s) : s()), n;
|
|
627
627
|
};
|
|
628
|
+
var Dt = /* @__PURE__ */ ((t) => (t.ASSETS_CONFIG_REPO_URL = "ASSETS_CONFIG_REPO_URL", t))(Dt || {});
|
|
629
|
+
const Nt = (t) => l.resolve(
|
|
630
|
+
rt(),
|
|
631
|
+
Mt,
|
|
632
|
+
`${t}-${ot()}`
|
|
633
|
+
), Bt = () => l.resolve(st(), bt), Gt = async () => {
|
|
634
|
+
const t = Bt();
|
|
635
|
+
console.log("读取全局配置:", t);
|
|
636
|
+
const e = {
|
|
637
|
+
ASSETS_CONFIG_REPO_URL: wt
|
|
638
|
+
};
|
|
639
|
+
try {
|
|
640
|
+
if (await N(t)) {
|
|
641
|
+
const r = await K(t, {});
|
|
642
|
+
Object.entries(r).forEach(([o, s]) => {
|
|
643
|
+
e[o] = s;
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
} catch {
|
|
647
|
+
}
|
|
648
|
+
return console.log("done-coding-cli 全局配置:", e), e;
|
|
649
|
+
}, Lt = async (t) => {
|
|
650
|
+
if (console.log("资产配置仓库临时目录:", t), await N(t))
|
|
651
|
+
return console.log(
|
|
652
|
+
p.red(`${t} 已存在,请手动删除该目录再试`)
|
|
653
|
+
), process.exit(1);
|
|
654
|
+
const {
|
|
655
|
+
[
|
|
656
|
+
"ASSETS_CONFIG_REPO_URL"
|
|
657
|
+
/* ASSETS_CONFIG_REPO_URL */
|
|
658
|
+
]: e
|
|
659
|
+
} = await Gt();
|
|
660
|
+
return $t(e) || It(e) ? (console.log("远程仓库拉取配置...", e), u(`git clone ${e} ${t} --depth=1`)) : (m.mkdirSync(t, { recursive: !0 }), u(`cp -r ${e}/ ${t}/`)), {
|
|
661
|
+
assetConfigRepoUrl: e
|
|
662
|
+
};
|
|
663
|
+
}, Ce = async ({
|
|
664
|
+
moduleName: t,
|
|
665
|
+
onSuccess: e
|
|
666
|
+
}) => (console.log(p.blue(`拉取${t}配置,请稍等...`)), Tt({
|
|
667
|
+
// 资源配置仓库临时文件夹
|
|
668
|
+
dir: Nt(t),
|
|
669
|
+
fn: async (r) => {
|
|
670
|
+
const { assetConfigRepoUrl: o } = await Lt(r), s = l.join(
|
|
671
|
+
At,
|
|
672
|
+
t
|
|
673
|
+
), n = l.join(
|
|
674
|
+
s,
|
|
675
|
+
Pt
|
|
676
|
+
), c = l.resolve(r, n), i = await K(c);
|
|
677
|
+
return await e({
|
|
678
|
+
repoUrl: o,
|
|
679
|
+
config: i,
|
|
680
|
+
moduleDirFileRelativePath: s,
|
|
681
|
+
moduleEntryFileRelativePath: n,
|
|
682
|
+
assetsConfigRepoTempDir: r
|
|
683
|
+
}), i;
|
|
684
|
+
}
|
|
685
|
+
}));
|
|
628
686
|
export {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
me as
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
687
|
+
Dt as DoneCodingCliGlobalConfigKeyEnum,
|
|
688
|
+
ct as EditorTypeEnum,
|
|
689
|
+
T as GitRefLogTypeEnum,
|
|
690
|
+
S as HooksNameEnum,
|
|
691
|
+
me as SUPPORT_GET_COMMIT_BY_HOOKS_NAMES,
|
|
692
|
+
Ge as _curry,
|
|
693
|
+
Te as _get,
|
|
694
|
+
Ne as _set,
|
|
695
|
+
ue as addHuskyHooks,
|
|
696
|
+
ae as addPackageConfig,
|
|
697
|
+
Tt as applyUseTempDir,
|
|
698
|
+
V as assetIsExits,
|
|
699
|
+
N as assetIsExitsAsync,
|
|
700
|
+
Ie as chalk,
|
|
701
|
+
Ee as checkCurrentIsRebasing,
|
|
702
|
+
re as createMainCommand,
|
|
703
|
+
se as createSubcommand,
|
|
704
|
+
te as decryptAES,
|
|
705
|
+
Zt as encryptAES,
|
|
706
|
+
dt as fileAddX,
|
|
707
|
+
Nt as getCliModuleTempDir,
|
|
708
|
+
pe as getCommitByHookName,
|
|
709
|
+
oe as getConfigFileCommonOptions,
|
|
710
|
+
Se as getCurrentBranchLastCommitList,
|
|
711
|
+
le as getCurrentBranchName,
|
|
712
|
+
at as getEditorType,
|
|
713
|
+
he as getGitLastCommitInfo,
|
|
714
|
+
$ as getGitProjectDir,
|
|
715
|
+
ye as getLastReflogList,
|
|
716
|
+
D as getPackageJson,
|
|
717
|
+
pt as getRelyPkgVersion,
|
|
718
|
+
ut as getRootDirOptions,
|
|
719
|
+
ee as getRootScriptName,
|
|
720
|
+
ce as getUseDefaultConfig,
|
|
721
|
+
Re as http2sshGitUrl,
|
|
722
|
+
mt as initConfigFile,
|
|
723
|
+
ne as initHandlerCommon,
|
|
724
|
+
It as isHttpGitUrl,
|
|
725
|
+
$t as isSshGitUrl,
|
|
726
|
+
Ae as json5,
|
|
727
|
+
g as log,
|
|
728
|
+
Qt as lookForParentTarget,
|
|
729
|
+
gt as openFileInEditor,
|
|
730
|
+
_e as pushGitPublishInfoToRemote,
|
|
731
|
+
Ce as readCliModuleAssetsConfig,
|
|
732
|
+
ie as readConfigFile,
|
|
733
|
+
yt as readFile,
|
|
734
|
+
Et as readFileAsync,
|
|
735
|
+
ge as readJsonFile,
|
|
736
|
+
K as readJsonFileAsync,
|
|
737
|
+
St as removeAsset,
|
|
738
|
+
fe as removeAssetAsync,
|
|
739
|
+
ht as resolveCheckoutInfoByRefInfo,
|
|
740
|
+
Y as resolveMergeInfoByCommitMsg,
|
|
741
|
+
de as resolveMergeInfoByGitReflogAction,
|
|
742
|
+
vt as resolveMergeInfoByRefType,
|
|
743
|
+
be as uuidv4,
|
|
744
|
+
H as xPrompts
|
|
672
745
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "cli utils",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@types/pinyin": "^2.10.0",
|
|
48
48
|
"@types/prompts": "^2.4.6",
|
|
49
49
|
"@types/semver": "^7.5.3",
|
|
50
|
+
"@types/uuid": "^10.0.0",
|
|
50
51
|
"@types/yargs": "^17.0.28",
|
|
51
52
|
"rimraf": "^6.0.1",
|
|
52
53
|
"typescript": "^5.2.2",
|
|
@@ -66,7 +67,8 @@
|
|
|
66
67
|
"pinyin": "^2.11.2",
|
|
67
68
|
"prompts": "^2.4.2",
|
|
68
69
|
"semver": "^7.5.4",
|
|
70
|
+
"uuid": "^11.1.0",
|
|
69
71
|
"yargs": "^17.7.2"
|
|
70
72
|
},
|
|
71
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "e68f726aa899f75c4d294b11620f343c953a74c3"
|
|
72
74
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import prompts from 'prompts';
|
|
|
15
15
|
import { PromptType } from 'prompts';
|
|
16
16
|
import { ValueOrFunc as PromptValueOrFunc } from 'prompts';
|
|
17
17
|
import _set from 'lodash.set';
|
|
18
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
18
19
|
import yargs from 'yargs';
|
|
19
20
|
import type { Argv as YargsArgv } from 'yargs';
|
|
20
21
|
import type { Options as YargsOptions } from 'yargs';
|
|
@@ -34,8 +35,31 @@ export declare const addPackageConfig: ({ patchConfig, rootDir, }: {
|
|
|
34
35
|
rootDir: string;
|
|
35
36
|
}) => void;
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* 申请使用临时目录
|
|
40
|
+
* ---
|
|
41
|
+
* !!! 临时目录 默认 执行完成及退出信号发出时 清理临时文件
|
|
42
|
+
*/
|
|
43
|
+
export declare const applyUseTempDir: <T>({ dir, fn, endClear, exitClear, }: {
|
|
44
|
+
dir: string;
|
|
45
|
+
fn: (dir: string) => T;
|
|
46
|
+
/** 结束时移除临时目录 */
|
|
47
|
+
endClear?: boolean | undefined;
|
|
48
|
+
/** 退出信号是否移除临时目录 */
|
|
49
|
+
exitClear?: boolean | undefined;
|
|
50
|
+
}) => T;
|
|
51
|
+
|
|
37
52
|
export { ArgumentsCamelCase }
|
|
38
53
|
|
|
54
|
+
/** 文件或文件夹是否存在(同步) */
|
|
55
|
+
export declare const assetIsExits: (assetPath: string) => boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 检查路径是否存在(包括文件、目录、符号链接)
|
|
59
|
+
* 异步版本,行为与 fs.existsSync 一致
|
|
60
|
+
*/
|
|
61
|
+
export declare const assetIsExitsAsync: (path: string) => Promise<boolean>;
|
|
62
|
+
|
|
39
63
|
export { chalk }
|
|
40
64
|
|
|
41
65
|
/** 检测当前正在变基 */
|
|
@@ -100,6 +124,22 @@ export declare function decryptAES({ encryptedText, secretKey, }: {
|
|
|
100
124
|
secretKey: string;
|
|
101
125
|
}): string;
|
|
102
126
|
|
|
127
|
+
/** done-coding-cli 全局配置 */
|
|
128
|
+
export declare type DoneCodingCliGlobalConfig = {
|
|
129
|
+
[K in DoneCodingCliGlobalConfigKeyEnum]: string;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** done-coding-cli 全局配置 key 枚举 */
|
|
133
|
+
export declare enum DoneCodingCliGlobalConfigKeyEnum {
|
|
134
|
+
/**
|
|
135
|
+
* 资产配置仓库
|
|
136
|
+
* ---
|
|
137
|
+
* 1. http ssh则认为远程仓库 临时拉取到本地临时目录中
|
|
138
|
+
* 2. 若非上述 则认为本地【绝对】路径
|
|
139
|
+
*/
|
|
140
|
+
ASSETS_CONFIG_REPO_URL = "ASSETS_CONFIG_REPO_URL"
|
|
141
|
+
}
|
|
142
|
+
|
|
103
143
|
/** 编辑器类型枚举 */
|
|
104
144
|
export declare enum EditorTypeEnum {
|
|
105
145
|
/** vscode */
|
|
@@ -121,6 +161,9 @@ export declare const fileAddX: (filePath: string) => void;
|
|
|
121
161
|
|
|
122
162
|
export { _get }
|
|
123
163
|
|
|
164
|
+
/** 获取cli模块【临时】目录[绝对路径] */
|
|
165
|
+
export declare const getCliModuleTempDir: (moduleName: string) => string;
|
|
166
|
+
|
|
124
167
|
/** 根据hookName获取(将)提交的信息 */
|
|
125
168
|
export declare const getCommitByHookName: ({ hookName, rootDir, }: {
|
|
126
169
|
hookName: SupportGetCommitByHookName;
|
|
@@ -366,6 +409,9 @@ export declare enum HooksNameEnum {
|
|
|
366
409
|
PRE_PUSH = "pre-push"
|
|
367
410
|
}
|
|
368
411
|
|
|
412
|
+
/** http 地址 转换为 ssh 地址 */
|
|
413
|
+
export declare const http2sshGitUrl: (httpUrl: string) => string;
|
|
414
|
+
|
|
369
415
|
/** 初始化配置文件 */
|
|
370
416
|
export declare const initConfigFile: <T>(content: T, argv: CliHandlerArgv<InitConfigFileOptions>) => Promise<string>;
|
|
371
417
|
|
|
@@ -379,6 +425,12 @@ export declare const initHandlerCommon: <T>(content: T, argv: CliHandlerArgv<Ini
|
|
|
379
425
|
edit?: boolean | undefined;
|
|
380
426
|
}) => Promise<void>;
|
|
381
427
|
|
|
428
|
+
/** 是http git地址 */
|
|
429
|
+
export declare const isHttpGitUrl: (url: string) => boolean;
|
|
430
|
+
|
|
431
|
+
/** 是 ssh git地址 */
|
|
432
|
+
export declare const isSshGitUrl: (url: string) => boolean;
|
|
433
|
+
|
|
382
434
|
export { json5 }
|
|
383
435
|
|
|
384
436
|
/** 日志 */
|
|
@@ -461,19 +513,24 @@ export declare const pushGitPublishInfoToRemote: ({ branchName, version, remoteI
|
|
|
461
513
|
remoteInfo?: GitRemoteInfo | undefined;
|
|
462
514
|
}) => void;
|
|
463
515
|
|
|
464
|
-
/**
|
|
465
|
-
export declare const
|
|
516
|
+
/** 读取(某个模块)配置 */
|
|
517
|
+
export declare const readCliModuleAssetsConfig: <R>({ moduleName, onSuccess, }: {
|
|
466
518
|
moduleName: string;
|
|
467
519
|
onSuccess: (params: {
|
|
520
|
+
/**
|
|
521
|
+
* 资产配置仓库地址
|
|
522
|
+
* ----
|
|
523
|
+
* 可能是 http ssh 也可能是本地【绝对】文件路径
|
|
524
|
+
*/
|
|
468
525
|
repoUrl: string;
|
|
469
|
-
/**
|
|
470
|
-
|
|
471
|
-
/**
|
|
472
|
-
|
|
526
|
+
/** 资产配置文件临时目录[绝对路径] */
|
|
527
|
+
assetsConfigRepoTempDir: string;
|
|
528
|
+
/** 模块对应的资产配置仓库(相对路径) */
|
|
529
|
+
moduleDirFileRelativePath: string;
|
|
530
|
+
/** 模块对应的资产配置入口文件(相对路径) */
|
|
531
|
+
moduleEntryFileRelativePath: string;
|
|
473
532
|
/** 配置文件内容 */
|
|
474
533
|
config: R;
|
|
475
|
-
/** 配置临时目录 */
|
|
476
|
-
configTemporaryDir: string;
|
|
477
534
|
}) => void | Promise<void>;
|
|
478
535
|
}) => Promise<R>;
|
|
479
536
|
|
|
@@ -483,6 +540,32 @@ export declare const readConfigFile: <T>(options: ReadConfigFileOptions, onNotEx
|
|
|
483
540
|
/** 读取配置文件选项 */
|
|
484
541
|
export declare type ReadConfigFileOptions = ConfigFileCommonOptions;
|
|
485
542
|
|
|
543
|
+
/** 读取文件[同步] */
|
|
544
|
+
export declare const readFile: (assetPath: string) => string;
|
|
545
|
+
|
|
546
|
+
/** 读取文件[异步] */
|
|
547
|
+
export declare const readFileAsync: (assetPath: string) => Promise<string>;
|
|
548
|
+
|
|
549
|
+
/** 读取json文件[同步] */
|
|
550
|
+
export declare const readJsonFile: <T>(assetPath: string, defaultValue?: T | undefined) => T;
|
|
551
|
+
|
|
552
|
+
/** 读取json文件[异步] */
|
|
553
|
+
export declare const readJsonFileAsync: <T>(assetPath: string, defaultValue?: T | undefined) => Promise<T>;
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* 删除资源 (同步)
|
|
557
|
+
* ---
|
|
558
|
+
* 无论文件还是文件夹
|
|
559
|
+
*/
|
|
560
|
+
export declare const removeAsset: (assetPath: string, force?: boolean) => void;
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* 删除资源 (异步)
|
|
564
|
+
* ---
|
|
565
|
+
* 无论文件还是文件夹
|
|
566
|
+
*/
|
|
567
|
+
export declare const removeAssetAsync: (assetPath: string, force?: boolean) => Promise<void>;
|
|
568
|
+
|
|
486
569
|
/** 解析checkoutInfo */
|
|
487
570
|
export declare const resolveCheckoutInfoByRefInfo: (message: string) => {
|
|
488
571
|
fromBranch: string;
|
|
@@ -511,8 +594,10 @@ export declare const SUPPORT_GET_COMMIT_BY_HOOKS_NAMES: readonly [HooksNameEnum.
|
|
|
511
594
|
|
|
512
595
|
export declare type SupportGetCommitByHookName = (typeof SUPPORT_GET_COMMIT_BY_HOOKS_NAMES)[number];
|
|
513
596
|
|
|
597
|
+
export { uuidv4 }
|
|
598
|
+
|
|
514
599
|
/** prompts 拓展 */
|
|
515
|
-
export declare const xPrompts: (questions: prompts.PromptObject<
|
|
600
|
+
export declare const xPrompts: <T extends string = string>(questions: prompts.PromptObject<T> | prompts.PromptObject<T>[], options?: prompts.Options | undefined) => Promise<prompts.Answers<T>>;
|
|
516
601
|
|
|
517
602
|
export { YargsArgv }
|
|
518
603
|
|