@done-coding/cli-component 0.3.11 → 0.3.12-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-7537c1e6.js → index-d1ae4540.js} +75 -71
- package/es/index.mjs +1 -1
- package/package.json +5 -5
package/es/cli.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import p from "node:path";
|
|
3
|
+
import u from "node:fs";
|
|
4
|
+
import h from "lodash.upperfirst";
|
|
5
5
|
import y from "lodash.camelcase";
|
|
6
6
|
import $ from "lodash.kebabcase";
|
|
7
7
|
import A from "lodash.lowerfirst";
|
|
8
|
-
import
|
|
9
|
-
import { log as m, json5 as L, chalk as
|
|
10
|
-
import { OutputModeEnum as
|
|
8
|
+
import d from "lodash.template";
|
|
9
|
+
import { log as m, json5 as L, chalk as D, xPrompts as w, _curry as b, createSubcommand as M, getRootScriptName as j, createMainCommand as F } from "@done-coding/cli-utils";
|
|
10
|
+
import { OutputModeEnum as S, compileHandler as N } from "@done-coding/cli-template";
|
|
11
11
|
var a = /* @__PURE__ */ ((e) => (e.ADD = "add", e.REMOVE = "remove", e.LIST = "list", e))(a || {});
|
|
12
12
|
const T = (e, t) => {
|
|
13
13
|
if (!/^[a-zA-Z]+[a-zA-Z0-9-]*$/.test(e))
|
|
@@ -15,19 +15,22 @@ const T = (e, t) => {
|
|
|
15
15
|
const { nameExcludes: n } = t;
|
|
16
16
|
return n.includes(e) ? (m.error(`组件名: ${e}是保留名称。
|
|
17
17
|
保留名称: ${n.join(",")}`), process.exit(1)) : !0;
|
|
18
|
-
},
|
|
18
|
+
}, C = {
|
|
19
19
|
name: "@done-coding/cli-component",
|
|
20
|
-
version: "0.3.
|
|
20
|
+
version: "0.3.12-alpha.0",
|
|
21
21
|
description: "组件命令行工具",
|
|
22
|
+
bin: {
|
|
23
|
+
"dc-component": "es/cli.mjs"
|
|
24
|
+
},
|
|
22
25
|
cliConfig: {
|
|
23
26
|
namespaceDir: ".done-coding",
|
|
24
27
|
moduleName: "component"
|
|
25
28
|
}
|
|
26
|
-
}, { namespaceDir: _, moduleName:
|
|
29
|
+
}, { namespaceDir: _, moduleName: K } = C.cliConfig, R = () => p.resolve(_, K), I = () => ({
|
|
27
30
|
execDir: process.cwd(),
|
|
28
|
-
templateDir:
|
|
29
|
-
}),
|
|
30
|
-
const { series: t, name: n } = e, o =
|
|
31
|
+
templateDir: R()
|
|
32
|
+
}), g = (e) => {
|
|
33
|
+
const { series: t, name: n } = e, o = h(y(n)), i = A(o), s = $(o), c = t ? h(y(t)) : "", l = c ? `${c}${o}` : "", r = $(l);
|
|
31
34
|
return {
|
|
32
35
|
series: c,
|
|
33
36
|
name: o,
|
|
@@ -37,44 +40,44 @@ const T = (e, t) => {
|
|
|
37
40
|
fullNameKebab: r,
|
|
38
41
|
cls: r
|
|
39
42
|
};
|
|
40
|
-
},
|
|
43
|
+
}, J = (e) => ({
|
|
41
44
|
$: "$",
|
|
42
|
-
...
|
|
43
|
-
...
|
|
44
|
-
}),
|
|
45
|
-
const e =
|
|
46
|
-
if (!
|
|
45
|
+
...I(),
|
|
46
|
+
...g(e)
|
|
47
|
+
}), E = () => {
|
|
48
|
+
const e = p.resolve(R(), "index.json");
|
|
49
|
+
if (!u.existsSync(e))
|
|
47
50
|
return m.error(`模块入口文件不存在: ${e}`), process.exit(1);
|
|
48
|
-
const n = JSON.parse(
|
|
51
|
+
const n = JSON.parse(u.readFileSync(e, "utf-8")).config;
|
|
49
52
|
if (!n)
|
|
50
53
|
return m.error(`配置文件相对路径不存在: ${n}`), process.exit(1);
|
|
51
|
-
const o =
|
|
52
|
-
|
|
54
|
+
const o = p.resolve(
|
|
55
|
+
p.dirname(e),
|
|
53
56
|
n
|
|
54
57
|
);
|
|
55
|
-
if (!
|
|
58
|
+
if (!u.existsSync(o))
|
|
56
59
|
return m.error(`配置文件不存在: ${o}`), process.exit(1);
|
|
57
|
-
const i = L.parse(
|
|
58
|
-
return i.componentDir =
|
|
59
|
-
},
|
|
60
|
+
const i = L.parse(u.readFileSync(o, "utf-8")), s = I();
|
|
61
|
+
return i.componentDir = d(i.componentDir)(s), i;
|
|
62
|
+
}, v = (e) => {
|
|
60
63
|
const { componentDir: t, nameExcludes: n } = e;
|
|
61
|
-
return
|
|
62
|
-
const l =
|
|
63
|
-
return
|
|
64
|
+
return u.statSync(t).isDirectory() ? u.readdirSync(t).map((c) => {
|
|
65
|
+
const l = p.join(t, c);
|
|
66
|
+
return u.statSync(l).isDirectory() ? (console.log("filePath:", l, p.basename(l)), p.basename(l)) : "";
|
|
64
67
|
}).filter((c) => !(!c || n.includes(c))) : (m.error("组件源码路径不是目录"), process.exit(1));
|
|
65
68
|
}, z = async () => {
|
|
66
69
|
m.stage("展示列表");
|
|
67
|
-
const e =
|
|
70
|
+
const e = E(), t = v(e);
|
|
68
71
|
console.table(
|
|
69
72
|
t.map((n) => {
|
|
70
|
-
const { name: o, fullName: i } =
|
|
73
|
+
const { name: o, fullName: i } = g({
|
|
71
74
|
...e,
|
|
72
75
|
name: n
|
|
73
76
|
});
|
|
74
77
|
return {
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[
|
|
78
|
+
[D.green("名称")]: o,
|
|
79
|
+
[D.green("带系列名称")]: i,
|
|
80
|
+
[D.green("绝对路径")]: p.resolve(e.componentDir, n)
|
|
78
81
|
};
|
|
79
82
|
})
|
|
80
83
|
);
|
|
@@ -85,18 +88,18 @@ const T = (e, t) => {
|
|
|
85
88
|
}) => {
|
|
86
89
|
if (![a.ADD, a.REMOVE].includes(n))
|
|
87
90
|
return m.error(`不支持组件${n}操作`), process.exit(1);
|
|
88
|
-
const o =
|
|
91
|
+
const o = J({
|
|
89
92
|
...t,
|
|
90
93
|
name: e
|
|
91
94
|
}), i = process.cwd(), s = JSON.stringify(o);
|
|
92
95
|
for (const { entry: c, index: l } of t.list) {
|
|
93
96
|
if (c) {
|
|
94
97
|
const r = c;
|
|
95
|
-
r != null && r.input && (r.input =
|
|
96
|
-
const
|
|
98
|
+
r != null && r.input && (r.input = d(r.input)(o)), r != null && r.output && (r.output = d(r.output)(o));
|
|
99
|
+
const f = {
|
|
97
100
|
...c,
|
|
98
101
|
envData: s,
|
|
99
|
-
mode:
|
|
102
|
+
mode: S.APPEND,
|
|
100
103
|
rollback: n === a.REMOVE,
|
|
101
104
|
/** 回滚时可以删除空文件 */
|
|
102
105
|
rollbackDelNullFile: !0,
|
|
@@ -104,24 +107,24 @@ const T = (e, t) => {
|
|
|
104
107
|
batch: !1,
|
|
105
108
|
rootDir: i
|
|
106
109
|
};
|
|
107
|
-
await
|
|
110
|
+
await N(f);
|
|
108
111
|
}
|
|
109
112
|
if (l) {
|
|
110
113
|
const r = l;
|
|
111
|
-
r != null && r.input && (r.input =
|
|
112
|
-
const
|
|
114
|
+
r != null && r.input && (r.input = d(r.input)(o)), r != null && r.output && (r.output = d(r.output)(o));
|
|
115
|
+
const f = {
|
|
113
116
|
...l,
|
|
114
117
|
envData: s,
|
|
115
|
-
mode:
|
|
118
|
+
mode: S.OVERWRITE,
|
|
116
119
|
rollback: n === a.REMOVE,
|
|
117
120
|
dealMarkdown: !0,
|
|
118
121
|
batch: !1,
|
|
119
122
|
rootDir: i
|
|
120
123
|
};
|
|
121
|
-
await
|
|
124
|
+
await N(f);
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
|
-
},
|
|
127
|
+
}, Z = async ({ name: e }) => {
|
|
125
128
|
m.stage("添加组件");
|
|
126
129
|
let t;
|
|
127
130
|
e ? t = e : t = (await w({
|
|
@@ -129,11 +132,11 @@ const T = (e, t) => {
|
|
|
129
132
|
name: "name",
|
|
130
133
|
message: "请输入组件名"
|
|
131
134
|
})).name;
|
|
132
|
-
const n =
|
|
135
|
+
const n = E();
|
|
133
136
|
T(t, n);
|
|
134
|
-
const { series: o } = n, i = await
|
|
137
|
+
const { series: o } = n, i = await v(n);
|
|
135
138
|
for (let s of i)
|
|
136
|
-
if (
|
|
139
|
+
if (g({
|
|
137
140
|
series: o,
|
|
138
141
|
name: t
|
|
139
142
|
}).nameKebab === s)
|
|
@@ -143,9 +146,9 @@ const T = (e, t) => {
|
|
|
143
146
|
config: n,
|
|
144
147
|
command: a.ADD
|
|
145
148
|
});
|
|
146
|
-
},
|
|
149
|
+
}, H = async ({ name: e }) => {
|
|
147
150
|
m.stage("移除组件");
|
|
148
|
-
const t =
|
|
151
|
+
const t = E(), n = await v(t);
|
|
149
152
|
if (n.length === 0)
|
|
150
153
|
return m.error("组件列表为空"), process.exit(1);
|
|
151
154
|
let o;
|
|
@@ -157,7 +160,7 @@ const T = (e, t) => {
|
|
|
157
160
|
})).name;
|
|
158
161
|
const { series: i } = t;
|
|
159
162
|
for (let s of n)
|
|
160
|
-
if (
|
|
163
|
+
if (g({
|
|
161
164
|
series: i,
|
|
162
165
|
name: o
|
|
163
166
|
}).nameKebab === s) {
|
|
@@ -165,15 +168,15 @@ const T = (e, t) => {
|
|
|
165
168
|
name: o,
|
|
166
169
|
config: t,
|
|
167
170
|
command: a.REMOVE
|
|
168
|
-
}),
|
|
171
|
+
}), u.rmdirSync(p.resolve(t.componentDir, s));
|
|
169
172
|
return;
|
|
170
173
|
}
|
|
171
174
|
return m.error(`组件${o}不存在`), process.exit(1);
|
|
172
|
-
},
|
|
173
|
-
version:
|
|
174
|
-
description:
|
|
175
|
-
cliConfig: { moduleName:
|
|
176
|
-
} =
|
|
175
|
+
}, x = async (e, t) => e === a.ADD ? Z(t) : e === a.REMOVE ? H(t) : e === a.LIST ? z() : (m.error(`无效的命令: ${e}`), process.exit(1)), {
|
|
176
|
+
version: U,
|
|
177
|
+
description: W,
|
|
178
|
+
cliConfig: { moduleName: O }
|
|
179
|
+
} = C, q = {
|
|
177
180
|
command: `${a.ADD} <name>`,
|
|
178
181
|
describe: "新增一个组件",
|
|
179
182
|
positionals: {
|
|
@@ -182,8 +185,8 @@ const T = (e, t) => {
|
|
|
182
185
|
type: "string"
|
|
183
186
|
}
|
|
184
187
|
},
|
|
185
|
-
handler: b(
|
|
186
|
-
},
|
|
188
|
+
handler: b(x)(a.ADD)
|
|
189
|
+
}, B = {
|
|
187
190
|
command: `${a.REMOVE} [name]`,
|
|
188
191
|
describe: "删除一个组件",
|
|
189
192
|
positionals: {
|
|
@@ -192,32 +195,33 @@ const T = (e, t) => {
|
|
|
192
195
|
type: "string"
|
|
193
196
|
}
|
|
194
197
|
},
|
|
195
|
-
handler: b(
|
|
196
|
-
},
|
|
198
|
+
handler: b(x)(a.REMOVE)
|
|
199
|
+
}, G = {
|
|
197
200
|
command: a.LIST,
|
|
198
201
|
describe: "展示组件列表",
|
|
199
|
-
handler: b(
|
|
202
|
+
handler: b(x)(a.LIST)
|
|
200
203
|
}, V = {
|
|
201
|
-
describe:
|
|
202
|
-
version:
|
|
204
|
+
describe: W,
|
|
205
|
+
version: U,
|
|
203
206
|
subcommands: [
|
|
204
|
-
W,
|
|
205
207
|
q,
|
|
206
|
-
B
|
|
208
|
+
B,
|
|
209
|
+
G
|
|
207
210
|
].map(M),
|
|
208
|
-
demandCommandCount: 1
|
|
211
|
+
demandCommandCount: 1,
|
|
212
|
+
rootScriptName: j({ packageJson: C })
|
|
209
213
|
}, k = (e = !1) => {
|
|
210
|
-
const t = e ?
|
|
214
|
+
const t = e ? O : void 0, n = `$0${e ? ` ${O}` : ""} <command> [options]`;
|
|
211
215
|
return { command: t, usage: n };
|
|
212
|
-
},
|
|
216
|
+
}, ae = async () => F({
|
|
213
217
|
...V,
|
|
214
218
|
...k()
|
|
215
|
-
}),
|
|
219
|
+
}), ie = () => M({
|
|
216
220
|
...V,
|
|
217
221
|
...k(!0)
|
|
218
222
|
});
|
|
219
223
|
export {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
224
|
+
ie as a,
|
|
225
|
+
ae as c,
|
|
226
|
+
x as h
|
|
223
227
|
};
|
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.3.
|
|
3
|
+
"version": "0.3.12-alpha.0",
|
|
4
4
|
"description": "组件命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"sideEffects": false,
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@done-coding/cli-inject": "^0.5.
|
|
43
|
+
"@done-coding/cli-inject": "^0.5.12-alpha.0",
|
|
44
44
|
"@types/lodash.camelcase": "^4.3.8",
|
|
45
45
|
"@types/lodash.kebabcase": "^4.1.8",
|
|
46
46
|
"@types/lodash.lowerfirst": "^4.3.8",
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
"node": ">=18.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@done-coding/cli-template": "^0.7.
|
|
61
|
-
"@done-coding/cli-utils": "^0.7.
|
|
60
|
+
"@done-coding/cli-template": "^0.7.12-alpha.0",
|
|
61
|
+
"@done-coding/cli-utils": "^0.7.3-alpha.0",
|
|
62
62
|
"lodash.camelcase": "^4.3.0",
|
|
63
63
|
"lodash.kebabcase": "^4.1.1",
|
|
64
64
|
"lodash.lowerfirst": "^4.3.1",
|
|
65
65
|
"lodash.template": "^4.5.0",
|
|
66
66
|
"lodash.upperfirst": "^4.3.1"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "9d9a2e60f255038a0f065e3a4e6d6d35488408ae"
|
|
69
69
|
}
|