done-coding-component 0.4.9 → 0.4.12
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 -1
- package/es/cli.mjs +1 -1
- package/es/{index-578b8ec1.js → index-6793b622.js} +97 -97
- package/es/index.mjs +1 -1
- package/package.json +10 -11
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
## 安装
|
|
9
9
|
|
|
10
10
|
### 独立安装
|
|
11
|
+
|
|
11
12
|
```bash
|
|
12
13
|
npm install @done-coding/cli-component
|
|
13
14
|
# 或
|
|
@@ -15,6 +16,7 @@ pnpm add @done-coding/cli-component
|
|
|
15
16
|
```
|
|
16
17
|
|
|
17
18
|
### 作为 done-coding CLI 的一部分
|
|
19
|
+
|
|
18
20
|
```bash
|
|
19
21
|
npm install -g @done-coding/cli
|
|
20
22
|
# 然后使用
|
|
@@ -46,6 +48,7 @@ dc-component --help
|
|
|
46
48
|
### 基础命令
|
|
47
49
|
|
|
48
50
|
#### `dc-component add <name>`
|
|
51
|
+
|
|
49
52
|
新增一个组件
|
|
50
53
|
|
|
51
54
|
```bash
|
|
@@ -57,9 +60,11 @@ dc-component add UserCard
|
|
|
57
60
|
```
|
|
58
61
|
|
|
59
62
|
**参数说明**:
|
|
63
|
+
|
|
60
64
|
- `name`: 组件名称(必需)
|
|
61
65
|
|
|
62
66
|
#### `dc-component remove [name]`
|
|
67
|
+
|
|
63
68
|
删除一个组件
|
|
64
69
|
|
|
65
70
|
```bash
|
|
@@ -71,9 +76,11 @@ dc-component remove
|
|
|
71
76
|
```
|
|
72
77
|
|
|
73
78
|
**参数说明**:
|
|
79
|
+
|
|
74
80
|
- `name`: 组件名称(可选)
|
|
75
81
|
|
|
76
82
|
#### `dc-component list`
|
|
83
|
+
|
|
77
84
|
展示组件列表
|
|
78
85
|
|
|
79
86
|
```bash
|
|
@@ -117,6 +124,7 @@ done-coding component list
|
|
|
117
124
|
### 常见问题
|
|
118
125
|
|
|
119
126
|
**Q: 组件创建失败**
|
|
127
|
+
|
|
120
128
|
```bash
|
|
121
129
|
# 检查当前目录
|
|
122
130
|
pwd
|
|
@@ -126,6 +134,7 @@ dc-component add MyButton
|
|
|
126
134
|
```
|
|
127
135
|
|
|
128
136
|
**Q: 组件列表为空**
|
|
137
|
+
|
|
129
138
|
```bash
|
|
130
139
|
# 确认是否在正确的项目目录
|
|
131
140
|
ls -la
|
|
@@ -135,6 +144,7 @@ dc-component list
|
|
|
135
144
|
```
|
|
136
145
|
|
|
137
146
|
**Q: 删除组件失败**
|
|
147
|
+
|
|
138
148
|
```bash
|
|
139
149
|
# 确认组件名称正确
|
|
140
150
|
dc-component list
|
|
@@ -157,7 +167,7 @@ ls -la src/components/
|
|
|
157
167
|
|
|
158
168
|
```bash
|
|
159
169
|
# 克隆仓库
|
|
160
|
-
git clone https://
|
|
170
|
+
git clone https://github.com/done-coding/done-coding-cli.git
|
|
161
171
|
cd done-coding-cli/packages/component
|
|
162
172
|
|
|
163
173
|
# 安装依赖
|
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 h, 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.12",
|
|
21
21
|
description: "组件命令行工具",
|
|
22
22
|
bin: {
|
|
23
23
|
"dc-component": "es/cli.mjs"
|
|
@@ -26,85 +26,85 @@ 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)),
|
|
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
|
-
nameLowerFirst:
|
|
37
|
+
nameLowerFirst: c,
|
|
38
38
|
nameKebab: a,
|
|
39
|
-
fullName:
|
|
39
|
+
fullName: i,
|
|
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
|
|
61
|
-
return
|
|
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
|
-
}),
|
|
64
|
-
},
|
|
63
|
+
}), c;
|
|
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
|
-
}),
|
|
75
|
-
for (const { entry:
|
|
74
|
+
}), c = process.cwd(), a = JSON.stringify(o);
|
|
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,
|
|
82
82
|
dealMarkdown: !0,
|
|
83
83
|
batch: !1,
|
|
84
|
-
rootDir:
|
|
84
|
+
rootDir: c
|
|
85
85
|
};
|
|
86
|
-
if (
|
|
87
|
-
const
|
|
88
|
-
|
|
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
89
|
const b = {
|
|
90
|
-
...
|
|
91
|
-
mode:
|
|
90
|
+
...r,
|
|
91
|
+
mode: C.APPEND,
|
|
92
92
|
...d
|
|
93
93
|
};
|
|
94
|
-
await
|
|
94
|
+
await E(b);
|
|
95
95
|
}
|
|
96
|
-
if (
|
|
97
|
-
const
|
|
98
|
-
|
|
96
|
+
if (i) {
|
|
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
99
|
const b = {
|
|
100
|
-
...
|
|
101
|
-
mode:
|
|
100
|
+
...i,
|
|
101
|
+
mode: C.OVERWRITE,
|
|
102
102
|
...d
|
|
103
103
|
};
|
|
104
|
-
await
|
|
104
|
+
await E(b);
|
|
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
|
|
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 =
|
|
131
|
-
const { name:
|
|
130
|
+
const n = $(), o = y(n), c = t || n.nameListJsonOutputPath, a = o.map((r) => {
|
|
131
|
+
const { name: i, fullName: d } = D({
|
|
132
132
|
...n,
|
|
133
|
-
name:
|
|
133
|
+
name: r
|
|
134
134
|
});
|
|
135
135
|
return {
|
|
136
|
-
name:
|
|
137
|
-
nameKebab:
|
|
136
|
+
name: i,
|
|
137
|
+
nameKebab: r,
|
|
138
138
|
fullName: d
|
|
139
139
|
};
|
|
140
140
|
});
|
|
141
|
-
if (
|
|
142
|
-
a.map(({ name:
|
|
143
|
-
[
|
|
144
|
-
[
|
|
145
|
-
[
|
|
141
|
+
if (m.table(
|
|
142
|
+
a.map(({ name: r, fullName: i, nameKebab: d }) => ({
|
|
143
|
+
[h.greenBright("名称")]: r,
|
|
144
|
+
[h.greenBright("带系列名称")]: i,
|
|
145
|
+
[h.greenBright("绝对路径")]: p.resolve(
|
|
146
146
|
n.componentDir,
|
|
147
147
|
d
|
|
148
148
|
)
|
|
149
149
|
}))
|
|
150
|
-
), e &&
|
|
151
|
-
const
|
|
152
|
-
|
|
150
|
+
), e && c) {
|
|
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"
|
|
@@ -171,26 +171,26 @@ const _ = (e, t) => {
|
|
|
171
171
|
name: "name",
|
|
172
172
|
message: "请输入组件名"
|
|
173
173
|
})).name;
|
|
174
|
-
const n =
|
|
174
|
+
const n = $();
|
|
175
175
|
_(t, n);
|
|
176
|
-
const { series: o } = n,
|
|
177
|
-
for (let a of
|
|
176
|
+
const { series: o } = n, c = await y(n);
|
|
177
|
+
for (let a of c)
|
|
178
178
|
if (D({
|
|
179
179
|
series: o,
|
|
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"
|
|
@@ -199,7 +199,7 @@ const _ = (e, t) => {
|
|
|
199
199
|
name: e
|
|
200
200
|
}) => {
|
|
201
201
|
m.stage("移除组件");
|
|
202
|
-
const t =
|
|
202
|
+
const t = $(), n = await y(t);
|
|
203
203
|
if (n.length === 0)
|
|
204
204
|
return m.error("组件列表为空"), process.exit(1);
|
|
205
205
|
let o;
|
|
@@ -209,61 +209,61 @@ const _ = (e, t) => {
|
|
|
209
209
|
message: "请选择要移除的组件",
|
|
210
210
|
choices: n.map((a) => ({ title: a, value: a }))
|
|
211
211
|
})).name;
|
|
212
|
-
const { series:
|
|
212
|
+
const { series: c } = t;
|
|
213
213
|
for (let a of n)
|
|
214
214
|
if (D({
|
|
215
|
-
series:
|
|
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-component",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.12",
|
|
4
4
|
"description": "组件命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
|
-
"url": "https://
|
|
23
|
+
"url": "https://github.com/done-coding/done-coding-cli.git",
|
|
24
24
|
"directory": "packages/component"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"sideEffects": false,
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@done-coding/cli-inject": "0.5.
|
|
34
|
+
"@done-coding/cli-inject": "0.5.23",
|
|
35
35
|
"@types/lodash.camelcase": "^4.3.8",
|
|
36
36
|
"@types/lodash.kebabcase": "^4.1.8",
|
|
37
37
|
"@types/lodash.lowerfirst": "^4.3.8",
|
|
@@ -39,23 +39,22 @@
|
|
|
39
39
|
"@types/lodash.upperfirst": "^4.3.8",
|
|
40
40
|
"@types/node": "^18.0.0",
|
|
41
41
|
"@types/yargs": "^17.0.28",
|
|
42
|
-
"
|
|
43
|
-
"typescript": "^5.2.2",
|
|
42
|
+
"typescript": "^5.8.3",
|
|
44
43
|
"vite": "^4.4.11",
|
|
45
44
|
"vite-plugin-dts": "^3.6.0"
|
|
46
45
|
},
|
|
47
|
-
"engines": {
|
|
48
|
-
"node": ">=18.0.0"
|
|
49
|
-
},
|
|
50
46
|
"dependencies": {
|
|
51
|
-
"@done-coding/cli-template": "0.8.
|
|
52
|
-
"@done-coding/cli-utils": "0.8.
|
|
47
|
+
"@done-coding/cli-template": "0.8.10",
|
|
48
|
+
"@done-coding/cli-utils": "0.8.4",
|
|
53
49
|
"lodash.camelcase": "^4.3.0",
|
|
54
50
|
"lodash.kebabcase": "^4.1.1",
|
|
55
51
|
"lodash.lowerfirst": "^4.3.1",
|
|
56
52
|
"lodash.template": "^4.5.0",
|
|
57
53
|
"lodash.upperfirst": "^4.3.1"
|
|
58
54
|
},
|
|
59
|
-
"
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=18.0.0"
|
|
57
|
+
},
|
|
58
|
+
"gitHead": "d90f437c0a716f3e62bd92a221341838710869ad",
|
|
60
59
|
"scripts": {}
|
|
61
60
|
}
|