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