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