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