done-coding-component 0.4.6 → 0.4.9

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 CHANGED
@@ -1,7 +1,188 @@
1
1
  # @done-coding/cli-component
2
2
 
3
- 组件命令行工具
3
+ 组件生成命令行工具 - 快速创建和管理项目组件
4
4
 
5
- ## 使用
5
+ [![npm version](https://badge.fury.io/js/@done-coding%2Fcli-component.svg)](https://www.npmjs.com/package/@done-coding/cli-component)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
7
 
8
+ ## 安装
9
+
10
+ ### 独立安装
11
+ ```bash
7
12
  npm install @done-coding/cli-component
13
+ # 或
14
+ pnpm add @done-coding/cli-component
15
+ ```
16
+
17
+ ### 作为 done-coding CLI 的一部分
18
+ ```bash
19
+ npm install -g @done-coding/cli
20
+ # 然后使用
21
+ DC component [command]
22
+ ```
23
+
24
+ ## 快速开始
25
+
26
+ ```bash
27
+ # 独立使用
28
+ dc-component [command]
29
+
30
+ # 作为主 CLI 的子命令
31
+ DC component [command]
32
+
33
+ # 查看帮助
34
+ dc-component --help
35
+ ```
36
+
37
+ ## 功能特性
38
+
39
+ - ✅ **组件创建**: 使用 `add` 命令创建新组件
40
+ - 🗂️ **组件管理**: 使用 `list` 命令查看已创建的组件
41
+ - 🗑️ **组件删除**: 使用 `remove` 命令删除不需要的组件
42
+ - 🔧 **智能命名**: 自动处理组件名称的格式转换
43
+
44
+ ## API 文档
45
+
46
+ ### 基础命令
47
+
48
+ #### `dc-component add <name>`
49
+ 新增一个组件
50
+
51
+ ```bash
52
+ # 创建一个名为 Button 的组件
53
+ dc-component add Button
54
+
55
+ # 创建一个名为 UserCard 的组件
56
+ dc-component add UserCard
57
+ ```
58
+
59
+ **参数说明**:
60
+ - `name`: 组件名称(必需)
61
+
62
+ #### `dc-component remove [name]`
63
+ 删除一个组件
64
+
65
+ ```bash
66
+ # 删除指定组件
67
+ dc-component remove Button
68
+
69
+ # 不指定名称时可能提供交互式选择
70
+ dc-component remove
71
+ ```
72
+
73
+ **参数说明**:
74
+ - `name`: 组件名称(可选)
75
+
76
+ #### `dc-component list`
77
+ 展示组件列表
78
+
79
+ ```bash
80
+ # 显示所有已创建的组件
81
+ dc-component list
82
+ ```
83
+
84
+ ## 使用示例
85
+
86
+ ### 基础使用场景
87
+
88
+ ```bash
89
+ # 1. 查看当前组件列表
90
+ dc-component list
91
+
92
+ # 2. 创建新组件
93
+ dc-component add MyButton
94
+
95
+ # 3. 再次查看组件列表确认创建
96
+ dc-component list
97
+
98
+ # 4. 删除不需要的组件
99
+ dc-component remove MyButton
100
+ ```
101
+
102
+ ### 作为主 CLI 的一部分
103
+
104
+ ```bash
105
+ # 使用主 CLI 命令
106
+ DC component add Button
107
+ DC component list
108
+ DC component remove Button
109
+
110
+ # 使用替代命令
111
+ dc-cli component add Button
112
+ done-coding component list
113
+ ```
114
+
115
+ ## 故障排除
116
+
117
+ ### 常见问题
118
+
119
+ **Q: 组件创建失败**
120
+ ```bash
121
+ # 检查当前目录
122
+ pwd
123
+
124
+ # 查看详细错误信息
125
+ dc-component add MyButton
126
+ ```
127
+
128
+ **Q: 组件列表为空**
129
+ ```bash
130
+ # 确认是否在正确的项目目录
131
+ ls -la
132
+
133
+ # 检查是否已创建过组件
134
+ dc-component list
135
+ ```
136
+
137
+ **Q: 删除组件失败**
138
+ ```bash
139
+ # 确认组件名称正确
140
+ dc-component list
141
+
142
+ # 检查文件权限
143
+ ls -la src/components/
144
+ ```
145
+
146
+ ## 贡献指南
147
+
148
+ 我们欢迎贡献!请遵循以下步骤:
149
+
150
+ 1. Fork 本仓库
151
+ 2. 创建功能分支:`git checkout -b feature/amazing-feature`
152
+ 3. 提交更改:`git commit -m "feat: add amazing feature"`
153
+ 4. 推送分支:`git push origin feature/amazing-feature`
154
+ 5. 创建 Pull Request
155
+
156
+ ### 开发环境设置
157
+
158
+ ```bash
159
+ # 克隆仓库
160
+ git clone https://gitee.com/done-coding/done-coding-cli.git
161
+ cd done-coding-cli/packages/component
162
+
163
+ # 安装依赖
164
+ pnpm install
165
+
166
+ # 开发模式
167
+ pnpm dev
168
+
169
+ # 构建
170
+ pnpm build
171
+
172
+ # 本地开发测试
173
+ node es/cli.mjs --help
174
+
175
+ # 注意:本地使用 node + 入口文件,发布后使用 bin 命令名
176
+ # 功能完全一致,只是调用方式不同
177
+ ```
178
+
179
+ ## 许可证
180
+
181
+ MIT © [JustSoSu](https://gitee.com/done-coding)
182
+
183
+ ## 相关链接
184
+
185
+ - [主 CLI 工具](https://www.npmjs.com/package/@done-coding/cli)
186
+ - [模板处理工具](https://www.npmjs.com/package/@done-coding/cli-template) - 本包依赖的模板引擎
187
+ - [Gitee 仓库](https://gitee.com/done-coding/done-coding-cli)
188
+ - [更新日志](./CHANGELOG.md)
package/es/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as m } from "./index-b5e73d43.js";
2
+ import { c as m } from "./index-578b8ec1.js";
3
3
  import "node:path";
4
4
  import "node:fs";
5
5
  import "@done-coding/cli-utils";
@@ -1,23 +1,23 @@
1
1
  #!/usr/bin/env node
2
2
  import p from "node:path";
3
- import m from "node:fs";
4
- import { log as l, json5 as L, chalk as g, xPrompts as w, createSubcommand as O, getRootScriptName as V, createMainCommand as J } from "@done-coding/cli-utils";
3
+ import u from "node:fs";
4
+ import { log as m, json5 as F, getLogText as $, xPrompts as w, createSubcommand as O, getRootScriptName as V, createMainCommand as J } from "@done-coding/cli-utils";
5
5
  import x from "lodash.upperfirst";
6
- import v from "lodash.camelcase";
7
- import S from "lodash.kebabcase";
6
+ import S from "lodash.camelcase";
7
+ import v from "lodash.kebabcase";
8
8
  import T from "lodash.lowerfirst";
9
9
  import f from "lodash.template";
10
10
  import { OutputModeEnum as E, compileHandler as C } from "@done-coding/cli-template";
11
- var u = /* @__PURE__ */ ((e) => (e.ADD = "add", e.REMOVE = "remove", e.LIST = "list", e))(u || {});
11
+ var l = /* @__PURE__ */ ((e) => (e.ADD = "add", e.REMOVE = "remove", e.LIST = "list", e))(l || {});
12
12
  const _ = (e, t) => {
13
13
  if (!/^[a-zA-Z]+[a-zA-Z0-9-]*$/.test(e))
14
- return l.error("组件名只能包含字母、数字、中划线"), process.exit(1);
14
+ return m.error("组件名只能包含字母、数字、中划线"), process.exit(1);
15
15
  const { nameExcludes: n } = t;
16
- return n.includes(e) ? (l.error(`组件名: ${e}是保留名称。
16
+ return n.includes(e) ? (m.error(`组件名: ${e}是保留名称。
17
17
  保留名称: ${n.join(",")}`), process.exit(1)) : !0;
18
- }, D = {
18
+ }, g = {
19
19
  name: "@done-coding/cli-component",
20
- version: "0.4.6",
20
+ version: "0.4.9",
21
21
  description: "组件命令行工具",
22
22
  bin: {
23
23
  "dc-component": "es/cli.mjs"
@@ -26,82 +26,82 @@ const _ = (e, t) => {
26
26
  namespaceDir: ".done-coding",
27
27
  moduleName: "component"
28
28
  }
29
- }, { namespaceDir: K, moduleName: z } = D.cliConfig, N = () => p.resolve(K, z), I = () => ({
29
+ }, { namespaceDir: K, moduleName: z } = g.cliConfig, N = () => p.resolve(K, z), I = () => ({
30
30
  execDir: process.cwd(),
31
31
  templateDir: N()
32
- }), b = (e) => {
33
- const { series: t, name: n } = e, o = x(v(n)), c = T(o), a = S(o), s = t ? x(v(t)) : "", i = s ? `${s}${o}` : "", d = S(i);
32
+ }), D = (e) => {
33
+ const { series: t, name: n } = e, o = x(S(n)), i = T(o), a = v(o), s = t ? x(S(t)) : "", c = s ? `${s}${o}` : "", d = v(c);
34
34
  return {
35
35
  series: s,
36
36
  name: o,
37
- nameLowerFirst: c,
37
+ nameLowerFirst: i,
38
38
  nameKebab: a,
39
- fullName: i,
39
+ fullName: c,
40
40
  fullNameKebab: d,
41
41
  cls: d
42
42
  };
43
43
  }, Z = (e) => ({
44
44
  $: "$",
45
45
  ...I(),
46
- ...b(e)
47
- }), $ = () => {
46
+ ...D(e)
47
+ }), h = () => {
48
48
  const e = p.resolve(N(), "index.json");
49
- if (!m.existsSync(e))
50
- return l.error(`模块入口文件不存在: ${e}`), process.exit(1);
51
- const n = JSON.parse(m.readFileSync(e, "utf-8")).config;
49
+ if (!u.existsSync(e))
50
+ return m.error(`模块入口文件不存在: ${e}`), process.exit(1);
51
+ const n = JSON.parse(u.readFileSync(e, "utf-8")).config;
52
52
  if (!n)
53
- return l.error(`配置文件相对路径不存在: ${n}`), process.exit(1);
53
+ return m.error(`配置文件相对路径不存在: ${n}`), process.exit(1);
54
54
  const o = p.resolve(
55
55
  p.dirname(e),
56
56
  n
57
57
  );
58
- if (!m.existsSync(o))
59
- return l.error(`配置文件不存在: ${o}`), process.exit(1);
60
- const c = L.parse(m.readFileSync(o, "utf-8")), a = I();
61
- return c.componentDir = f(c.componentDir)(a), m.existsSync(c.componentDir) || m.mkdirSync(c.componentDir, {
58
+ if (!u.existsSync(o))
59
+ return m.error(`配置文件不存在: ${o}`), process.exit(1);
60
+ const i = F.parse(u.readFileSync(o, "utf-8")), a = I();
61
+ return i.componentDir = f(i.componentDir)(a), u.existsSync(i.componentDir) || u.mkdirSync(i.componentDir, {
62
62
  recursive: !0
63
- }), c;
64
- }, k = async ({
63
+ }), i;
64
+ }, R = async ({
65
65
  name: e,
66
66
  config: t,
67
67
  command: n
68
68
  }) => {
69
- if (![u.ADD, u.REMOVE].includes(n))
70
- return l.error(`不支持组件${n}操作`), process.exit(1);
69
+ if (![l.ADD, l.REMOVE].includes(n))
70
+ return m.error(`不支持组件${n}操作`), process.exit(1);
71
71
  const o = Z({
72
72
  ...t,
73
73
  name: e
74
- }), c = process.cwd(), a = JSON.stringify(o);
75
- for (const { entry: s, index: i } of t.list) {
74
+ }), i = process.cwd(), a = JSON.stringify(o);
75
+ for (const { entry: s, index: c } of t.list) {
76
76
  const d = {
77
77
  envData: a,
78
- rollback: n === u.REMOVE,
78
+ rollback: n === l.REMOVE,
79
79
  /** 回滚时可以删除空文件 */
80
80
  rollbackDelNullFile: !0,
81
81
  rollbackDelAskAsYes: !0,
82
82
  dealMarkdown: !0,
83
83
  batch: !1,
84
- rootDir: c
84
+ rootDir: i
85
85
  };
86
86
  if (s) {
87
87
  const r = s;
88
88
  r != null && r.input && (r.input = f(r.input)(o)), r != null && r.output && (r.output = f(r.output)(o));
89
- const h = {
89
+ const b = {
90
90
  ...s,
91
91
  mode: E.APPEND,
92
92
  ...d
93
93
  };
94
- await C(h);
94
+ await C(b);
95
95
  }
96
- if (i) {
97
- const r = i;
96
+ if (c) {
97
+ const r = c;
98
98
  r != null && r.input && (r.input = f(r.input)(o)), r != null && r.output && (r.output = f(r.output)(o));
99
- const h = {
100
- ...i,
99
+ const b = {
100
+ ...c,
101
101
  mode: E.OVERWRITE,
102
102
  ...d
103
103
  };
104
- await C(h);
104
+ await C(b);
105
105
  }
106
106
  }
107
107
  }, H = () => ({
@@ -118,41 +118,44 @@ const _ = (e, t) => {
118
118
  }
119
119
  }), y = (e) => {
120
120
  const { componentDir: t, nameExcludes: n } = e;
121
- return m.statSync(t).isDirectory() ? m.readdirSync(t).map((s) => {
122
- const i = p.join(t, s);
123
- return m.statSync(i).isDirectory() ? (console.log("filePath:", i, p.basename(i)), p.basename(i)) : "";
124
- }).filter((s) => !(!s || n.includes(s))) : (l.error("组件源码路径不是目录"), process.exit(1));
125
- }, R = async ({
121
+ return u.statSync(t).isDirectory() ? u.readdirSync(t).map((s) => {
122
+ const c = p.join(t, s);
123
+ return u.statSync(c).isDirectory() ? (m.info("filePath:", c, p.basename(c)), p.basename(c)) : "";
124
+ }).filter((s) => !(!s || n.includes(s))) : (m.error("组件源码路径不是目录"), process.exit(1));
125
+ }, k = async ({
126
126
  outputJson: e,
127
127
  outputPath: t
128
128
  }) => {
129
- l.stage("展示列表");
130
- const n = $(), o = y(n), c = t || n.nameListJsonOutputPath, a = o.map((s) => {
131
- const { name: i, fullName: d } = b({
129
+ m.stage("展示列表");
130
+ const n = h(), o = y(n), i = t || n.nameListJsonOutputPath, a = o.map((s) => {
131
+ const { name: c, fullName: d } = D({
132
132
  ...n,
133
133
  name: s
134
134
  });
135
135
  return {
136
- name: i,
136
+ name: c,
137
137
  nameKebab: s,
138
138
  fullName: d
139
139
  };
140
140
  });
141
141
  if (console.table(
142
- a.map(({ name: s, fullName: i, nameKebab: d }) => ({
143
- [g.green("名称")]: s,
144
- [g.green("带系列名称")]: i,
145
- [g.green("绝对路径")]: p.resolve(n.componentDir, d)
142
+ a.map(({ name: s, fullName: c, nameKebab: d }) => ({
143
+ [$.success("名称")]: s,
144
+ [$.success("带系列名称")]: c,
145
+ [$.success("绝对路径")]: p.resolve(
146
+ n.componentDir,
147
+ d
148
+ )
146
149
  }))
147
- ), e && c) {
148
- const s = p.resolve(c), i = p.dirname(s);
149
- m.existsSync(i) || m.mkdirSync(i, { recursive: !0 }), console.log(g.blue(`输出组件名列表到${s}`)), m.writeFileSync(s, JSON.stringify(a, null, 2));
150
+ ), e && i) {
151
+ const s = p.resolve(i), c = p.dirname(s);
152
+ u.existsSync(c) || u.mkdirSync(c, { recursive: !0 }), m.stage(`输出组件名列表到${s}`), u.writeFileSync(s, JSON.stringify(a, null, 2));
150
153
  }
151
154
  }, U = {
152
- command: u.LIST,
155
+ command: l.LIST,
153
156
  describe: "展示组件列表",
154
157
  options: H(),
155
- handler: R
158
+ handler: k
156
159
  }, W = () => ({
157
160
  name: {
158
161
  describe: "组件名称",
@@ -161,29 +164,29 @@ const _ = (e, t) => {
161
164
  }), A = async ({
162
165
  name: e
163
166
  }) => {
164
- l.stage("添加组件");
167
+ m.stage("添加组件");
165
168
  let t;
166
169
  e ? t = e : t = (await w({
167
170
  type: "text",
168
171
  name: "name",
169
172
  message: "请输入组件名"
170
173
  })).name;
171
- const n = $();
174
+ const n = h();
172
175
  _(t, n);
173
- const { series: o } = n, c = await y(n);
174
- for (let a of c)
175
- if (b({
176
+ const { series: o } = n, i = await y(n);
177
+ for (let a of i)
178
+ if (D({
176
179
  series: o,
177
180
  name: t
178
181
  }).nameKebab === a)
179
- return l.error(`组件${a}已存在, 不能再次创建${t}组件`), process.exit(1);
180
- return k({
182
+ return m.error(`组件${a}已存在, 不能再次创建${t}组件`), process.exit(1);
183
+ return R({
181
184
  name: t,
182
185
  config: n,
183
- command: u.ADD
186
+ command: l.ADD
184
187
  });
185
188
  }, Y = {
186
- command: `${u.ADD} <name>`,
189
+ command: `${l.ADD} <name>`,
187
190
  describe: "新增一个组件",
188
191
  positionals: W(),
189
192
  handler: A
@@ -195,10 +198,10 @@ const _ = (e, t) => {
195
198
  }), M = async ({
196
199
  name: e
197
200
  }) => {
198
- l.stage("移除组件");
199
- const t = $(), n = await y(t);
201
+ m.stage("移除组件");
202
+ const t = h(), n = await y(t);
200
203
  if (n.length === 0)
201
- return l.error("组件列表为空"), process.exit(1);
204
+ return m.error("组件列表为空"), process.exit(1);
202
205
  let o;
203
206
  e ? o = e : o = (await w({
204
207
  type: "select",
@@ -206,37 +209,37 @@ const _ = (e, t) => {
206
209
  message: "请选择要移除的组件",
207
210
  choices: n.map((a) => ({ title: a, value: a }))
208
211
  })).name;
209
- const { series: c } = t;
212
+ const { series: i } = t;
210
213
  for (let a of n)
211
- if (b({
212
- series: c,
214
+ if (D({
215
+ series: i,
213
216
  name: o
214
217
  }).nameKebab === a) {
215
- await k({
218
+ await R({
216
219
  name: o,
217
220
  config: t,
218
- command: u.REMOVE
219
- }), m.rmdirSync(p.resolve(t.componentDir, a));
221
+ command: l.REMOVE
222
+ }), u.rmdirSync(p.resolve(t.componentDir, a));
220
223
  return;
221
224
  }
222
- return l.error(`组件${o}不存在`), process.exit(1);
225
+ return m.error(`组件${o}不存在`), process.exit(1);
223
226
  }, B = {
224
- command: `${u.REMOVE} [name]`,
227
+ command: `${l.REMOVE} [name]`,
225
228
  describe: "删除一个组件",
226
229
  positionals: q(),
227
230
  handler: M
228
- }, ce = async (e, t) => {
231
+ }, ie = async (e, t) => {
229
232
  switch (e) {
230
- case u.ADD:
233
+ case l.ADD:
231
234
  return A(t);
232
- case u.REMOVE:
235
+ case l.REMOVE:
233
236
  return M(t);
234
- case u.LIST:
235
- return R();
237
+ case l.LIST:
238
+ return k(t);
236
239
  default:
237
240
  throw new Error(`不支持的命令 ${e}`);
238
241
  }
239
- }, { version: G, description: Q } = D, j = {
242
+ }, { version: G, description: Q } = g, L = {
240
243
  describe: Q,
241
244
  version: G,
242
245
  subcommands: [
@@ -245,22 +248,22 @@ const _ = (e, t) => {
245
248
  U
246
249
  ].map(O),
247
250
  demandCommandCount: 1,
248
- rootScriptName: V({ packageJson: D })
251
+ rootScriptName: V({ packageJson: g })
249
252
  }, {
250
253
  cliConfig: { moduleName: P }
251
- } = D, F = (e = !1) => {
254
+ } = g, j = (e = !1) => {
252
255
  const t = e ? P : void 0, n = `$0${e ? ` ${P}` : ""} <command> [options]`;
253
256
  return { command: t, usage: n };
254
257
  }, me = async () => J({
255
- ...j,
256
- ...F()
257
- }), le = () => O({
258
- ...j,
259
- ...F(!0)
258
+ ...L,
259
+ ...j()
260
+ }), ue = () => O({
261
+ ...L,
262
+ ...j(!0)
260
263
  });
261
264
  export {
262
- u as S,
263
- le as a,
265
+ l as S,
266
+ ue as a,
264
267
  me as c,
265
- ce as h
268
+ ie as h
266
269
  };
package/es/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { S as u, a as b, h as c } from "./index-b5e73d43.js";
2
+ import { S as u, a as b, h as c } from "./index-578b8ec1.js";
3
3
  import "node:path";
4
4
  import "node:fs";
5
5
  import "@done-coding/cli-utils";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "done-coding-component",
3
- "version": "0.4.6",
3
+ "version": "0.4.9",
4
4
  "description": "组件命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -31,7 +31,7 @@
31
31
  "license": "MIT",
32
32
  "sideEffects": false,
33
33
  "devDependencies": {
34
- "@done-coding/cli-inject": "0.5.17",
34
+ "@done-coding/cli-inject": "0.5.20",
35
35
  "@types/lodash.camelcase": "^4.3.8",
36
36
  "@types/lodash.kebabcase": "^4.1.8",
37
37
  "@types/lodash.lowerfirst": "^4.3.8",
@@ -48,14 +48,14 @@
48
48
  "node": ">=18.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "@done-coding/cli-template": "0.8.4",
52
- "@done-coding/cli-utils": "0.7.7",
51
+ "@done-coding/cli-template": "0.8.7",
52
+ "@done-coding/cli-utils": "0.8.1",
53
53
  "lodash.camelcase": "^4.3.0",
54
54
  "lodash.kebabcase": "^4.1.1",
55
55
  "lodash.lowerfirst": "^4.3.1",
56
56
  "lodash.template": "^4.5.0",
57
57
  "lodash.upperfirst": "^4.3.1"
58
58
  },
59
- "gitHead": "5089d971d16fc1a44e6b79209578b57158405b38",
59
+ "gitHead": "0930f800167c04a86b56eae9741872dd51bec0c6",
60
60
  "scripts": {}
61
61
  }