@done-coding/cli-component 0.4.10-alpha.1 → 0.4.11-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/cli.mjs +1 -1
- package/es/{index-26ea3160.js → index-1913b07b.js} +79 -79
- package/es/index.mjs +1 -1
- package/package.json +9 -13
package/es/cli.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import p from "node:path";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import l from "node:fs";
|
|
4
|
+
import { outputConsole as m, json5 as L, chalk as b, xPrompts as w, createSubcommand as O, getRootScriptName as V, createMainCommand as J } from "@done-coding/cli-utils";
|
|
5
5
|
import x from "lodash.upperfirst";
|
|
6
6
|
import S from "lodash.camelcase";
|
|
7
7
|
import v from "lodash.kebabcase";
|
|
8
8
|
import T from "lodash.lowerfirst";
|
|
9
9
|
import f from "lodash.template";
|
|
10
|
-
import { OutputModeEnum as
|
|
11
|
-
var
|
|
10
|
+
import { OutputModeEnum as C, compileHandler as E } from "@done-coding/cli-template";
|
|
11
|
+
var u = /* @__PURE__ */ ((e) => (e.ADD = "add", e.REMOVE = "remove", e.LIST = "list", e))(u || {});
|
|
12
12
|
const _ = (e, t) => {
|
|
13
13
|
if (!/^[a-zA-Z]+[a-zA-Z0-9-]*$/.test(e))
|
|
14
14
|
return m.error("组件名只能包含字母、数字、中划线"), process.exit(1);
|
|
@@ -17,7 +17,7 @@ const _ = (e, t) => {
|
|
|
17
17
|
保留名称: ${n.join(",")}`), process.exit(1)) : !0;
|
|
18
18
|
}, g = {
|
|
19
19
|
name: "@done-coding/cli-component",
|
|
20
|
-
version: "0.4.
|
|
20
|
+
version: "0.4.11-alpha.0",
|
|
21
21
|
description: "组件命令行工具",
|
|
22
22
|
bin: {
|
|
23
23
|
"dc-component": "es/cli.mjs"
|
|
@@ -26,13 +26,13 @@ const _ = (e, t) => {
|
|
|
26
26
|
namespaceDir: ".done-coding",
|
|
27
27
|
moduleName: "component"
|
|
28
28
|
}
|
|
29
|
-
}, { namespaceDir: K, moduleName:
|
|
29
|
+
}, { namespaceDir: K, moduleName: B } = g.cliConfig, N = () => p.resolve(K, B), I = () => ({
|
|
30
30
|
execDir: process.cwd(),
|
|
31
31
|
templateDir: N()
|
|
32
32
|
}), D = (e) => {
|
|
33
|
-
const { series: t, name: n } = e, o = x(S(n)), c = T(o), a = v(o),
|
|
33
|
+
const { series: t, name: n } = e, o = x(S(n)), c = T(o), a = v(o), r = t ? x(S(t)) : "", i = r ? `${r}${o}` : "", d = v(i);
|
|
34
34
|
return {
|
|
35
|
-
series:
|
|
35
|
+
series: r,
|
|
36
36
|
name: o,
|
|
37
37
|
nameLowerFirst: c,
|
|
38
38
|
nameKebab: a,
|
|
@@ -40,42 +40,42 @@ const _ = (e, t) => {
|
|
|
40
40
|
fullNameKebab: d,
|
|
41
41
|
cls: d
|
|
42
42
|
};
|
|
43
|
-
},
|
|
43
|
+
}, z = (e) => ({
|
|
44
44
|
$: "$",
|
|
45
45
|
...I(),
|
|
46
46
|
...D(e)
|
|
47
47
|
}), $ = () => {
|
|
48
48
|
const e = p.resolve(N(), "index.json");
|
|
49
|
-
if (!
|
|
49
|
+
if (!l.existsSync(e))
|
|
50
50
|
return m.error(`模块入口文件不存在: ${e}`), process.exit(1);
|
|
51
|
-
const n = JSON.parse(
|
|
51
|
+
const n = JSON.parse(l.readFileSync(e, "utf-8")).config;
|
|
52
52
|
if (!n)
|
|
53
53
|
return m.error(`配置文件相对路径不存在: ${n}`), process.exit(1);
|
|
54
54
|
const o = p.resolve(
|
|
55
55
|
p.dirname(e),
|
|
56
56
|
n
|
|
57
57
|
);
|
|
58
|
-
if (!
|
|
58
|
+
if (!l.existsSync(o))
|
|
59
59
|
return m.error(`配置文件不存在: ${o}`), process.exit(1);
|
|
60
|
-
const c =
|
|
61
|
-
return c.componentDir = f(c.componentDir)(a),
|
|
60
|
+
const c = L.parse(l.readFileSync(o, "utf-8")), a = I();
|
|
61
|
+
return c.componentDir = f(c.componentDir)(a), l.existsSync(c.componentDir) || l.mkdirSync(c.componentDir, {
|
|
62
62
|
recursive: !0
|
|
63
63
|
}), c;
|
|
64
|
-
},
|
|
64
|
+
}, k = async ({
|
|
65
65
|
name: e,
|
|
66
66
|
config: t,
|
|
67
67
|
command: n
|
|
68
68
|
}) => {
|
|
69
|
-
if (![
|
|
69
|
+
if (![u.ADD, u.REMOVE].includes(n))
|
|
70
70
|
return m.error(`不支持组件${n}操作`), process.exit(1);
|
|
71
|
-
const o =
|
|
71
|
+
const o = z({
|
|
72
72
|
...t,
|
|
73
73
|
name: e
|
|
74
74
|
}), c = process.cwd(), a = JSON.stringify(o);
|
|
75
|
-
for (const { entry:
|
|
75
|
+
for (const { entry: r, index: i } of t.list) {
|
|
76
76
|
const d = {
|
|
77
77
|
envData: a,
|
|
78
|
-
rollback: n ===
|
|
78
|
+
rollback: n === u.REMOVE,
|
|
79
79
|
/** 回滚时可以删除空文件 */
|
|
80
80
|
rollbackDelNullFile: !0,
|
|
81
81
|
rollbackDelAskAsYes: !0,
|
|
@@ -83,28 +83,28 @@ const _ = (e, t) => {
|
|
|
83
83
|
batch: !1,
|
|
84
84
|
rootDir: c
|
|
85
85
|
};
|
|
86
|
-
if (
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
...
|
|
91
|
-
mode:
|
|
86
|
+
if (r) {
|
|
87
|
+
const s = r;
|
|
88
|
+
s != null && s.input && (s.input = f(s.input)(o)), s != null && s.output && (s.output = f(s.output)(o));
|
|
89
|
+
const h = {
|
|
90
|
+
...r,
|
|
91
|
+
mode: C.APPEND,
|
|
92
92
|
...d
|
|
93
93
|
};
|
|
94
|
-
await
|
|
94
|
+
await E(h);
|
|
95
95
|
}
|
|
96
96
|
if (i) {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const
|
|
97
|
+
const s = i;
|
|
98
|
+
s != null && s.input && (s.input = f(s.input)(o)), s != null && s.output && (s.output = f(s.output)(o));
|
|
99
|
+
const h = {
|
|
100
100
|
...i,
|
|
101
|
-
mode:
|
|
101
|
+
mode: C.OVERWRITE,
|
|
102
102
|
...d
|
|
103
103
|
};
|
|
104
|
-
await
|
|
104
|
+
await E(h);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
},
|
|
107
|
+
}, Z = () => ({
|
|
108
108
|
outputJson: {
|
|
109
109
|
alias: "o",
|
|
110
110
|
describe: "是否输出组件名列表json",
|
|
@@ -118,45 +118,45 @@ const _ = (e, t) => {
|
|
|
118
118
|
}
|
|
119
119
|
}), y = (e) => {
|
|
120
120
|
const { componentDir: t, nameExcludes: n } = e;
|
|
121
|
-
return
|
|
122
|
-
const i = p.join(t,
|
|
123
|
-
return
|
|
124
|
-
}).filter((
|
|
125
|
-
},
|
|
121
|
+
return l.statSync(t).isDirectory() ? l.readdirSync(t).map((r) => {
|
|
122
|
+
const i = p.join(t, r);
|
|
123
|
+
return l.statSync(i).isDirectory() ? (m.info("filePath:", i, p.basename(i)), p.basename(i)) : "";
|
|
124
|
+
}).filter((r) => !(!r || n.includes(r))) : (m.error("组件源码路径不是目录"), process.exit(1));
|
|
125
|
+
}, R = async ({
|
|
126
126
|
outputJson: e,
|
|
127
127
|
outputPath: t
|
|
128
128
|
}) => {
|
|
129
129
|
m.stage("展示列表");
|
|
130
|
-
const n = $(), o = y(n), c = t || n.nameListJsonOutputPath, a = o.map((
|
|
130
|
+
const n = $(), o = y(n), c = t || n.nameListJsonOutputPath, a = o.map((r) => {
|
|
131
131
|
const { name: i, fullName: d } = D({
|
|
132
132
|
...n,
|
|
133
|
-
name:
|
|
133
|
+
name: r
|
|
134
134
|
});
|
|
135
135
|
return {
|
|
136
136
|
name: i,
|
|
137
|
-
nameKebab:
|
|
137
|
+
nameKebab: r,
|
|
138
138
|
fullName: d
|
|
139
139
|
};
|
|
140
140
|
});
|
|
141
141
|
if (m.table(
|
|
142
|
-
a.map(({ name:
|
|
143
|
-
[
|
|
144
|
-
[
|
|
145
|
-
[
|
|
142
|
+
a.map(({ name: r, fullName: i, nameKebab: d }) => ({
|
|
143
|
+
[b.greenBright("名称")]: r,
|
|
144
|
+
[b.greenBright("带系列名称")]: i,
|
|
145
|
+
[b.greenBright("绝对路径")]: p.resolve(
|
|
146
146
|
n.componentDir,
|
|
147
147
|
d
|
|
148
148
|
)
|
|
149
149
|
}))
|
|
150
150
|
), e && c) {
|
|
151
|
-
const
|
|
152
|
-
|
|
151
|
+
const r = p.resolve(c), i = p.dirname(r);
|
|
152
|
+
l.existsSync(i) || l.mkdirSync(i, { recursive: !0 }), m.stage(`输出组件名列表到${r}`), l.writeFileSync(r, JSON.stringify(a, null, 2));
|
|
153
153
|
}
|
|
154
|
-
},
|
|
155
|
-
command:
|
|
154
|
+
}, H = {
|
|
155
|
+
command: u.LIST,
|
|
156
156
|
describe: "展示组件列表",
|
|
157
|
-
options:
|
|
158
|
-
handler:
|
|
159
|
-
},
|
|
157
|
+
options: Z(),
|
|
158
|
+
handler: R
|
|
159
|
+
}, U = () => ({
|
|
160
160
|
name: {
|
|
161
161
|
describe: "组件名称",
|
|
162
162
|
type: "string"
|
|
@@ -180,17 +180,17 @@ const _ = (e, t) => {
|
|
|
180
180
|
name: t
|
|
181
181
|
}).nameKebab === a)
|
|
182
182
|
return m.error(`组件${a}已存在, 不能再次创建${t}组件`), process.exit(1);
|
|
183
|
-
return
|
|
183
|
+
return k({
|
|
184
184
|
name: t,
|
|
185
185
|
config: n,
|
|
186
|
-
command:
|
|
186
|
+
command: u.ADD
|
|
187
187
|
});
|
|
188
|
-
},
|
|
189
|
-
command: `${
|
|
188
|
+
}, W = {
|
|
189
|
+
command: `${u.ADD} <name>`,
|
|
190
190
|
describe: "新增一个组件",
|
|
191
|
-
positionals:
|
|
191
|
+
positionals: U(),
|
|
192
192
|
handler: A
|
|
193
|
-
},
|
|
193
|
+
}, Y = () => ({
|
|
194
194
|
name: {
|
|
195
195
|
describe: "组件名称",
|
|
196
196
|
type: "string"
|
|
@@ -215,55 +215,55 @@ const _ = (e, t) => {
|
|
|
215
215
|
series: c,
|
|
216
216
|
name: o
|
|
217
217
|
}).nameKebab === a) {
|
|
218
|
-
await
|
|
218
|
+
await k({
|
|
219
219
|
name: o,
|
|
220
220
|
config: t,
|
|
221
|
-
command:
|
|
222
|
-
}),
|
|
221
|
+
command: u.REMOVE
|
|
222
|
+
}), l.rmdirSync(p.resolve(t.componentDir, a));
|
|
223
223
|
return;
|
|
224
224
|
}
|
|
225
225
|
return m.error(`组件${o}不存在`), process.exit(1);
|
|
226
|
-
},
|
|
227
|
-
command: `${
|
|
226
|
+
}, q = {
|
|
227
|
+
command: `${u.REMOVE} [name]`,
|
|
228
228
|
describe: "删除一个组件",
|
|
229
|
-
positionals:
|
|
229
|
+
positionals: Y(),
|
|
230
230
|
handler: M
|
|
231
231
|
}, ce = async (e, t) => {
|
|
232
232
|
switch (e) {
|
|
233
|
-
case
|
|
233
|
+
case u.ADD:
|
|
234
234
|
return A(t);
|
|
235
|
-
case
|
|
235
|
+
case u.REMOVE:
|
|
236
236
|
return M(t);
|
|
237
|
-
case
|
|
238
|
-
return
|
|
237
|
+
case u.LIST:
|
|
238
|
+
return R(t);
|
|
239
239
|
default:
|
|
240
240
|
throw new Error(`不支持的命令 ${e}`);
|
|
241
241
|
}
|
|
242
|
-
}, { version: G, description: Q } = g,
|
|
242
|
+
}, { version: G, description: Q } = g, j = {
|
|
243
243
|
describe: Q,
|
|
244
244
|
version: G,
|
|
245
245
|
subcommands: [
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
246
|
+
W,
|
|
247
|
+
q,
|
|
248
|
+
H
|
|
249
249
|
].map(O),
|
|
250
250
|
demandCommandCount: 1,
|
|
251
251
|
rootScriptName: V({ packageJson: g })
|
|
252
252
|
}, {
|
|
253
253
|
cliConfig: { moduleName: P }
|
|
254
|
-
} = g,
|
|
254
|
+
} = g, F = (e = !1) => {
|
|
255
255
|
const t = e ? P : void 0, n = `$0${e ? ` ${P}` : ""} <command> [options]`;
|
|
256
256
|
return { command: t, usage: n };
|
|
257
257
|
}, me = async () => J({
|
|
258
|
-
...
|
|
259
|
-
...
|
|
260
|
-
}),
|
|
261
|
-
...
|
|
262
|
-
...
|
|
258
|
+
...j,
|
|
259
|
+
...F()
|
|
260
|
+
}), le = () => O({
|
|
261
|
+
...j,
|
|
262
|
+
...F(!0)
|
|
263
263
|
});
|
|
264
264
|
export {
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
u as S,
|
|
266
|
+
le as a,
|
|
267
267
|
me as c,
|
|
268
268
|
ce as h
|
|
269
269
|
};
|
package/es/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-component",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.11-alpha.0",
|
|
4
4
|
"description": "组件命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -21,10 +21,7 @@
|
|
|
21
21
|
"types"
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
|
-
"
|
|
25
|
-
"predev": "pnpm run clean",
|
|
26
|
-
"dev": "vite build --watch",
|
|
27
|
-
"prebuild": "pnpm run clean",
|
|
24
|
+
"dev": "vite build -w -m hotBuild",
|
|
28
25
|
"build": "vite build",
|
|
29
26
|
"prepack": "pnpm build"
|
|
30
27
|
},
|
|
@@ -41,7 +38,7 @@
|
|
|
41
38
|
"license": "MIT",
|
|
42
39
|
"sideEffects": false,
|
|
43
40
|
"devDependencies": {
|
|
44
|
-
"@done-coding/cli-inject": "0.5.
|
|
41
|
+
"@done-coding/cli-inject": "0.5.22-alpha.0",
|
|
45
42
|
"@types/lodash.camelcase": "^4.3.8",
|
|
46
43
|
"@types/lodash.kebabcase": "^4.1.8",
|
|
47
44
|
"@types/lodash.lowerfirst": "^4.3.8",
|
|
@@ -49,22 +46,21 @@
|
|
|
49
46
|
"@types/lodash.upperfirst": "^4.3.8",
|
|
50
47
|
"@types/node": "^18.0.0",
|
|
51
48
|
"@types/yargs": "^17.0.28",
|
|
52
|
-
"rimraf": "^6.0.1",
|
|
53
49
|
"typescript": "^5.8.3",
|
|
54
50
|
"vite": "^4.4.11",
|
|
55
51
|
"vite-plugin-dts": "^3.6.0"
|
|
56
52
|
},
|
|
57
|
-
"engines": {
|
|
58
|
-
"node": ">=18.0.0"
|
|
59
|
-
},
|
|
60
53
|
"dependencies": {
|
|
61
|
-
"@done-coding/cli-template": "0.8.
|
|
62
|
-
"@done-coding/cli-utils": "0.8.
|
|
54
|
+
"@done-coding/cli-template": "0.8.9-alpha.0",
|
|
55
|
+
"@done-coding/cli-utils": "0.8.3-alpha.0",
|
|
63
56
|
"lodash.camelcase": "^4.3.0",
|
|
64
57
|
"lodash.kebabcase": "^4.1.1",
|
|
65
58
|
"lodash.lowerfirst": "^4.3.1",
|
|
66
59
|
"lodash.template": "^4.5.0",
|
|
67
60
|
"lodash.upperfirst": "^4.3.1"
|
|
68
61
|
},
|
|
69
|
-
"
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=18.0.0"
|
|
64
|
+
},
|
|
65
|
+
"gitHead": "906b7683d9e4dc75fb07806b12e5507827122a16"
|
|
70
66
|
}
|