@done-coding/cli-config 0.1.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/README.md +11 -0
- package/es/cli.mjs +7 -0
- package/es/index-48970952.js +404 -0
- package/es/index.mjs +10 -0
- package/package.json +58 -0
- package/types/cli.d.ts +2 -0
- package/types/handlers/add.d.ts +15 -0
- package/types/handlers/check.d.ts +12 -0
- package/types/handlers/index.d.ts +10 -0
- package/types/index.d.ts +2 -0
- package/types/injectInfo.json.d.ts +11 -0
- package/types/main.d.ts +9 -0
- package/types/types/index.d.ts +92 -0
- package/types/utils/config-resolve.d.ts +20 -0
- package/types/utils/index.d.ts +2 -0
- package/types/utils/path.d.ts +4 -0
package/README.md
ADDED
package/es/cli.mjs
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readConfigFile as B, log as r, getPackageJson as Q, getRelyPkgVersion as X, getConfigFileCommonOptions as Y, readCliConfig as Z, xPrompts as j, addPackageConfig as ee, addHuskyHooks as te, createSubcommand as _, createMainCommand as ne } from "@done-coding/cli-utils";
|
|
3
|
+
import h, { existsSync as C } from "node:fs";
|
|
4
|
+
import g from "node:path";
|
|
5
|
+
import { execSync as k } from "node:child_process";
|
|
6
|
+
var y = /* @__PURE__ */ ((e) => (e.CHECK = "check", e.ADD = "add", e))(y || {}), m = /* @__PURE__ */ ((e) => (e.ESLINT = "eslint", e.PRETTIER = "prettier", e.COMMITLINT = "commitlint", e.LSLINT = "ls-lint", e.MERGELINT = "merge-lint", e))(m || {});
|
|
7
|
+
const N = {
|
|
8
|
+
name: "@done-coding/cli-config",
|
|
9
|
+
version: "0.1.0-alpha.0",
|
|
10
|
+
description: "工程化配置命令行工具",
|
|
11
|
+
cliConfig: {
|
|
12
|
+
namespaceDir: ".done-coding",
|
|
13
|
+
moduleName: "config"
|
|
14
|
+
}
|
|
15
|
+
}, {
|
|
16
|
+
cliConfig: { namespaceDir: oe, moduleName: se }
|
|
17
|
+
} = N, re = `./${oe}/${se}`, ie = `${re}.json`, I = Object.values(m).filter(
|
|
18
|
+
(e) => e.toUpperCase() !== e
|
|
19
|
+
), ce = async (e) => await B(e, () => {
|
|
20
|
+
const { moduleList: t = [] } = e;
|
|
21
|
+
return r.info(
|
|
22
|
+
`配置文件不存在 读取命令行参数 moduleList: ${JSON.stringify(
|
|
23
|
+
t,
|
|
24
|
+
null,
|
|
25
|
+
2
|
|
26
|
+
)}`
|
|
27
|
+
), {
|
|
28
|
+
moduleList: t
|
|
29
|
+
};
|
|
30
|
+
}), F = {
|
|
31
|
+
[m.ESLINT]: "eslint",
|
|
32
|
+
[m.PRETTIER]: "prettier",
|
|
33
|
+
[m.COMMITLINT]: "@commitlint/cli",
|
|
34
|
+
[m.LSLINT]: "@ls-lint/ls-lint",
|
|
35
|
+
[m.MERGELINT]: "@done-coding/cli-git"
|
|
36
|
+
}, n = "_$_", ae = {
|
|
37
|
+
[m.ESLINT]: [
|
|
38
|
+
`${n}.config.js`,
|
|
39
|
+
`${n}.config.mjs`,
|
|
40
|
+
`${n}.config.cjs`,
|
|
41
|
+
`.${n}rc`,
|
|
42
|
+
`.${n}rc.js`,
|
|
43
|
+
`.${n}rc.json`,
|
|
44
|
+
`.${n}rc.mjs`,
|
|
45
|
+
`.${n}rc.cjs`,
|
|
46
|
+
`.${n}rc.yaml`,
|
|
47
|
+
`.${n}rc.yml`
|
|
48
|
+
],
|
|
49
|
+
[m.PRETTIER]: [
|
|
50
|
+
`${n}.config.js`,
|
|
51
|
+
`${n}.config.mjs`,
|
|
52
|
+
`${n}.config.cjs`,
|
|
53
|
+
`.${n}rc`,
|
|
54
|
+
`.${n}rc.js`,
|
|
55
|
+
`.${n}rc.json`,
|
|
56
|
+
`.${n}rc.json5`,
|
|
57
|
+
`.${n}rc.mjs`,
|
|
58
|
+
`.${n}rc.cjs`,
|
|
59
|
+
`.${n}rc.yaml`,
|
|
60
|
+
`.${n}rc.yml`,
|
|
61
|
+
`.${n}rc.toml`
|
|
62
|
+
],
|
|
63
|
+
[m.COMMITLINT]: [
|
|
64
|
+
`${n}.config.js`,
|
|
65
|
+
`${n}.config.mjs`,
|
|
66
|
+
`${n}.config.cjs`,
|
|
67
|
+
`.${n}rc`,
|
|
68
|
+
`.${n}rc.js`,
|
|
69
|
+
`.${n}rc.json`,
|
|
70
|
+
`.${n}rc.mjs`,
|
|
71
|
+
`.${n}rc.cjs`,
|
|
72
|
+
`.${n}rc.yaml`,
|
|
73
|
+
`.${n}rc.yml`
|
|
74
|
+
],
|
|
75
|
+
[m.LSLINT]: [`.${n}.yaml`, `.${n}.yml`],
|
|
76
|
+
[m.MERGELINT]: [".done-coding/git.json"]
|
|
77
|
+
}, le = (e, t) => t.filter((o) => C(g.resolve(e, o))), H = (e) => e.filter((t) => {
|
|
78
|
+
const o = I.includes(t);
|
|
79
|
+
return o || r.warn(
|
|
80
|
+
`当前不支持${t}的配置检测, 支持的类型有${I.join(
|
|
81
|
+
", "
|
|
82
|
+
)}`
|
|
83
|
+
), o;
|
|
84
|
+
}), me = ({
|
|
85
|
+
config: e,
|
|
86
|
+
rootDir: t
|
|
87
|
+
}) => {
|
|
88
|
+
const { moduleList: o = [] } = e, s = H(o);
|
|
89
|
+
r.stage(`开始获取${s.join(", ")}配置信息...`);
|
|
90
|
+
const i = Q({ rootDir: t });
|
|
91
|
+
return s.reduce(
|
|
92
|
+
(a, l) => {
|
|
93
|
+
const f = X({
|
|
94
|
+
rootDir: t,
|
|
95
|
+
pkgJson: i,
|
|
96
|
+
pkgName: F[l],
|
|
97
|
+
isDevPkg: !0
|
|
98
|
+
});
|
|
99
|
+
if (!f)
|
|
100
|
+
return a;
|
|
101
|
+
const c = ae[l].map((u) => u.replace(n, l));
|
|
102
|
+
return c.length ? (a[l] = {
|
|
103
|
+
version: f,
|
|
104
|
+
configFileRelativePathList: le(
|
|
105
|
+
t,
|
|
106
|
+
c
|
|
107
|
+
)
|
|
108
|
+
}, a) : (r.warn(`安装了${l}, 但未找到${l}的配置文件 认为未使用`), a);
|
|
109
|
+
},
|
|
110
|
+
{}
|
|
111
|
+
);
|
|
112
|
+
}, J = () => ({
|
|
113
|
+
...Y({
|
|
114
|
+
configPathDefault: ie
|
|
115
|
+
}),
|
|
116
|
+
moduleList: {
|
|
117
|
+
type: "array",
|
|
118
|
+
alias: "m",
|
|
119
|
+
description: "需要检测的工程化配置模块",
|
|
120
|
+
choices: I,
|
|
121
|
+
default: I.filter(
|
|
122
|
+
(e) => e !== m.MERGELINT
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
}), E = async (e) => {
|
|
126
|
+
const t = await ce(e), o = me({ config: t, rootDir: e.rootDir });
|
|
127
|
+
return r.success(`检测到工程化配置信息:
|
|
128
|
+
${JSON.stringify(o, null, 2)}`), {
|
|
129
|
+
config: t,
|
|
130
|
+
info: o
|
|
131
|
+
};
|
|
132
|
+
}, de = {
|
|
133
|
+
command: y.CHECK,
|
|
134
|
+
describe: "检测工程化配置",
|
|
135
|
+
options: J(),
|
|
136
|
+
handler: E
|
|
137
|
+
}, {
|
|
138
|
+
cliConfig: { moduleName: ue }
|
|
139
|
+
} = N, fe = () => ({
|
|
140
|
+
...J(),
|
|
141
|
+
commitGit: {
|
|
142
|
+
type: "boolean",
|
|
143
|
+
alias: "g",
|
|
144
|
+
description: "添加完成后是否提交到git",
|
|
145
|
+
default: !1
|
|
146
|
+
}
|
|
147
|
+
}), ge = async ({
|
|
148
|
+
moduleName: e,
|
|
149
|
+
moduleConfigList: t
|
|
150
|
+
}) => {
|
|
151
|
+
if (!Array.isArray(t) || t.length === 0) {
|
|
152
|
+
r.error(`未找到 ${e} 预设版本配置`);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (t.length === 1) {
|
|
156
|
+
const s = t[0];
|
|
157
|
+
return r.skip(
|
|
158
|
+
`${e} 跳过版本选择: 仅有一个预设版本配置, 默认选择第一个(${s.version})`
|
|
159
|
+
), s;
|
|
160
|
+
}
|
|
161
|
+
const { version: o } = await j({
|
|
162
|
+
type: "select",
|
|
163
|
+
name: "version",
|
|
164
|
+
message: `请选择需要添加的${e}版本`,
|
|
165
|
+
choices: t.map((s) => {
|
|
166
|
+
const { version: i } = s;
|
|
167
|
+
return {
|
|
168
|
+
title: `${F[e]}@${i}`,
|
|
169
|
+
value: i
|
|
170
|
+
};
|
|
171
|
+
})
|
|
172
|
+
});
|
|
173
|
+
return t.find((s) => s.version === o);
|
|
174
|
+
}, $e = async ({
|
|
175
|
+
moduleName: e,
|
|
176
|
+
moduleConfig: t
|
|
177
|
+
}) => {
|
|
178
|
+
const { configFileInfoList: o } = t;
|
|
179
|
+
if (!Array.isArray(o) || o.length === 0) {
|
|
180
|
+
r.error(`未找到 ${e} 配置文件信息列表`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (o.length === 1) {
|
|
184
|
+
const i = o[0];
|
|
185
|
+
return r.skip(
|
|
186
|
+
`${e} 跳过配置文件信息选择: 仅有一个配置文件信息, 默认选择第一个(${i.sourceFile})`
|
|
187
|
+
), i;
|
|
188
|
+
}
|
|
189
|
+
const { info: s } = await j({
|
|
190
|
+
type: "select",
|
|
191
|
+
name: "info",
|
|
192
|
+
message: "请选择需要添加的配置文件",
|
|
193
|
+
choices: o.map((i) => {
|
|
194
|
+
const { sourceFile: a, description: l } = i;
|
|
195
|
+
return {
|
|
196
|
+
title: a,
|
|
197
|
+
value: i,
|
|
198
|
+
description: l
|
|
199
|
+
};
|
|
200
|
+
})
|
|
201
|
+
});
|
|
202
|
+
return o.find((i) => i.sourceFile === s.sourceFile);
|
|
203
|
+
}, pe = ({ rootDir: e, list: t }) => {
|
|
204
|
+
r.stage(`开始安装依赖包: ${JSON.stringify(t, null, 2)}`);
|
|
205
|
+
const o = g.resolve(e, "pnpm-workspace.yaml"), s = C(o);
|
|
206
|
+
k(`pnpm add -D ${s ? "-w" : ""} ${t.join(" ")}`, {
|
|
207
|
+
cwd: e,
|
|
208
|
+
stdio: "inherit"
|
|
209
|
+
});
|
|
210
|
+
}, ye = async ({
|
|
211
|
+
hooksConfig: e,
|
|
212
|
+
argv: t
|
|
213
|
+
}) => Object.entries(e).forEach(async ([o, s]) => {
|
|
214
|
+
await te({
|
|
215
|
+
hookNames: [o],
|
|
216
|
+
rootDir: t.rootDir,
|
|
217
|
+
getCode: () => s
|
|
218
|
+
});
|
|
219
|
+
}), Le = async ({
|
|
220
|
+
moduleName: e,
|
|
221
|
+
moduleConfigList: t,
|
|
222
|
+
argv: o
|
|
223
|
+
}) => {
|
|
224
|
+
const s = await ge({
|
|
225
|
+
moduleName: e,
|
|
226
|
+
moduleConfigList: t
|
|
227
|
+
});
|
|
228
|
+
if (!s)
|
|
229
|
+
return;
|
|
230
|
+
const i = await $e({
|
|
231
|
+
moduleName: e,
|
|
232
|
+
moduleConfig: s
|
|
233
|
+
});
|
|
234
|
+
if (!i)
|
|
235
|
+
return;
|
|
236
|
+
const {
|
|
237
|
+
relyPackages: a = [],
|
|
238
|
+
version: l,
|
|
239
|
+
runScripts: f = []
|
|
240
|
+
} = s, {
|
|
241
|
+
relyPackages: c = [],
|
|
242
|
+
sourceFile: u,
|
|
243
|
+
targetFile: w
|
|
244
|
+
} = i, $ = [
|
|
245
|
+
`${F[e]}@${l}`,
|
|
246
|
+
...a,
|
|
247
|
+
...c
|
|
248
|
+
];
|
|
249
|
+
return r.stage(`需要安装的依赖包:
|
|
250
|
+
${JSON.stringify($, null, 2)}`), await ee({
|
|
251
|
+
patchConfig: s.packageJson,
|
|
252
|
+
rootDir: o.rootDir
|
|
253
|
+
}), {
|
|
254
|
+
sourceFile: u,
|
|
255
|
+
targetFile: w,
|
|
256
|
+
version: l,
|
|
257
|
+
pkgList: $,
|
|
258
|
+
runScripts: f,
|
|
259
|
+
/** 方法内部已经使用husky了 但是所有依赖包在最后才统一安装 */
|
|
260
|
+
addHuskyConfigFn: () => {
|
|
261
|
+
var p;
|
|
262
|
+
return ye({
|
|
263
|
+
hooksConfig: ((p = s.husky) == null ? void 0 : p.hooks) || {},
|
|
264
|
+
argv: o
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}, he = ({
|
|
269
|
+
listConfig: e,
|
|
270
|
+
moduleDir: t,
|
|
271
|
+
moduleName: o
|
|
272
|
+
}) => {
|
|
273
|
+
if (typeof e == "string") {
|
|
274
|
+
console.log(e);
|
|
275
|
+
const s = g.resolve(t, e);
|
|
276
|
+
if (!C(s))
|
|
277
|
+
throw new Error(
|
|
278
|
+
`${o} 预设列表文件 ${s} 不存在`
|
|
279
|
+
);
|
|
280
|
+
const i = h.readFileSync(s, "utf-8");
|
|
281
|
+
return JSON.parse(
|
|
282
|
+
i
|
|
283
|
+
);
|
|
284
|
+
} else {
|
|
285
|
+
if (!Array.isArray(e))
|
|
286
|
+
throw new Error(
|
|
287
|
+
`(${o})预置项必须是数组或者是相对于当前工程化配置模块目录的相对路径`
|
|
288
|
+
);
|
|
289
|
+
return e;
|
|
290
|
+
}
|
|
291
|
+
}, b = async (e) => {
|
|
292
|
+
const { config: t, info: o } = await E(e), { moduleList: s = [] } = t, a = H(s).filter((c) => {
|
|
293
|
+
const u = o[c];
|
|
294
|
+
return u ? (r.skip(`
|
|
295
|
+
检测到 ${c} 已配置, ${JSON.stringify(u, null, 2)},
|
|
296
|
+
跳过添加 ${c}`), !1) : !0;
|
|
297
|
+
});
|
|
298
|
+
if (!a.length) {
|
|
299
|
+
r.success("所有配置项均已配置, 无需添加");
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
await Z({
|
|
303
|
+
moduleName: ue,
|
|
304
|
+
onSuccess: async ({
|
|
305
|
+
config: c,
|
|
306
|
+
configTemporaryDir: u,
|
|
307
|
+
cliConfigDirRelativePath: w
|
|
308
|
+
}) => {
|
|
309
|
+
if (!(c != null && c.project))
|
|
310
|
+
throw new Error("项目工程化预设不存在");
|
|
311
|
+
r.success("预设配置拉取成功");
|
|
312
|
+
const { project: P } = c, { rootDir: $ } = e, p = [], T = [], S = [];
|
|
313
|
+
for (let d of a) {
|
|
314
|
+
const v = g.resolve(
|
|
315
|
+
u,
|
|
316
|
+
w,
|
|
317
|
+
d
|
|
318
|
+
), D = he({
|
|
319
|
+
listConfig: P[d],
|
|
320
|
+
moduleDir: v,
|
|
321
|
+
moduleName: d
|
|
322
|
+
});
|
|
323
|
+
if (!D) {
|
|
324
|
+
r.error(`未找到 ${d} 预设配置`);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
r.stage(`开始添加 ${d} 配置`);
|
|
328
|
+
const M = await Le({
|
|
329
|
+
moduleName: d,
|
|
330
|
+
moduleConfigList: D,
|
|
331
|
+
argv: e
|
|
332
|
+
});
|
|
333
|
+
if (M) {
|
|
334
|
+
const {
|
|
335
|
+
sourceFile: U,
|
|
336
|
+
targetFile: K,
|
|
337
|
+
version: V,
|
|
338
|
+
pkgList: W,
|
|
339
|
+
addHuskyConfigFn: q,
|
|
340
|
+
runScripts: z
|
|
341
|
+
} = M, A = g.resolve(v, V, U), L = g.resolve($, K);
|
|
342
|
+
r.stage(`开始复制 ${A} -> ${L}`);
|
|
343
|
+
const O = g.dirname(L);
|
|
344
|
+
h.existsSync(O) || h.mkdirSync(O, { recursive: !0 }), h.copyFileSync(A, L), r.success(`添加 ${d} 配置成功, 路径: ${L}`), p.push(...W), T.push(q), S.push(...z);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
await pe({
|
|
348
|
+
rootDir: $,
|
|
349
|
+
list: [...new Set(p)]
|
|
350
|
+
});
|
|
351
|
+
for (let d of S)
|
|
352
|
+
r.stage(`运行脚本: ${d}`), k(d, { cwd: $, stdio: "inherit" });
|
|
353
|
+
await Promise.all(T.map((d) => d()));
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
const { commitGit: l, rootDir: f } = e;
|
|
357
|
+
if (l) {
|
|
358
|
+
const { commitMsg: c } = await j({
|
|
359
|
+
type: "text",
|
|
360
|
+
name: "commitMsg",
|
|
361
|
+
message: "请输入提交信息",
|
|
362
|
+
initial: `chore: 添加 ${a.join(", ")} 工程化配置`
|
|
363
|
+
});
|
|
364
|
+
k("git add .", { cwd: f, stdio: "inherit" }), k(`git commit -m "${c}"`, {
|
|
365
|
+
cwd: f,
|
|
366
|
+
stdio: "inherit"
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
}, ke = {
|
|
370
|
+
command: y.ADD,
|
|
371
|
+
describe: "添加工程化配置",
|
|
372
|
+
options: fe(),
|
|
373
|
+
handler: b
|
|
374
|
+
}, Ee = async (e, t) => {
|
|
375
|
+
switch (e) {
|
|
376
|
+
case y.CHECK:
|
|
377
|
+
return E(t);
|
|
378
|
+
case y.ADD:
|
|
379
|
+
return b(t);
|
|
380
|
+
default:
|
|
381
|
+
throw new Error(`不支持的命令 ${e}`);
|
|
382
|
+
}
|
|
383
|
+
}, { version: Ie, description: Ne } = N, G = {
|
|
384
|
+
describe: Ne,
|
|
385
|
+
version: Ie,
|
|
386
|
+
subcommands: [de, ke].map(_),
|
|
387
|
+
demandCommandCount: 1
|
|
388
|
+
}, {
|
|
389
|
+
cliConfig: { moduleName: R }
|
|
390
|
+
} = N, x = (e = !1) => {
|
|
391
|
+
const t = e ? R : void 0, o = `$0${e ? ` ${R}` : ""} <command> [options]`;
|
|
392
|
+
return { command: t, usage: o };
|
|
393
|
+
}, Pe = async () => ne({
|
|
394
|
+
...G,
|
|
395
|
+
...x()
|
|
396
|
+
}), Te = () => _({
|
|
397
|
+
...G,
|
|
398
|
+
...x(!0)
|
|
399
|
+
});
|
|
400
|
+
export {
|
|
401
|
+
Te as a,
|
|
402
|
+
Pe as c,
|
|
403
|
+
Ee as h
|
|
404
|
+
};
|
package/es/index.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@done-coding/cli-config",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "工程化配置命令行工具",
|
|
5
|
+
"private": false,
|
|
6
|
+
"module": "es/index.mjs",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
9
|
+
"bin": {
|
|
10
|
+
"dc-config": "es/cli.mjs"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./es/index.mjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"es",
|
|
19
|
+
"lib",
|
|
20
|
+
"types"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"clean": "rimraf es lib types",
|
|
24
|
+
"predev": "pnpm run clean",
|
|
25
|
+
"dev": "vite build --watch",
|
|
26
|
+
"prebuild": "pnpm run clean",
|
|
27
|
+
"build": "vite build",
|
|
28
|
+
"prepack": "pnpm build"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://gitee.com/justsosu/done-coding-cli.git",
|
|
33
|
+
"directory": "packages/config"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"registry": "https://registry.npmjs.org/"
|
|
38
|
+
},
|
|
39
|
+
"author": "JustSoSu",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"sideEffects": false,
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@done-coding/cli-inject": "^0.5.8-alpha.1",
|
|
44
|
+
"@types/node": "^18.0.0",
|
|
45
|
+
"@types/yargs": "^17.0.28",
|
|
46
|
+
"rimraf": "^6.0.1",
|
|
47
|
+
"typescript": "^5.2.2",
|
|
48
|
+
"vite": "^4.4.11",
|
|
49
|
+
"vite-plugin-dts": "^3.6.0"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18.0.0"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@done-coding/cli-utils": "^0.7.0-alpha.0"
|
|
56
|
+
},
|
|
57
|
+
"gitHead": "ff1616738586a268b50f46dce762774fa5fa6d52"
|
|
58
|
+
}
|
package/types/cli.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type AddConfigOptions, type ConfigModuleEnum, type ConfigProjectConfigItem } from '../types';
|
|
2
|
+
import type { ArgumentsCamelCase } from "yargs";
|
|
3
|
+
import type { SubCliInfo } from "@done-coding/cli-utils";
|
|
4
|
+
import type yargs from "yargs";
|
|
5
|
+
export declare const getOptions: () => {
|
|
6
|
+
[key: string]: yargs.Options;
|
|
7
|
+
};
|
|
8
|
+
/** 解析模块配置列表 */
|
|
9
|
+
export declare const resolveModuleConfigList: ({ listConfig, moduleDir, moduleName, }: {
|
|
10
|
+
listConfig: ConfigProjectConfigItem[] | string;
|
|
11
|
+
moduleDir: string;
|
|
12
|
+
moduleName: ConfigModuleEnum;
|
|
13
|
+
}) => ConfigProjectConfigItem[];
|
|
14
|
+
export declare const handler: (argv: ArgumentsCamelCase<AddConfigOptions>) => Promise<void>;
|
|
15
|
+
export declare const commandCliInfo: SubCliInfo;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type CheckConfigOptions, type ConfigConfig, type TypeConfigInfo } from '../types';
|
|
2
|
+
import type { SubCliInfo } from "@done-coding/cli-utils";
|
|
3
|
+
import type { ArgumentsCamelCase } from "yargs";
|
|
4
|
+
import type yargs from "yargs";
|
|
5
|
+
export declare const getOptions: () => {
|
|
6
|
+
[key: string]: yargs.Options;
|
|
7
|
+
};
|
|
8
|
+
export declare const handler: (argv: ArgumentsCamelCase<CheckConfigOptions>) => Promise<{
|
|
9
|
+
config: ConfigConfig;
|
|
10
|
+
info: TypeConfigInfo;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const commandCliInfo: SubCliInfo;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { handler as checkHandler, commandCliInfo as checkCommandCliInfo } from "./check";
|
|
2
|
+
import { handler as addHandler, commandCliInfo as addCommandCliInfo } from "./add";
|
|
3
|
+
import { SubcommandEnum } from '../types';
|
|
4
|
+
import { type CliHandlerArgv, type CliInfo } from "@done-coding/cli-utils";
|
|
5
|
+
export { checkHandler, checkCommandCliInfo, addHandler, addCommandCliInfo };
|
|
6
|
+
export declare const handler: (command: SubcommandEnum, argv: CliHandlerArgv<any>) => Promise<void | {
|
|
7
|
+
config: import('../types').ConfigConfig;
|
|
8
|
+
info: import('../types').TypeConfigInfo;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const commandCliInfo: Omit<CliInfo, "usage">;
|
package/types/index.d.ts
ADDED
package/types/main.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
/** 作为主命令创建 */
|
|
3
|
+
export declare const createCommand: () => Promise<void | {
|
|
4
|
+
[x: string]: unknown;
|
|
5
|
+
_: (string | number)[];
|
|
6
|
+
$0: string;
|
|
7
|
+
}>;
|
|
8
|
+
/** 作为子命令创建 */
|
|
9
|
+
export declare const crateAsSubcommand: () => import("yargs").CommandModule<{}, {}>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { InitConfigFileOptions, ReadConfigFileOptions } from "@done-coding/cli-utils";
|
|
2
|
+
/** 子命令枚举 */
|
|
3
|
+
export declare enum SubcommandEnum {
|
|
4
|
+
/** 检测工程化配置*/
|
|
5
|
+
CHECK = "check",
|
|
6
|
+
/** 添加工程化配置 */
|
|
7
|
+
ADD = "add"
|
|
8
|
+
}
|
|
9
|
+
/** (工程化)配置模块枚举 */
|
|
10
|
+
export declare enum ConfigModuleEnum {
|
|
11
|
+
/** eslint 配置 */
|
|
12
|
+
ESLINT = "eslint",
|
|
13
|
+
/** prettier 配置 */
|
|
14
|
+
PRETTIER = "prettier",
|
|
15
|
+
/** 提交配置 */
|
|
16
|
+
COMMITLINT = "commitlint",
|
|
17
|
+
/** 文件配置 */
|
|
18
|
+
LSLINT = "ls-lint",
|
|
19
|
+
/** (git)合并检测 */
|
|
20
|
+
MERGELINT = "merge-lint"
|
|
21
|
+
}
|
|
22
|
+
/** config命令的配置 */
|
|
23
|
+
export interface ConfigConfig {
|
|
24
|
+
moduleList?: ConfigModuleEnum[];
|
|
25
|
+
}
|
|
26
|
+
/** 初始化配置选项 */
|
|
27
|
+
export interface initConfigOptions extends InitConfigFileOptions {
|
|
28
|
+
}
|
|
29
|
+
/** 检测配置选项 */
|
|
30
|
+
export interface CheckConfigOptions extends ReadConfigFileOptions, Partial<ConfigConfig> {
|
|
31
|
+
}
|
|
32
|
+
/** 添加配置选项 */
|
|
33
|
+
export interface AddConfigOptions extends ReadConfigFileOptions, Partial<ConfigConfig> {
|
|
34
|
+
/** 是否直接提交git */
|
|
35
|
+
commitGit?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** 各类型工程化配置信息 */
|
|
38
|
+
export type TypeConfigInfo = {
|
|
39
|
+
[key in ConfigModuleEnum]?: {
|
|
40
|
+
version: string;
|
|
41
|
+
/** 配置文件相对路径 */
|
|
42
|
+
configFileRelativePathList: string[];
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/** 配置文件信息 */
|
|
46
|
+
export interface ConfigConfigFileInfo {
|
|
47
|
+
/**
|
|
48
|
+
* 待复制的配置文件路径
|
|
49
|
+
* ---
|
|
50
|
+
* 相对于当前工程化模块目录对应的版本目录
|
|
51
|
+
*/
|
|
52
|
+
sourceFile: string;
|
|
53
|
+
/**
|
|
54
|
+
* 目标配置文件路径
|
|
55
|
+
* ---
|
|
56
|
+
* 相对于命令运行目录
|
|
57
|
+
*/
|
|
58
|
+
targetFile: string;
|
|
59
|
+
/** 描述 */
|
|
60
|
+
description?: string;
|
|
61
|
+
/** 当前配置依赖的额外包 */
|
|
62
|
+
relyPackages?: string[];
|
|
63
|
+
}
|
|
64
|
+
/** 项目配置单项 */
|
|
65
|
+
export interface ConfigProjectConfigItem {
|
|
66
|
+
version: string;
|
|
67
|
+
/** 配置文件配置列表 */
|
|
68
|
+
configFileInfoList: ConfigConfigFileInfo[];
|
|
69
|
+
/** 依赖的包 */
|
|
70
|
+
relyPackages?: string[];
|
|
71
|
+
/** package.json需要添加的配置 */
|
|
72
|
+
packageJson?: {
|
|
73
|
+
scripts?: Record<string, string>;
|
|
74
|
+
"lint-staged"?: Record<string, string[]>;
|
|
75
|
+
};
|
|
76
|
+
/** husky需要添加的配置 */
|
|
77
|
+
husky?: {
|
|
78
|
+
hooks?: Record<string, string>;
|
|
79
|
+
};
|
|
80
|
+
/** 运行脚本 */
|
|
81
|
+
runScripts?: string[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 项目配置
|
|
85
|
+
* ---
|
|
86
|
+
* value 为 string时则是该模块对应的预置列表json文件名【相对于所属工程化模块目录】,如 reset-list.json
|
|
87
|
+
*/
|
|
88
|
+
export type ConfigProject = Record<string, ConfigProjectConfigItem[] | string>;
|
|
89
|
+
/** 工程化配置 */
|
|
90
|
+
export interface ConfigConfigJson {
|
|
91
|
+
project: ConfigProject;
|
|
92
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AddConfigOptions, CheckConfigOptions, ConfigConfig, TypeConfigInfo } from '../types';
|
|
2
|
+
import { ConfigModuleEnum } from '../types';
|
|
3
|
+
/** 允许的模块 */
|
|
4
|
+
export declare const ALLOW_MODULE_LIST: ConfigModuleEnum[];
|
|
5
|
+
export declare const getConfig: (argv: CheckConfigOptions | AddConfigOptions) => Promise<ConfigConfig>;
|
|
6
|
+
/** 配置模块与包名的映射 */
|
|
7
|
+
export declare const configModulePkgNameMap: {
|
|
8
|
+
[key in ConfigModuleEnum]: string;
|
|
9
|
+
};
|
|
10
|
+
/** 配置类型与配置文件后缀的映射 */
|
|
11
|
+
export declare const configModuleConfigFileSuffixMap: {
|
|
12
|
+
[key in ConfigModuleEnum]: string[];
|
|
13
|
+
};
|
|
14
|
+
/** 矫正配置模块列表 */
|
|
15
|
+
export declare const adjustModuleList: (list: string[]) => ConfigModuleEnum[];
|
|
16
|
+
/** 获取配置信息 */
|
|
17
|
+
export declare const getConfigInfo: ({ config, rootDir, }: {
|
|
18
|
+
config: ConfigConfig;
|
|
19
|
+
rootDir: string;
|
|
20
|
+
}) => TypeConfigInfo;
|