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