done-coding-component 0.3.8-alpha.1
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/README.md +7 -0
- package/es/cli.mjs +12 -0
- package/es/index-f3df0c33.js +223 -0
- package/es/index.mjs +15 -0
- package/package.json +60 -0
- package/types/cli.d.ts +2 -0
- package/types/handler.d.ts +5 -0
- package/types/index.d.ts +2 -0
- package/types/injectInfo.json.d.ts +11 -0
- package/types/main.d.ts +9 -0
- package/types/utils/add.d.ts +3 -0
- package/types/utils/config.d.ts +3 -0
- package/types/utils/env-data.d.ts +41 -0
- package/types/utils/index.d.ts +6 -0
- package/types/utils/list.d.ts +6 -0
- package/types/utils/name.d.ts +7 -0
- package/types/utils/operate.d.ts +8 -0
- package/types/utils/remove.d.ts +3 -0
- package/types/utils/types.d.ts +44 -0
package/README.md
ADDED
package/es/cli.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { c as m } from "./index-f3df0c33.js";
|
|
3
|
+
import "node:path";
|
|
4
|
+
import "node:fs";
|
|
5
|
+
import "lodash.upperfirst";
|
|
6
|
+
import "lodash.camelcase";
|
|
7
|
+
import "lodash.kebabcase";
|
|
8
|
+
import "lodash.lowerfirst";
|
|
9
|
+
import "lodash.template";
|
|
10
|
+
import "@done-coding/cli-utils";
|
|
11
|
+
import "@done-coding/cli-template";
|
|
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.8-alpha.1",
|
|
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
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as b, h as c } from "./index-f3df0c33.js";
|
|
3
|
+
import "node:path";
|
|
4
|
+
import "node:fs";
|
|
5
|
+
import "lodash.upperfirst";
|
|
6
|
+
import "lodash.camelcase";
|
|
7
|
+
import "lodash.kebabcase";
|
|
8
|
+
import "lodash.lowerfirst";
|
|
9
|
+
import "lodash.template";
|
|
10
|
+
import "@done-coding/cli-utils";
|
|
11
|
+
import "@done-coding/cli-template";
|
|
12
|
+
export {
|
|
13
|
+
b as crateAsSubcommand,
|
|
14
|
+
c as handler
|
|
15
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "done-coding-component",
|
|
3
|
+
"version": "0.3.8-alpha.1",
|
|
4
|
+
"description": "组件命令行工具",
|
|
5
|
+
"private": false,
|
|
6
|
+
"module": "es/index.mjs",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
9
|
+
"bin": "es/cli.mjs",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./es/index.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"es",
|
|
17
|
+
"lib",
|
|
18
|
+
"types"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://gitee.com/justsosu/done-coding-cli.git",
|
|
24
|
+
"directory": "packages/component"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"registry": "https://registry.npmjs.org/"
|
|
29
|
+
},
|
|
30
|
+
"author": "JustSoSu",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@done-coding/cli-inject": "^0.5.8-alpha.0",
|
|
35
|
+
"@types/lodash.camelcase": "^4.3.8",
|
|
36
|
+
"@types/lodash.kebabcase": "^4.1.8",
|
|
37
|
+
"@types/lodash.lowerfirst": "^4.3.8",
|
|
38
|
+
"@types/lodash.template": "^4.5.2",
|
|
39
|
+
"@types/lodash.upperfirst": "^4.3.8",
|
|
40
|
+
"@types/node": "^18.0.0",
|
|
41
|
+
"@types/yargs": "^17.0.28",
|
|
42
|
+
"rimraf": "^6.0.1",
|
|
43
|
+
"typescript": "^5.2.2",
|
|
44
|
+
"vite": "^4.4.11",
|
|
45
|
+
"vite-plugin-dts": "^3.6.0"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@done-coding/cli-template": "^0.7.8-alpha.1",
|
|
52
|
+
"@done-coding/cli-utils": "^0.6.0-alpha.0",
|
|
53
|
+
"lodash.camelcase": "^4.3.0",
|
|
54
|
+
"lodash.kebabcase": "^4.1.1",
|
|
55
|
+
"lodash.lowerfirst": "^4.3.1",
|
|
56
|
+
"lodash.template": "^4.5.0",
|
|
57
|
+
"lodash.upperfirst": "^4.3.1"
|
|
58
|
+
},
|
|
59
|
+
"gitHead": "5879161383e32e7bed351d71d3ef607d81dc021a"
|
|
60
|
+
}
|
package/types/cli.d.ts
ADDED
package/types/index.d.ts
ADDED
package/types/main.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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<{}, {}>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Config, Options } from "./types";
|
|
2
|
+
/** 获取模板目录绝对路径 */
|
|
3
|
+
export declare const getTemplateDirAbsolutePath: () => string;
|
|
4
|
+
/** 路径环境变量 */
|
|
5
|
+
export interface PathEnvData {
|
|
6
|
+
/** 执行命令的目录绝对路径 */
|
|
7
|
+
execDir: string;
|
|
8
|
+
/** 模板目录绝对路径 */
|
|
9
|
+
templateDir: string;
|
|
10
|
+
}
|
|
11
|
+
/** 获取路径环境变量 */
|
|
12
|
+
export declare const getPathEnvData: () => {
|
|
13
|
+
execDir: string;
|
|
14
|
+
templateDir: string;
|
|
15
|
+
};
|
|
16
|
+
/** 组件环境变量 */
|
|
17
|
+
export interface ComponentEnvData {
|
|
18
|
+
/** 矫正后的组件系列 */
|
|
19
|
+
series: string;
|
|
20
|
+
/** 矫正后的组件名 */
|
|
21
|
+
name: string;
|
|
22
|
+
/** 矫正后的组件名小写开头 */
|
|
23
|
+
nameLowerFirst: string;
|
|
24
|
+
/** 小写连接的组件名 */
|
|
25
|
+
nameKebab: string;
|
|
26
|
+
/** 矫正后的带系列组件名 */
|
|
27
|
+
fullName: string;
|
|
28
|
+
/** 矫正后的带系列小写连接的组件名 */
|
|
29
|
+
fullNameKebab: string;
|
|
30
|
+
/** 组件类名 */
|
|
31
|
+
cls: string;
|
|
32
|
+
}
|
|
33
|
+
/** 获取环境变量 */
|
|
34
|
+
export declare const getComponentEnvData: (data: Pick<Config, "series"> & Required<Options>) => ComponentEnvData;
|
|
35
|
+
/** 环境变量 */
|
|
36
|
+
export interface EnvData extends PathEnvData, ComponentEnvData {
|
|
37
|
+
/** 转义的$ */
|
|
38
|
+
$: "$";
|
|
39
|
+
}
|
|
40
|
+
/** 获取环境变量 */
|
|
41
|
+
export declare const getEnvData: (data: Pick<Config, "series"> & Required<Options>) => EnvData;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { CompileOptions } from "@done-coding/cli-template";
|
|
2
|
+
/** 子命令枚举 */
|
|
3
|
+
export declare enum SubcommandEnum {
|
|
4
|
+
/** 新增组件 */
|
|
5
|
+
ADD = "add",
|
|
6
|
+
/** 移除组件 */
|
|
7
|
+
REMOVE = "remove",
|
|
8
|
+
/** 展示列表 */
|
|
9
|
+
LIST = "list"
|
|
10
|
+
}
|
|
11
|
+
export interface Options {
|
|
12
|
+
/**
|
|
13
|
+
* 组件名
|
|
14
|
+
* ---
|
|
15
|
+
* 新增时必传
|
|
16
|
+
*/
|
|
17
|
+
name?: string;
|
|
18
|
+
}
|
|
19
|
+
/** 模版配置输入路径 */
|
|
20
|
+
export type TemplateConfigInputByPath = Pick<CompileOptions, "input" | "output">;
|
|
21
|
+
/** 模版配置输入数据 */
|
|
22
|
+
export type TemplateConfigInputByData = Pick<CompileOptions, "inputData" | "output">;
|
|
23
|
+
/** 模版配置 */
|
|
24
|
+
export type TemplateConfig = TemplateConfigInputByPath | TemplateConfigInputByData;
|
|
25
|
+
/** 模版配置完整 */
|
|
26
|
+
export type TemplateConfigFull = Pick<CompileOptions, "input" | "inputData" | "output">;
|
|
27
|
+
/** 列表item */
|
|
28
|
+
export interface ConfigListItem {
|
|
29
|
+
/** 入口文件 */
|
|
30
|
+
entry: TemplateConfig;
|
|
31
|
+
/** 索引文件 */
|
|
32
|
+
index?: TemplateConfig;
|
|
33
|
+
}
|
|
34
|
+
/** 组件配置 */
|
|
35
|
+
export interface Config {
|
|
36
|
+
/** 组件系列 */
|
|
37
|
+
series: string;
|
|
38
|
+
/** 组件名排除列表 */
|
|
39
|
+
nameExcludes: string[];
|
|
40
|
+
/** 组件目录 */
|
|
41
|
+
componentDir: string;
|
|
42
|
+
/** 配置列表 */
|
|
43
|
+
list: ConfigListItem[];
|
|
44
|
+
}
|