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