@done-coding/cli-config 0.1.9 → 0.1.11
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/cli.mjs +1 -1
- package/es/{index-436a0546.js → index-7d957358.js} +73 -72
- package/es/index.mjs +1 -1
- package/package.json +4 -4
package/es/cli.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readConfigFile as B, log as i, getPackageJson as Q, getRelyPkgVersion as X, getConfigFileCommonOptions as Y,
|
|
2
|
+
import { readConfigFile as B, log as i, getPackageJson as Q, getRelyPkgVersion as X, getConfigFileCommonOptions as Y, readCliModuleAssetsConfig as Z, xPrompts as w, addPackageConfig as ee, addHuskyHooks as te, createSubcommand as J, getRootScriptName as oe, createMainCommand as ne } from "@done-coding/cli-utils";
|
|
3
3
|
import k, { existsSync as C } from "node:fs";
|
|
4
4
|
import g from "node:path";
|
|
5
5
|
import { execSync as N } from "node:child_process";
|
|
6
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
7
|
const L = {
|
|
8
8
|
name: "@done-coding/cli-config",
|
|
9
|
-
version: "0.1.
|
|
9
|
+
version: "0.1.11",
|
|
10
10
|
description: "工程化配置命令行工具",
|
|
11
11
|
bin: {
|
|
12
12
|
"dc-config": "es/cli.mjs"
|
|
@@ -36,59 +36,59 @@ const L = {
|
|
|
36
36
|
[m.COMMITLINT]: "@commitlint/cli",
|
|
37
37
|
[m.LSLINT]: "@ls-lint/ls-lint",
|
|
38
38
|
[m.MERGELINT]: "@done-coding/cli-git"
|
|
39
|
-
},
|
|
39
|
+
}, o = "_$_", le = {
|
|
40
40
|
[m.ESLINT]: [
|
|
41
|
-
`${
|
|
42
|
-
`${
|
|
43
|
-
`${
|
|
44
|
-
`.${
|
|
45
|
-
`.${
|
|
46
|
-
`.${
|
|
47
|
-
`.${
|
|
48
|
-
`.${
|
|
49
|
-
`.${
|
|
50
|
-
`.${
|
|
41
|
+
`${o}.config.js`,
|
|
42
|
+
`${o}.config.mjs`,
|
|
43
|
+
`${o}.config.cjs`,
|
|
44
|
+
`.${o}rc`,
|
|
45
|
+
`.${o}rc.js`,
|
|
46
|
+
`.${o}rc.json`,
|
|
47
|
+
`.${o}rc.mjs`,
|
|
48
|
+
`.${o}rc.cjs`,
|
|
49
|
+
`.${o}rc.yaml`,
|
|
50
|
+
`.${o}rc.yml`
|
|
51
51
|
],
|
|
52
52
|
[m.PRETTIER]: [
|
|
53
|
-
`${
|
|
54
|
-
`${
|
|
55
|
-
`${
|
|
56
|
-
`.${
|
|
57
|
-
`.${
|
|
58
|
-
`.${
|
|
59
|
-
`.${
|
|
60
|
-
`.${
|
|
61
|
-
`.${
|
|
62
|
-
`.${
|
|
63
|
-
`.${
|
|
64
|
-
`.${
|
|
53
|
+
`${o}.config.js`,
|
|
54
|
+
`${o}.config.mjs`,
|
|
55
|
+
`${o}.config.cjs`,
|
|
56
|
+
`.${o}rc`,
|
|
57
|
+
`.${o}rc.js`,
|
|
58
|
+
`.${o}rc.json`,
|
|
59
|
+
`.${o}rc.json5`,
|
|
60
|
+
`.${o}rc.mjs`,
|
|
61
|
+
`.${o}rc.cjs`,
|
|
62
|
+
`.${o}rc.yaml`,
|
|
63
|
+
`.${o}rc.yml`,
|
|
64
|
+
`.${o}rc.toml`
|
|
65
65
|
],
|
|
66
66
|
[m.COMMITLINT]: [
|
|
67
|
-
`${
|
|
68
|
-
`${
|
|
69
|
-
`${
|
|
70
|
-
`.${
|
|
71
|
-
`.${
|
|
72
|
-
`.${
|
|
73
|
-
`.${
|
|
74
|
-
`.${
|
|
75
|
-
`.${
|
|
76
|
-
`.${
|
|
67
|
+
`${o}.config.js`,
|
|
68
|
+
`${o}.config.mjs`,
|
|
69
|
+
`${o}.config.cjs`,
|
|
70
|
+
`.${o}rc`,
|
|
71
|
+
`.${o}rc.js`,
|
|
72
|
+
`.${o}rc.json`,
|
|
73
|
+
`.${o}rc.mjs`,
|
|
74
|
+
`.${o}rc.cjs`,
|
|
75
|
+
`.${o}rc.yaml`,
|
|
76
|
+
`.${o}rc.yml`
|
|
77
77
|
],
|
|
78
|
-
[m.LSLINT]: [`.${
|
|
78
|
+
[m.LSLINT]: [`.${o}.yaml`, `.${o}.yml`],
|
|
79
79
|
[m.MERGELINT]: [".done-coding/git.json"]
|
|
80
|
-
}, me = (e, t) => t.filter((
|
|
81
|
-
const
|
|
82
|
-
return
|
|
80
|
+
}, me = (e, t) => t.filter((n) => C(g.resolve(e, n))), _ = (e) => e.filter((t) => {
|
|
81
|
+
const n = I.includes(t);
|
|
82
|
+
return n || i.warn(
|
|
83
83
|
`当前不支持${t}的配置检测, 支持的类型有${I.join(
|
|
84
84
|
", "
|
|
85
85
|
)}`
|
|
86
|
-
),
|
|
86
|
+
), n;
|
|
87
87
|
}), de = ({
|
|
88
88
|
config: e,
|
|
89
89
|
rootDir: t
|
|
90
90
|
}) => {
|
|
91
|
-
const { moduleList:
|
|
91
|
+
const { moduleList: n = [] } = e, s = _(n);
|
|
92
92
|
i.stage(`开始获取${s.join(", ")}配置信息...`);
|
|
93
93
|
const r = Q({ rootDir: t });
|
|
94
94
|
return s.reduce(
|
|
@@ -101,7 +101,7 @@ const L = {
|
|
|
101
101
|
});
|
|
102
102
|
if (!f)
|
|
103
103
|
return a;
|
|
104
|
-
const c = le[l].map((u) => u.replace(
|
|
104
|
+
const c = le[l].map((u) => u.replace(o, l));
|
|
105
105
|
return c.length ? (a[l] = {
|
|
106
106
|
version: f,
|
|
107
107
|
configFileRelativePathList: me(
|
|
@@ -126,11 +126,11 @@ const L = {
|
|
|
126
126
|
)
|
|
127
127
|
}
|
|
128
128
|
}), E = async (e) => {
|
|
129
|
-
const t = await ae(e),
|
|
129
|
+
const t = await ae(e), n = de({ config: t, rootDir: e.rootDir });
|
|
130
130
|
return i.success(`检测到工程化配置信息:
|
|
131
|
-
${JSON.stringify(
|
|
131
|
+
${JSON.stringify(n, null, 2)}`), {
|
|
132
132
|
config: t,
|
|
133
|
-
info:
|
|
133
|
+
info: n
|
|
134
134
|
};
|
|
135
135
|
}, ue = {
|
|
136
136
|
command: y.CHECK,
|
|
@@ -161,7 +161,7 @@ ${JSON.stringify(o, null, 2)}`), {
|
|
|
161
161
|
`${e} 跳过版本选择: 仅有一个预设版本配置, 默认选择第一个(${s.version})`
|
|
162
162
|
), s;
|
|
163
163
|
}
|
|
164
|
-
const { version:
|
|
164
|
+
const { version: n } = await w({
|
|
165
165
|
type: "select",
|
|
166
166
|
name: "version",
|
|
167
167
|
message: `请选择需要添加的${e}版本`,
|
|
@@ -173,18 +173,18 @@ ${JSON.stringify(o, null, 2)}`), {
|
|
|
173
173
|
};
|
|
174
174
|
})
|
|
175
175
|
});
|
|
176
|
-
return t.find((s) => s.version ===
|
|
176
|
+
return t.find((s) => s.version === n);
|
|
177
177
|
}, pe = async ({
|
|
178
178
|
moduleName: e,
|
|
179
179
|
moduleConfig: t
|
|
180
180
|
}) => {
|
|
181
|
-
const { configFileInfoList:
|
|
182
|
-
if (!Array.isArray(
|
|
181
|
+
const { configFileInfoList: n } = t;
|
|
182
|
+
if (!Array.isArray(n) || n.length === 0) {
|
|
183
183
|
i.error(`未找到 ${e} 配置文件信息列表`);
|
|
184
184
|
return;
|
|
185
185
|
}
|
|
186
|
-
if (
|
|
187
|
-
const r =
|
|
186
|
+
if (n.length === 1) {
|
|
187
|
+
const r = n[0];
|
|
188
188
|
return i.skip(
|
|
189
189
|
`${e} 跳过配置文件信息选择: 仅有一个配置文件信息, 默认选择第一个(${r.sourceFile})`
|
|
190
190
|
), r;
|
|
@@ -193,7 +193,7 @@ ${JSON.stringify(o, null, 2)}`), {
|
|
|
193
193
|
type: "select",
|
|
194
194
|
name: "info",
|
|
195
195
|
message: "请选择需要添加的配置文件",
|
|
196
|
-
choices:
|
|
196
|
+
choices: n.map((r) => {
|
|
197
197
|
const { sourceFile: a, description: l } = r;
|
|
198
198
|
return {
|
|
199
199
|
title: a,
|
|
@@ -202,10 +202,10 @@ ${JSON.stringify(o, null, 2)}`), {
|
|
|
202
202
|
};
|
|
203
203
|
})
|
|
204
204
|
});
|
|
205
|
-
return
|
|
205
|
+
return n.find((r) => r.sourceFile === s.sourceFile);
|
|
206
206
|
}, ye = ({ rootDir: e, list: t }) => {
|
|
207
207
|
i.stage(`开始安装依赖包: ${JSON.stringify(t, null, 2)}`);
|
|
208
|
-
const
|
|
208
|
+
const n = g.resolve(e, "pnpm-workspace.yaml"), s = C(n);
|
|
209
209
|
N(`pnpm add -D ${s ? "-w" : ""} ${t.join(" ")}`, {
|
|
210
210
|
cwd: e,
|
|
211
211
|
stdio: "inherit"
|
|
@@ -213,16 +213,16 @@ ${JSON.stringify(o, null, 2)}`), {
|
|
|
213
213
|
}, Le = async ({
|
|
214
214
|
hooksConfig: e,
|
|
215
215
|
argv: t
|
|
216
|
-
}) => Object.entries(e).forEach(async ([
|
|
216
|
+
}) => Object.entries(e).forEach(async ([n, s]) => {
|
|
217
217
|
await te({
|
|
218
|
-
hookNames: [
|
|
218
|
+
hookNames: [n],
|
|
219
219
|
rootDir: t.rootDir,
|
|
220
220
|
getCode: () => s
|
|
221
221
|
});
|
|
222
222
|
}), he = async ({
|
|
223
223
|
moduleName: e,
|
|
224
224
|
moduleConfigList: t,
|
|
225
|
-
argv:
|
|
225
|
+
argv: n
|
|
226
226
|
}) => {
|
|
227
227
|
const s = await $e({
|
|
228
228
|
moduleName: e,
|
|
@@ -252,7 +252,7 @@ ${JSON.stringify(o, null, 2)}`), {
|
|
|
252
252
|
return i.stage(`需要安装的依赖包:
|
|
253
253
|
${JSON.stringify($, null, 2)}`), await ee({
|
|
254
254
|
patchConfig: s.packageJson,
|
|
255
|
-
rootDir:
|
|
255
|
+
rootDir: n.rootDir
|
|
256
256
|
}), {
|
|
257
257
|
sourceFile: u,
|
|
258
258
|
targetFile: j,
|
|
@@ -264,21 +264,21 @@ ${JSON.stringify($, null, 2)}`), await ee({
|
|
|
264
264
|
var p;
|
|
265
265
|
return Le({
|
|
266
266
|
hooksConfig: ((p = s.husky) == null ? void 0 : p.hooks) || {},
|
|
267
|
-
argv:
|
|
267
|
+
argv: n
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
270
|
};
|
|
271
271
|
}, ke = ({
|
|
272
272
|
listConfig: e,
|
|
273
273
|
moduleDir: t,
|
|
274
|
-
moduleName:
|
|
274
|
+
moduleName: n
|
|
275
275
|
}) => {
|
|
276
276
|
if (typeof e == "string") {
|
|
277
277
|
console.log(e);
|
|
278
278
|
const s = g.resolve(t, e);
|
|
279
279
|
if (!C(s))
|
|
280
280
|
throw new Error(
|
|
281
|
-
`${
|
|
281
|
+
`${n} 预设列表文件 ${s} 不存在`
|
|
282
282
|
);
|
|
283
283
|
const r = k.readFileSync(s, "utf-8");
|
|
284
284
|
return JSON.parse(
|
|
@@ -287,13 +287,13 @@ ${JSON.stringify($, null, 2)}`), await ee({
|
|
|
287
287
|
} else {
|
|
288
288
|
if (!Array.isArray(e))
|
|
289
289
|
throw new Error(
|
|
290
|
-
`(${
|
|
290
|
+
`(${n})预置项必须是数组或者是相对于当前工程化配置模块目录的相对路径`
|
|
291
291
|
);
|
|
292
292
|
return e;
|
|
293
293
|
}
|
|
294
294
|
}, b = async (e) => {
|
|
295
|
-
const { config: t, info:
|
|
296
|
-
const u =
|
|
295
|
+
const { config: t, info: n } = await E(e), { moduleList: s = [] } = t, a = _(s).filter((c) => {
|
|
296
|
+
const u = n[c];
|
|
297
297
|
return u ? (i.skip(`
|
|
298
298
|
检测到 ${c} 已配置, ${JSON.stringify(u, null, 2)},
|
|
299
299
|
跳过添加 ${c}`), !1) : !0;
|
|
@@ -306,8 +306,10 @@ ${JSON.stringify($, null, 2)}`), await ee({
|
|
|
306
306
|
moduleName: fe,
|
|
307
307
|
onSuccess: async ({
|
|
308
308
|
config: c,
|
|
309
|
-
configTemporaryDir
|
|
310
|
-
cliConfigDirRelativePath
|
|
309
|
+
// configTemporaryDir,
|
|
310
|
+
// cliConfigDirRelativePath,
|
|
311
|
+
assetsConfigRepoTempDir: u,
|
|
312
|
+
moduleEntryFileRelativePath: j
|
|
311
313
|
}) => {
|
|
312
314
|
if (!(c != null && c.project))
|
|
313
315
|
throw new Error("项目工程化预设不存在");
|
|
@@ -316,8 +318,7 @@ ${JSON.stringify($, null, 2)}`), await ee({
|
|
|
316
318
|
for (let d of a) {
|
|
317
319
|
const v = g.resolve(
|
|
318
320
|
u,
|
|
319
|
-
j
|
|
320
|
-
d
|
|
321
|
+
j
|
|
321
322
|
), D = ke({
|
|
322
323
|
listConfig: S[d],
|
|
323
324
|
moduleDir: v,
|
|
@@ -388,13 +389,13 @@ ${JSON.stringify($, null, 2)}`), await ee({
|
|
|
388
389
|
version: Ie,
|
|
389
390
|
subcommands: [ue, Ne].map(J),
|
|
390
391
|
demandCommandCount: 1,
|
|
391
|
-
rootScriptName:
|
|
392
|
+
rootScriptName: oe({ packageJson: L })
|
|
392
393
|
}, {
|
|
393
394
|
cliConfig: { moduleName: O }
|
|
394
395
|
} = L, x = (e = !1) => {
|
|
395
|
-
const t = e ? O : void 0,
|
|
396
|
-
return { command: t, usage:
|
|
397
|
-
}, Pe = async () =>
|
|
396
|
+
const t = e ? O : void 0, n = `$0${e ? ` ${O}` : ""} <command> [options]`;
|
|
397
|
+
return { command: t, usage: n };
|
|
398
|
+
}, Pe = async () => ne({
|
|
398
399
|
...G,
|
|
399
400
|
...x()
|
|
400
401
|
}), Te = () => J({
|
package/es/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-config",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "工程化配置命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"sideEffects": false,
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@done-coding/cli-inject": "0.5.
|
|
44
|
+
"@done-coding/cli-inject": "0.5.19",
|
|
45
45
|
"@types/node": "^18.0.0",
|
|
46
46
|
"@types/yargs": "^17.0.28",
|
|
47
47
|
"rimraf": "^6.0.1",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"node": ">=18.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@done-coding/cli-utils": "0.
|
|
56
|
+
"@done-coding/cli-utils": "0.8.0"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "e68f726aa899f75c4d294b11620f343c953a74c3"
|
|
59
59
|
}
|