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