@done-coding/cli-utils 0.4.0-alpha.0 → 0.6.0-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 +324 -140
- package/package.json +8 -2
- package/types/cli-config.d.ts +15 -0
- package/types/file-operate.d.ts +2 -0
- package/types/git.d.ts +73 -0
- package/types/husky.d.ts +16 -0
- package/types/index.d.ts +4 -0
- package/types/package-json.d.ts +21 -0
package/es/index.mjs
CHANGED
|
@@ -1,50 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import { default as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { hideBin as
|
|
10
|
-
import { execSync as
|
|
11
|
-
import
|
|
2
|
+
import u from "chalk";
|
|
3
|
+
import { default as Ae } from "chalk";
|
|
4
|
+
import g from "node:path";
|
|
5
|
+
import d, { existsSync as p, mkdirSync as j, writeFileSync as S, readFileSync as $, rmSync as A } from "node:fs";
|
|
6
|
+
import y from "crypto";
|
|
7
|
+
import I from "prompts";
|
|
8
|
+
import N from "yargs";
|
|
9
|
+
import { hideBin as M } from "yargs/helpers";
|
|
10
|
+
import { execSync as f } from "node:child_process";
|
|
11
|
+
import k from "json5";
|
|
12
12
|
export * from "json5";
|
|
13
|
-
import { default as
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
import { default as Me } from "json5";
|
|
14
|
+
import Y from "lodash.merge";
|
|
15
|
+
import m from "pinyin";
|
|
16
|
+
import J from "semver";
|
|
17
|
+
import { tmpdir as L } from "node:os";
|
|
18
|
+
import { default as Je } from "lodash.get";
|
|
19
|
+
import { default as Ge } from "lodash.set";
|
|
20
|
+
import { default as Be } from "lodash.curry";
|
|
21
|
+
const a = Object.assign(
|
|
22
|
+
(e, ...o) => console.log(...o.map((t) => u[e](t))),
|
|
19
23
|
{
|
|
20
24
|
/** 成功 */
|
|
21
|
-
success: (...e) =>
|
|
25
|
+
success: (...e) => a("green", ...e),
|
|
22
26
|
/** /步骤 */
|
|
23
|
-
stage: (...e) =>
|
|
27
|
+
stage: (...e) => a("blue", ...e),
|
|
24
28
|
/** 提示信息 */
|
|
25
|
-
info: (...e) =>
|
|
29
|
+
info: (...e) => a("cyan", ...e),
|
|
26
30
|
/** 警告 */
|
|
27
|
-
warn: (...e) =>
|
|
31
|
+
warn: (...e) => a("yellow", ...e),
|
|
28
32
|
/** 错误 */
|
|
29
|
-
error: (...e) =>
|
|
33
|
+
error: (...e) => a("red", ...e),
|
|
30
34
|
/** 跳过 */
|
|
31
|
-
skip: (...e) =>
|
|
35
|
+
skip: (...e) => a("gray", ...e)
|
|
32
36
|
}
|
|
33
|
-
),
|
|
37
|
+
), Se = (e, {
|
|
34
38
|
/** 当前目录 */
|
|
35
|
-
currentDir:
|
|
39
|
+
currentDir: o = process.cwd(),
|
|
36
40
|
/** 优先找最远的父目录 */
|
|
37
41
|
isFindFarthest: t = !0
|
|
38
42
|
} = {}) => {
|
|
39
|
-
const
|
|
40
|
-
for (;
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
return
|
|
43
|
+
const r = g.resolve(o).split(g.sep).map((n, s, c) => s ? g.join(c.slice(0, s).join(g.sep), n) : n);
|
|
44
|
+
for (; r.length; ) {
|
|
45
|
+
const n = t ? r.shift() : r.pop(), s = g.join(n, e);
|
|
46
|
+
if (d.existsSync(s))
|
|
47
|
+
return n;
|
|
44
48
|
}
|
|
45
|
-
},
|
|
46
|
-
function
|
|
47
|
-
return
|
|
49
|
+
}, w = "aes-256-cbc", _ = 16, h = "hex", v = ":";
|
|
50
|
+
function P(e) {
|
|
51
|
+
return y.pbkdf2Sync(
|
|
48
52
|
e,
|
|
49
53
|
"done-coding-cli-salt",
|
|
50
54
|
// 使用固定的盐值
|
|
@@ -55,84 +59,84 @@ function $(e) {
|
|
|
55
59
|
"sha256"
|
|
56
60
|
);
|
|
57
61
|
}
|
|
58
|
-
function
|
|
62
|
+
function $e({
|
|
59
63
|
text: e,
|
|
60
|
-
secretKey:
|
|
64
|
+
secretKey: o
|
|
61
65
|
}) {
|
|
62
66
|
try {
|
|
63
|
-
const t =
|
|
64
|
-
let s =
|
|
65
|
-
s = Buffer.concat([s,
|
|
66
|
-
const
|
|
67
|
-
return `${
|
|
67
|
+
const t = P(o), r = y.randomBytes(_), n = y.createCipheriv(w, t, r);
|
|
68
|
+
let s = n.update(e);
|
|
69
|
+
s = Buffer.concat([s, n.final()]);
|
|
70
|
+
const c = r.toString(h), i = s.toString(h);
|
|
71
|
+
return `${c}${v}${i}`;
|
|
68
72
|
} catch (t) {
|
|
69
|
-
return
|
|
73
|
+
return a.error(
|
|
70
74
|
`加密失败: ${t instanceof Error ? t.message : String(t)}`
|
|
71
75
|
), "";
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
|
-
function
|
|
78
|
+
function ve({
|
|
75
79
|
encryptedText: e,
|
|
76
|
-
secretKey:
|
|
80
|
+
secretKey: o
|
|
77
81
|
}) {
|
|
78
82
|
try {
|
|
79
|
-
if (!e.includes(
|
|
83
|
+
if (!e.includes(v))
|
|
80
84
|
return "";
|
|
81
|
-
const t =
|
|
82
|
-
if (
|
|
85
|
+
const t = P(o), [r, n] = e.split(v);
|
|
86
|
+
if (r.length !== _ * 2)
|
|
83
87
|
return "";
|
|
84
|
-
const s = Buffer.from(
|
|
85
|
-
let
|
|
86
|
-
return
|
|
88
|
+
const s = Buffer.from(r, h), c = Buffer.from(n, h), i = y.createDecipheriv(w, t, s);
|
|
89
|
+
let l = i.update(c);
|
|
90
|
+
return l = Buffer.concat([l, i.final()]), l.toString();
|
|
87
91
|
} catch (t) {
|
|
88
|
-
return
|
|
92
|
+
return a.error(
|
|
89
93
|
`解密失败: ${t instanceof Error ? t.message : String(t)}`
|
|
90
94
|
), "";
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
|
-
const
|
|
94
|
-
const [
|
|
95
|
-
return
|
|
96
|
-
onCancel(
|
|
97
|
-
return
|
|
97
|
+
const D = (...e) => {
|
|
98
|
+
const [o, t = {}] = e;
|
|
99
|
+
return I(o, {
|
|
100
|
+
onCancel(r) {
|
|
101
|
+
return a.error(`退出${r == null ? void 0 : r.name}输入`), process.exit(1);
|
|
98
102
|
},
|
|
99
103
|
...t
|
|
100
104
|
});
|
|
101
|
-
},
|
|
102
|
-
e ?
|
|
103
|
-
},
|
|
104
|
-
const e =
|
|
105
|
-
return
|
|
106
|
-
},
|
|
107
|
-
usage:
|
|
105
|
+
}, G = (e, o) => {
|
|
106
|
+
e ? a.error(e) : a.error(o.message), o != null && o.stack && a.error(o.stack), process.exit(1);
|
|
107
|
+
}, V = () => {
|
|
108
|
+
const e = M(process.argv);
|
|
109
|
+
return N(e);
|
|
110
|
+
}, x = (e, {
|
|
111
|
+
usage: o,
|
|
108
112
|
version: t,
|
|
109
|
-
demandCommandCount:
|
|
110
|
-
options:
|
|
113
|
+
demandCommandCount: r,
|
|
114
|
+
options: n,
|
|
111
115
|
positionals: s,
|
|
112
|
-
subcommands:
|
|
116
|
+
subcommands: c
|
|
113
117
|
}) => {
|
|
114
118
|
let i = e.strict();
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
return i = i.help(
|
|
118
|
-
},
|
|
119
|
-
const t = await
|
|
119
|
+
o && (i = i.usage(`Usage: ${o}`)), r && (i = i.demandCommand(r));
|
|
120
|
+
const l = "help";
|
|
121
|
+
return i = i.help(l), t ? i = i.version(t).alias("h", l).alias("v", "version") : i = i.alias("h", l), n && (i = i.options(n)), s && (i = Object.entries(s).reduce((E, [H, T]) => E.positional(H, T), i)), c && (i = i.command(c)), i;
|
|
122
|
+
}, Re = async ({ handler: e, ...o }) => {
|
|
123
|
+
const t = await x(V(), o).fail(G).argv;
|
|
120
124
|
return e ? e(t) : t;
|
|
121
|
-
},
|
|
122
|
-
const { command:
|
|
123
|
-
}, ...
|
|
125
|
+
}, Ee = (e) => {
|
|
126
|
+
const { command: o, describe: t, handler: r = () => {
|
|
127
|
+
}, ...n } = e;
|
|
124
128
|
return {
|
|
125
|
-
command:
|
|
129
|
+
command: o,
|
|
126
130
|
describe: t,
|
|
127
131
|
builder(s) {
|
|
128
|
-
return
|
|
132
|
+
return x(s, n);
|
|
129
133
|
},
|
|
130
|
-
handler:
|
|
134
|
+
handler: r
|
|
131
135
|
};
|
|
132
136
|
};
|
|
133
|
-
var
|
|
134
|
-
const
|
|
135
|
-
const { editorType: e } = await
|
|
137
|
+
var B = /* @__PURE__ */ ((e) => (e.VSCODE = "VsCode", e.CURSOR = "Cursor", e.OTHER = "其他", e))(B || {});
|
|
138
|
+
const K = async () => {
|
|
139
|
+
const { editorType: e } = await D([
|
|
136
140
|
{
|
|
137
141
|
name: "editorType",
|
|
138
142
|
type: "select",
|
|
@@ -142,39 +146,39 @@ const N = async () => {
|
|
|
142
146
|
"VsCode",
|
|
143
147
|
"其他"
|
|
144
148
|
/* OTHER */
|
|
145
|
-
].map((
|
|
146
|
-
title:
|
|
147
|
-
value:
|
|
149
|
+
].map((o) => ({
|
|
150
|
+
title: o,
|
|
151
|
+
value: o
|
|
148
152
|
}))
|
|
149
153
|
}
|
|
150
154
|
]);
|
|
151
155
|
return e;
|
|
152
|
-
},
|
|
156
|
+
}, U = {
|
|
153
157
|
Cursor: "cursor",
|
|
154
158
|
VsCode: "code"
|
|
155
|
-
},
|
|
159
|
+
}, W = (e, o, t) => {
|
|
156
160
|
try {
|
|
157
|
-
|
|
161
|
+
f(`${e} -v`, { stdio: "ignore" }), f(`${e} ${o}`);
|
|
158
162
|
} catch {
|
|
159
163
|
t();
|
|
160
164
|
}
|
|
161
|
-
},
|
|
162
|
-
const t = (
|
|
163
|
-
${
|
|
165
|
+
}, X = (e, o) => {
|
|
166
|
+
const t = (r) => a.info(`
|
|
167
|
+
${r}, 请用编辑器打开 ${e} 进行编辑
|
|
164
168
|
`);
|
|
165
|
-
switch (
|
|
169
|
+
switch (o) {
|
|
166
170
|
case "Cursor":
|
|
167
171
|
case "VsCode": {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
t(`${
|
|
172
|
+
const r = U[o];
|
|
173
|
+
W(r, e, () => {
|
|
174
|
+
t(`${r}命令未安装`);
|
|
171
175
|
});
|
|
172
176
|
break;
|
|
173
177
|
}
|
|
174
178
|
default:
|
|
175
179
|
t("其他编辑器");
|
|
176
180
|
}
|
|
177
|
-
},
|
|
181
|
+
}, q = (e = process.cwd()) => ({
|
|
178
182
|
/** 必须保留 */
|
|
179
183
|
rootDir: {
|
|
180
184
|
type: "string",
|
|
@@ -183,12 +187,12 @@ const N = async () => {
|
|
|
183
187
|
/** 必须设置默认值 */
|
|
184
188
|
default: e
|
|
185
189
|
}
|
|
186
|
-
}),
|
|
190
|
+
}), Oe = ({
|
|
187
191
|
configPathDefault: e,
|
|
188
|
-
rootDirDefault:
|
|
192
|
+
rootDirDefault: o
|
|
189
193
|
}) => ({
|
|
190
194
|
/** 必须保留 */
|
|
191
|
-
...
|
|
195
|
+
...q(o),
|
|
192
196
|
/** 必须保留 */
|
|
193
197
|
configPath: {
|
|
194
198
|
type: "string",
|
|
@@ -197,67 +201,247 @@ const N = async () => {
|
|
|
197
201
|
/** 必须设置默认值 */
|
|
198
202
|
default: e
|
|
199
203
|
}
|
|
200
|
-
}),
|
|
201
|
-
const { configPath: t, rootDir:
|
|
202
|
-
return
|
|
204
|
+
}), z = async (e, o) => {
|
|
205
|
+
const { configPath: t, rootDir: r } = o, n = g.resolve(r, t), s = g.dirname(n);
|
|
206
|
+
return p(s) || j(s, {
|
|
203
207
|
recursive: !0
|
|
204
|
-
}),
|
|
205
|
-
},
|
|
208
|
+
}), n.endsWith(".json5") ? (a.info(`json5模式写入 ${n}`), S(n, k.stringify(e, null, 2)), n) : (a.info(`json模式写入 ${n}`), S(n, JSON.stringify(e, null, 2)), n);
|
|
209
|
+
}, ke = async (e, o, {
|
|
206
210
|
onFileGenerated: t,
|
|
207
|
-
edit:
|
|
211
|
+
edit: r = !1
|
|
208
212
|
} = {}) => {
|
|
209
|
-
const
|
|
210
|
-
if (t == null || t(
|
|
211
|
-
const s = await
|
|
212
|
-
|
|
213
|
+
const n = await z(e, o);
|
|
214
|
+
if (t == null || t(n), r) {
|
|
215
|
+
const s = await K();
|
|
216
|
+
X(o.configPath, s);
|
|
213
217
|
}
|
|
214
|
-
},
|
|
215
|
-
const { configPath: t, rootDir:
|
|
216
|
-
if (!
|
|
217
|
-
if (
|
|
218
|
-
return
|
|
219
|
-
const s = `配置文件不存在 ${
|
|
218
|
+
}, we = async (e, o) => {
|
|
219
|
+
const { configPath: t, rootDir: r } = e, n = g.resolve(r, t);
|
|
220
|
+
if (!p(n)) {
|
|
221
|
+
if (o)
|
|
222
|
+
return a.info("配置文件不存在,使用onNotExists返回值"), o();
|
|
223
|
+
const s = `配置文件不存在 ${n}`;
|
|
220
224
|
throw new Error(s);
|
|
221
225
|
}
|
|
222
|
-
return
|
|
223
|
-
},
|
|
224
|
-
const { useDefaultConfig: e } = await
|
|
226
|
+
return n.endsWith(".json5") ? (a.info(`json5模式解析 ${n}`), k.parse($(n, "utf8"))) : (a.info(`json模式解析 ${n}`), JSON.parse($(n, "utf8")));
|
|
227
|
+
}, _e = async () => {
|
|
228
|
+
const { useDefaultConfig: e } = await D({
|
|
225
229
|
name: "useDefaultConfig",
|
|
226
230
|
type: "confirm",
|
|
227
231
|
message: "使用默认模板配置",
|
|
228
232
|
initial: !0
|
|
229
233
|
});
|
|
230
234
|
return e;
|
|
231
|
-
},
|
|
235
|
+
}, b = "package.json", R = ({
|
|
232
236
|
rootDir: e
|
|
233
237
|
}) => {
|
|
234
|
-
const
|
|
235
|
-
if (!
|
|
238
|
+
const o = g.resolve(e, b);
|
|
239
|
+
if (!p(o))
|
|
236
240
|
throw new Error(`${e}未找到package.json文件`);
|
|
237
|
-
const t =
|
|
241
|
+
const t = $(o, "utf-8");
|
|
238
242
|
return JSON.parse(t);
|
|
243
|
+
}, Q = ({
|
|
244
|
+
rootDir: e,
|
|
245
|
+
pkgJson: o,
|
|
246
|
+
pkgName: t,
|
|
247
|
+
isDevPkg: r
|
|
248
|
+
}) => {
|
|
249
|
+
const n = o || R({ rootDir: e }), s = r ? n.devDependencies : n.dependencies;
|
|
250
|
+
let c = s == null ? void 0 : s[t];
|
|
251
|
+
if (!c) {
|
|
252
|
+
const i = r ? n.dependencies : n.devDependencies;
|
|
253
|
+
c = i == null ? void 0 : i[t], c && console.log(
|
|
254
|
+
u.yellow(
|
|
255
|
+
`${r ? "开发" : "生产"}依赖包${t}可能错误的安装在${r ? "dependencies" : "devDependencies"}`
|
|
256
|
+
)
|
|
257
|
+
);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
return c || console.log(u.cyan(`依赖包${t}未安装`)), c;
|
|
261
|
+
}, Pe = ({
|
|
262
|
+
patchConfig: e,
|
|
263
|
+
rootDir: o
|
|
264
|
+
}) => {
|
|
265
|
+
if (!e)
|
|
266
|
+
return;
|
|
267
|
+
const t = R({ rootDir: o }), r = Y(t, e), n = g.resolve(o, b);
|
|
268
|
+
S(n, JSON.stringify(r, null, 2), "utf-8");
|
|
269
|
+
}, De = (e) => {
|
|
270
|
+
const t = f("git rev-parse --show-toplevel", {
|
|
271
|
+
cwd: e
|
|
272
|
+
}).toString();
|
|
273
|
+
if (!t)
|
|
274
|
+
throw new Error("获取git根目录失败");
|
|
275
|
+
return t.trim();
|
|
276
|
+
}, xe = ({
|
|
277
|
+
remoteAlias: e
|
|
278
|
+
} = {}) => {
|
|
279
|
+
try {
|
|
280
|
+
const o = f("git rev-parse HEAD").toString().trim(), t = f('git log -1 --pretty=format:"%an"').toString().trim(), r = f('git log -1 --pretty=format:"%ae"').toString().trim(), n = f('git log -1 --pretty=format:"%s"').toString().trim(), s = f("git config user.name").toString().trim(), c = f("git config user.email").toString().trim(), i = f("git rev-parse --abbrev-ref HEAD").toString().trim();
|
|
281
|
+
let l = "";
|
|
282
|
+
try {
|
|
283
|
+
l = f(`git config --get remote.${e}.url`).toString().trim();
|
|
284
|
+
} catch {
|
|
285
|
+
a.warn("git远程仓库地址获取失败或者不存在");
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
lastHash: o,
|
|
289
|
+
lastCommitter: t,
|
|
290
|
+
lastCommitterPinYin: m(t, {
|
|
291
|
+
style: m.STYLE_NORMAL,
|
|
292
|
+
heteronym: !1
|
|
293
|
+
}).join(""),
|
|
294
|
+
lastCommitEmail: r,
|
|
295
|
+
lastCommitMsg: n,
|
|
296
|
+
userName: s,
|
|
297
|
+
userNamePinYin: m(s, {
|
|
298
|
+
style: m.STYLE_NORMAL,
|
|
299
|
+
heteronym: !1
|
|
300
|
+
}).join(""),
|
|
301
|
+
userEmail: c,
|
|
302
|
+
branchName: i,
|
|
303
|
+
remoteInfo: l ? {
|
|
304
|
+
alias: e,
|
|
305
|
+
url: l
|
|
306
|
+
} : void 0
|
|
307
|
+
};
|
|
308
|
+
} catch (o) {
|
|
309
|
+
throw a.error("获取git最后提交信息失败"), o;
|
|
310
|
+
}
|
|
311
|
+
}, be = ({
|
|
312
|
+
branchName: e,
|
|
313
|
+
version: o,
|
|
314
|
+
remoteInfo: t
|
|
315
|
+
}) => {
|
|
316
|
+
t && (f(`git push ${t.alias} v${o}`, {
|
|
317
|
+
stdio: "inherit"
|
|
318
|
+
}), f(`git push ${t.alias} ${e}`, {
|
|
319
|
+
stdio: "inherit"
|
|
320
|
+
}));
|
|
321
|
+
}, C = 73, Z = (e) => {
|
|
322
|
+
const t = d.statSync(e).mode;
|
|
323
|
+
if ((t & C) === C)
|
|
324
|
+
return;
|
|
325
|
+
console.log(u.blue(`${e} 没有执行权限 添加... `));
|
|
326
|
+
const r = t | C;
|
|
327
|
+
d.chmodSync(e, r), console.log(u.green(`${e} 添加执行权限成功`));
|
|
328
|
+
}, ee = "husky", te = ".husky", oe = ({
|
|
329
|
+
projectRootDir: e
|
|
330
|
+
}) => {
|
|
331
|
+
const o = Q({
|
|
332
|
+
rootDir: e,
|
|
333
|
+
pkgJson: R({ rootDir: e }),
|
|
334
|
+
pkgName: ee,
|
|
335
|
+
isDevPkg: !0
|
|
336
|
+
});
|
|
337
|
+
if (!o)
|
|
338
|
+
throw new Error("husky版本获取失败, 可能husky未安装");
|
|
339
|
+
const t = o.replace(/^(\^|~)/, ""), r = "<9.0.0";
|
|
340
|
+
return J.satisfies(t, r) ? (console.log(u.cyan(`${t}符合${r}`)), `#!/usr/bin/env sh
|
|
341
|
+
. "$(dirname -- "$0")/_/husky.sh"`) : (console.log(u.cyan(`${t}不符合${r}`)), "");
|
|
342
|
+
}, re = ({
|
|
343
|
+
projectRootDir: e
|
|
344
|
+
}) => g.resolve(e, te), Fe = ({
|
|
345
|
+
hookNames: e,
|
|
346
|
+
projectRootDir: o,
|
|
347
|
+
getCode: t
|
|
348
|
+
}) => {
|
|
349
|
+
const r = re({ projectRootDir: o });
|
|
350
|
+
d.existsSync(r) || d.mkdirSync(r, { recursive: !0 }), e.forEach((n) => {
|
|
351
|
+
const s = g.resolve(r, n), c = d.existsSync(s);
|
|
352
|
+
let i = t(n);
|
|
353
|
+
if (c)
|
|
354
|
+
d.readFileSync(s, "utf-8").includes(i) ? console.log(
|
|
355
|
+
u.gray(`${s} ${n}相关调用 ${i} 已存在 跳过`)
|
|
356
|
+
) : (d.appendFileSync(
|
|
357
|
+
s,
|
|
358
|
+
`
|
|
359
|
+
${i}
|
|
360
|
+
`
|
|
361
|
+
), console.log(u.green(`${s} 添加 ${n}相关调用成功`)));
|
|
362
|
+
else {
|
|
363
|
+
const l = oe({
|
|
364
|
+
projectRootDir: o
|
|
365
|
+
});
|
|
366
|
+
d.writeFileSync(
|
|
367
|
+
s,
|
|
368
|
+
`${l}
|
|
369
|
+
|
|
370
|
+
${i}
|
|
371
|
+
`,
|
|
372
|
+
"utf-8"
|
|
373
|
+
), console.log(u.green(`${s} 添加 ${n}相关调用成功`));
|
|
374
|
+
}
|
|
375
|
+
Z(s);
|
|
376
|
+
});
|
|
377
|
+
}, O = "git@gitee.com:justsosu/done-coding-cli-assets-config.git", ne = (e) => `./.DONE_CODING_CLI_CONFIG_TEMPORARY_DIRECTORY_FOR_${e}`, F = (e) => `./assets/${e}`, se = (e) => `${F(e)}/index.json`, He = async ({
|
|
378
|
+
moduleName: e,
|
|
379
|
+
onSuccess: o
|
|
380
|
+
}) => {
|
|
381
|
+
console.log(u.blue(`拉取${e}配置,请稍等...`));
|
|
382
|
+
const t = ne(e), r = g.resolve(
|
|
383
|
+
L(),
|
|
384
|
+
t
|
|
385
|
+
);
|
|
386
|
+
if (p(r))
|
|
387
|
+
return console.log(
|
|
388
|
+
u.red(`${r} 已存在,请手动删除该目录再试`)
|
|
389
|
+
), process.exit(1);
|
|
390
|
+
const n = () => {
|
|
391
|
+
A(r, { recursive: !0, force: !0 });
|
|
392
|
+
};
|
|
393
|
+
let s;
|
|
394
|
+
try {
|
|
395
|
+
f(`git clone ${O} ${r} --depth=1`);
|
|
396
|
+
const c = se(e), i = F(e), l = g.resolve(
|
|
397
|
+
r,
|
|
398
|
+
c
|
|
399
|
+
);
|
|
400
|
+
s = JSON.parse(d.readFileSync(l, "utf-8")), process.once("exit", () => {
|
|
401
|
+
p(r) && (console.log("发现进程退出,正在清理临时目录..."), n());
|
|
402
|
+
}), await o({
|
|
403
|
+
repoUrl: O,
|
|
404
|
+
config: s,
|
|
405
|
+
cliConfigFileRelativePath: c,
|
|
406
|
+
cliConfigDirRelativePath: i,
|
|
407
|
+
configTemporaryDir: r
|
|
408
|
+
});
|
|
409
|
+
} finally {
|
|
410
|
+
n();
|
|
411
|
+
}
|
|
412
|
+
return s;
|
|
239
413
|
};
|
|
240
414
|
export {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
415
|
+
B as EditorTypeEnum,
|
|
416
|
+
Be as _curry,
|
|
417
|
+
Je as _get,
|
|
418
|
+
Ge as _set,
|
|
419
|
+
Fe as addHuskyHooks,
|
|
420
|
+
Pe as addPackageConfig,
|
|
421
|
+
Ae as chalk,
|
|
422
|
+
Re as createMainCommand,
|
|
423
|
+
Ee as createSubcommand,
|
|
424
|
+
ve as decryptAES,
|
|
425
|
+
$e as encryptAES,
|
|
426
|
+
Z as fileAddX,
|
|
427
|
+
Oe as getConfigFileCommonOptions,
|
|
428
|
+
K as getEditorType,
|
|
429
|
+
xe as getGitLastCommitInfo,
|
|
430
|
+
De as getGitProjectDir,
|
|
431
|
+
oe as getHuskyBootCode,
|
|
432
|
+
re as getHuskyRootDir,
|
|
433
|
+
R as getPackageJson,
|
|
434
|
+
Q as getRelyPkgVersion,
|
|
435
|
+
q as getRootDirOptions,
|
|
436
|
+
_e as getUseDefaultConfig,
|
|
437
|
+
z as initConfigFile,
|
|
438
|
+
ke as initHandlerCommon,
|
|
439
|
+
Me as json5,
|
|
440
|
+
a as log,
|
|
441
|
+
Se as lookForParentTarget,
|
|
442
|
+
X as openFileInEditor,
|
|
443
|
+
be as pushGitPublishInfoToRemote,
|
|
444
|
+
He as readCliConfig,
|
|
445
|
+
we as readConfigFile,
|
|
446
|
+
D as xPrompts
|
|
263
447
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-alpha.0",
|
|
4
4
|
"description": "cli utils",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -40,9 +40,12 @@
|
|
|
40
40
|
"@types/json5": "^2.2.0",
|
|
41
41
|
"@types/lodash.curry": "^4.1.8",
|
|
42
42
|
"@types/lodash.get": "^4.4.9",
|
|
43
|
+
"@types/lodash.merge": "^4.6.9",
|
|
43
44
|
"@types/lodash.set": "^4.3.9",
|
|
44
45
|
"@types/node": "^18.0.0",
|
|
46
|
+
"@types/pinyin": "^2.10.0",
|
|
45
47
|
"@types/prompts": "^2.4.6",
|
|
48
|
+
"@types/semver": "^7.5.3",
|
|
46
49
|
"@types/yargs": "^17.0.28",
|
|
47
50
|
"rimraf": "^6.0.1",
|
|
48
51
|
"typescript": "^5.2.2",
|
|
@@ -57,9 +60,12 @@
|
|
|
57
60
|
"json5": "^2.2.3",
|
|
58
61
|
"lodash.curry": "^4.1.1",
|
|
59
62
|
"lodash.get": "^4.4.2",
|
|
63
|
+
"lodash.merge": "^4.6.2",
|
|
60
64
|
"lodash.set": "^4.3.2",
|
|
65
|
+
"pinyin": "^2.11.2",
|
|
61
66
|
"prompts": "^2.4.2",
|
|
67
|
+
"semver": "^7.5.4",
|
|
62
68
|
"yargs": "^17.7.2"
|
|
63
69
|
},
|
|
64
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "5879161383e32e7bed351d71d3ef607d81dc021a"
|
|
65
71
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 读取配置 */
|
|
2
|
+
export declare const readCliConfig: <R>({ moduleName, onSuccess, }: {
|
|
3
|
+
moduleName: string;
|
|
4
|
+
onSuccess: (params: {
|
|
5
|
+
repoUrl: string;
|
|
6
|
+
/** 配置文件相对路径 */
|
|
7
|
+
cliConfigFileRelativePath: string;
|
|
8
|
+
/** 配置文件目录相对路径 */
|
|
9
|
+
cliConfigDirRelativePath: string;
|
|
10
|
+
/** 配置文件内容 */
|
|
11
|
+
config: R;
|
|
12
|
+
/** 配置临时目录 */
|
|
13
|
+
configTemporaryDir: string;
|
|
14
|
+
}) => void | Promise<void>;
|
|
15
|
+
}) => Promise<R>;
|
package/types/git.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** 获取git最好提交信息参数 */
|
|
2
|
+
export interface GetGitLastCommitParams {
|
|
3
|
+
/**
|
|
4
|
+
* 远程仓库别名
|
|
5
|
+
*/
|
|
6
|
+
remoteAlias?: string;
|
|
7
|
+
}
|
|
8
|
+
/** 远程仓库信息 */
|
|
9
|
+
export interface GitRemoteInfo {
|
|
10
|
+
/**
|
|
11
|
+
* 远程仓库别名
|
|
12
|
+
*/
|
|
13
|
+
alias?: GetGitLastCommitParams["remoteAlias"];
|
|
14
|
+
/**
|
|
15
|
+
* 仓库地址
|
|
16
|
+
*/
|
|
17
|
+
url?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* git最后提交信息
|
|
21
|
+
*/
|
|
22
|
+
export interface GitLastCommitInfo {
|
|
23
|
+
/**
|
|
24
|
+
* 最后一次提交hash值
|
|
25
|
+
*/
|
|
26
|
+
lastHash: string;
|
|
27
|
+
/**
|
|
28
|
+
* 最后一次提交者
|
|
29
|
+
*/
|
|
30
|
+
lastCommitter: string;
|
|
31
|
+
/**
|
|
32
|
+
* 最后一次提交者拼音
|
|
33
|
+
*/
|
|
34
|
+
lastCommitterPinYin: string;
|
|
35
|
+
/**
|
|
36
|
+
* 最后一次提交者邮箱
|
|
37
|
+
*/
|
|
38
|
+
lastCommitEmail: string;
|
|
39
|
+
/**
|
|
40
|
+
* 最后一次提交信息
|
|
41
|
+
*/
|
|
42
|
+
lastCommitMsg: string;
|
|
43
|
+
/**
|
|
44
|
+
* 用户名
|
|
45
|
+
*/
|
|
46
|
+
userName: string;
|
|
47
|
+
/**
|
|
48
|
+
* 用户名拼音
|
|
49
|
+
*/
|
|
50
|
+
userNamePinYin: string;
|
|
51
|
+
/**
|
|
52
|
+
* 邮箱
|
|
53
|
+
*/
|
|
54
|
+
userEmail: string;
|
|
55
|
+
/**
|
|
56
|
+
* 分知名
|
|
57
|
+
*/
|
|
58
|
+
branchName: string;
|
|
59
|
+
/** 远程仓库信息 */
|
|
60
|
+
remoteInfo?: GitRemoteInfo;
|
|
61
|
+
}
|
|
62
|
+
/** 获取git项目目录 */
|
|
63
|
+
export declare const getGitProjectDir: (rootDir: string) => string;
|
|
64
|
+
/**
|
|
65
|
+
* 获取git 最后提交信息
|
|
66
|
+
*/
|
|
67
|
+
export declare const getGitLastCommitInfo: ({ remoteAlias, }?: GetGitLastCommitParams) => GitLastCommitInfo;
|
|
68
|
+
/** 推送git发布信息到远程仓库 */
|
|
69
|
+
export declare const pushGitPublishInfoToRemote: ({ branchName, version, remoteInfo, }: {
|
|
70
|
+
branchName: string;
|
|
71
|
+
version: string;
|
|
72
|
+
remoteInfo?: GitRemoteInfo | undefined;
|
|
73
|
+
}) => void;
|
package/types/husky.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** 获取husky引导代码 */
|
|
2
|
+
export declare const getHuskyBootCode: ({ projectRootDir, }: {
|
|
3
|
+
projectRootDir: string;
|
|
4
|
+
}) => "" | "#!/usr/bin/env sh\n. \"$(dirname -- \"$0\")/_/husky.sh\"";
|
|
5
|
+
/** 获取husky根目录 */
|
|
6
|
+
export declare const getHuskyRootDir: ({ projectRootDir, }: {
|
|
7
|
+
projectRootDir: string;
|
|
8
|
+
}) => string;
|
|
9
|
+
/** 添加 husky hooks */
|
|
10
|
+
export declare const addHuskyHooks: <H extends string>({ hookNames, projectRootDir, getCode, }: {
|
|
11
|
+
hookNames: H[];
|
|
12
|
+
/** 项目根目录 */
|
|
13
|
+
projectRootDir: string;
|
|
14
|
+
/** 获取husky hooks 添加的代码 */
|
|
15
|
+
getCode: (hook: string) => string;
|
|
16
|
+
}) => void;
|
package/types/index.d.ts
CHANGED
package/types/package-json.d.ts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
+
/** package.json文件内容 */
|
|
1
2
|
export interface PackageJson {
|
|
2
3
|
name: string;
|
|
3
4
|
version?: string;
|
|
5
|
+
bin?: Record<string, string> | string;
|
|
6
|
+
scripts?: Record<string, string>;
|
|
7
|
+
files?: string[];
|
|
8
|
+
dependencies?: Record<string, string>;
|
|
9
|
+
devDependencies?: Record<string, string>;
|
|
10
|
+
peerDependencies?: Record<string, string>;
|
|
4
11
|
}
|
|
12
|
+
/** 获取package.json文件内容 */
|
|
5
13
|
export declare const getPackageJson: <R extends PackageJson>({ rootDir, }: {
|
|
6
14
|
rootDir: string;
|
|
7
15
|
}) => R;
|
|
16
|
+
/** 获取依赖包版本 */
|
|
17
|
+
export declare const getRelyPkgVersion: <R extends PackageJson>({ rootDir, pkgJson, pkgName, isDevPkg, }: {
|
|
18
|
+
rootDir: string;
|
|
19
|
+
pkgJson?: R | undefined;
|
|
20
|
+
pkgName: string;
|
|
21
|
+
/** 是开发依赖包 */
|
|
22
|
+
isDevPkg: boolean;
|
|
23
|
+
}) => string | undefined;
|
|
24
|
+
/** 添加package.json配置 */
|
|
25
|
+
export declare const addPackageConfig: ({ patchConfig, rootDir, }: {
|
|
26
|
+
patchConfig?: Record<string, any> | undefined;
|
|
27
|
+
rootDir: string;
|
|
28
|
+
}) => void;
|