@done-coding/cli-component 0.4.10-alpha.1 → 0.4.11-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-26ea3160.js";
2
+ import { c as m } from "./index-1913b07b.js";
3
3
  import "node:path";
4
4
  import "node:fs";
5
5
  import "@done-coding/cli-utils";
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import p from "node:path";
3
- import u from "node:fs";
4
- import { log as m, json5 as F, getLogText as h, xPrompts as w, createSubcommand as O, getRootScriptName as V, createMainCommand as J } from "@done-coding/cli-utils";
3
+ import l from "node:fs";
4
+ import { outputConsole as m, json5 as L, chalk as b, 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
6
  import S from "lodash.camelcase";
7
7
  import v from "lodash.kebabcase";
8
8
  import T from "lodash.lowerfirst";
9
9
  import f from "lodash.template";
10
- import { OutputModeEnum as E, compileHandler as C } from "@done-coding/cli-template";
11
- var l = /* @__PURE__ */ ((e) => (e.ADD = "add", e.REMOVE = "remove", e.LIST = "list", e))(l || {});
10
+ import { OutputModeEnum as C, compileHandler as E } from "@done-coding/cli-template";
11
+ var u = /* @__PURE__ */ ((e) => (e.ADD = "add", e.REMOVE = "remove", e.LIST = "list", e))(u || {});
12
12
  const _ = (e, t) => {
13
13
  if (!/^[a-zA-Z]+[a-zA-Z0-9-]*$/.test(e))
14
14
  return m.error("组件名只能包含字母、数字、中划线"), process.exit(1);
@@ -17,7 +17,7 @@ const _ = (e, t) => {
17
17
  保留名称: ${n.join(",")}`), process.exit(1)) : !0;
18
18
  }, g = {
19
19
  name: "@done-coding/cli-component",
20
- version: "0.4.10-alpha.1",
20
+ version: "0.4.11-alpha.0",
21
21
  description: "组件命令行工具",
22
22
  bin: {
23
23
  "dc-component": "es/cli.mjs"
@@ -26,13 +26,13 @@ const _ = (e, t) => {
26
26
  namespaceDir: ".done-coding",
27
27
  moduleName: "component"
28
28
  }
29
- }, { namespaceDir: K, moduleName: z } = g.cliConfig, N = () => p.resolve(K, z), I = () => ({
29
+ }, { namespaceDir: K, moduleName: B } = g.cliConfig, N = () => p.resolve(K, B), I = () => ({
30
30
  execDir: process.cwd(),
31
31
  templateDir: N()
32
32
  }), D = (e) => {
33
- const { series: t, name: n } = e, o = x(S(n)), c = T(o), a = v(o), s = t ? x(S(t)) : "", i = s ? `${s}${o}` : "", d = v(i);
33
+ const { series: t, name: n } = e, o = x(S(n)), c = T(o), a = v(o), r = t ? x(S(t)) : "", i = r ? `${r}${o}` : "", d = v(i);
34
34
  return {
35
- series: s,
35
+ series: r,
36
36
  name: o,
37
37
  nameLowerFirst: c,
38
38
  nameKebab: a,
@@ -40,42 +40,42 @@ const _ = (e, t) => {
40
40
  fullNameKebab: d,
41
41
  cls: d
42
42
  };
43
- }, Z = (e) => ({
43
+ }, z = (e) => ({
44
44
  $: "$",
45
45
  ...I(),
46
46
  ...D(e)
47
47
  }), $ = () => {
48
48
  const e = p.resolve(N(), "index.json");
49
- if (!u.existsSync(e))
49
+ if (!l.existsSync(e))
50
50
  return m.error(`模块入口文件不存在: ${e}`), process.exit(1);
51
- const n = JSON.parse(u.readFileSync(e, "utf-8")).config;
51
+ const n = JSON.parse(l.readFileSync(e, "utf-8")).config;
52
52
  if (!n)
53
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 (!u.existsSync(o))
58
+ if (!l.existsSync(o))
59
59
  return m.error(`配置文件不存在: ${o}`), process.exit(1);
60
- const c = F.parse(u.readFileSync(o, "utf-8")), a = I();
61
- return c.componentDir = f(c.componentDir)(a), u.existsSync(c.componentDir) || u.mkdirSync(c.componentDir, {
60
+ const c = L.parse(l.readFileSync(o, "utf-8")), a = I();
61
+ return c.componentDir = f(c.componentDir)(a), l.existsSync(c.componentDir) || l.mkdirSync(c.componentDir, {
62
62
  recursive: !0
63
63
  }), c;
64
- }, R = async ({
64
+ }, k = async ({
65
65
  name: e,
66
66
  config: t,
67
67
  command: n
68
68
  }) => {
69
- if (![l.ADD, l.REMOVE].includes(n))
69
+ if (![u.ADD, u.REMOVE].includes(n))
70
70
  return m.error(`不支持组件${n}操作`), process.exit(1);
71
- const o = Z({
71
+ const o = z({
72
72
  ...t,
73
73
  name: e
74
74
  }), c = process.cwd(), a = JSON.stringify(o);
75
- for (const { entry: s, index: i } of t.list) {
75
+ for (const { entry: r, index: i } of t.list) {
76
76
  const d = {
77
77
  envData: a,
78
- rollback: n === l.REMOVE,
78
+ rollback: n === u.REMOVE,
79
79
  /** 回滚时可以删除空文件 */
80
80
  rollbackDelNullFile: !0,
81
81
  rollbackDelAskAsYes: !0,
@@ -83,28 +83,28 @@ const _ = (e, t) => {
83
83
  batch: !1,
84
84
  rootDir: c
85
85
  };
86
- if (s) {
87
- const r = s;
88
- r != null && r.input && (r.input = f(r.input)(o)), r != null && r.output && (r.output = f(r.output)(o));
89
- const b = {
90
- ...s,
91
- mode: E.APPEND,
86
+ if (r) {
87
+ const s = r;
88
+ s != null && s.input && (s.input = f(s.input)(o)), s != null && s.output && (s.output = f(s.output)(o));
89
+ const h = {
90
+ ...r,
91
+ mode: C.APPEND,
92
92
  ...d
93
93
  };
94
- await C(b);
94
+ await E(h);
95
95
  }
96
96
  if (i) {
97
- const r = i;
98
- r != null && r.input && (r.input = f(r.input)(o)), r != null && r.output && (r.output = f(r.output)(o));
99
- const b = {
97
+ const s = i;
98
+ s != null && s.input && (s.input = f(s.input)(o)), s != null && s.output && (s.output = f(s.output)(o));
99
+ const h = {
100
100
  ...i,
101
- mode: E.OVERWRITE,
101
+ mode: C.OVERWRITE,
102
102
  ...d
103
103
  };
104
- await C(b);
104
+ await E(h);
105
105
  }
106
106
  }
107
- }, H = () => ({
107
+ }, Z = () => ({
108
108
  outputJson: {
109
109
  alias: "o",
110
110
  describe: "是否输出组件名列表json",
@@ -118,45 +118,45 @@ const _ = (e, t) => {
118
118
  }
119
119
  }), y = (e) => {
120
120
  const { componentDir: t, nameExcludes: n } = e;
121
- return u.statSync(t).isDirectory() ? u.readdirSync(t).map((s) => {
122
- const i = p.join(t, s);
123
- return u.statSync(i).isDirectory() ? (m.info("filePath:", i, p.basename(i)), p.basename(i)) : "";
124
- }).filter((s) => !(!s || n.includes(s))) : (m.error("组件源码路径不是目录"), process.exit(1));
125
- }, k = async ({
121
+ return l.statSync(t).isDirectory() ? l.readdirSync(t).map((r) => {
122
+ const i = p.join(t, r);
123
+ return l.statSync(i).isDirectory() ? (m.info("filePath:", i, p.basename(i)), p.basename(i)) : "";
124
+ }).filter((r) => !(!r || n.includes(r))) : (m.error("组件源码路径不是目录"), process.exit(1));
125
+ }, R = async ({
126
126
  outputJson: e,
127
127
  outputPath: t
128
128
  }) => {
129
129
  m.stage("展示列表");
130
- const n = $(), o = y(n), c = t || n.nameListJsonOutputPath, a = o.map((s) => {
130
+ const n = $(), o = y(n), c = t || n.nameListJsonOutputPath, a = o.map((r) => {
131
131
  const { name: i, fullName: d } = D({
132
132
  ...n,
133
- name: s
133
+ name: r
134
134
  });
135
135
  return {
136
136
  name: i,
137
- nameKebab: s,
137
+ nameKebab: r,
138
138
  fullName: d
139
139
  };
140
140
  });
141
141
  if (m.table(
142
- a.map(({ name: s, fullName: i, nameKebab: d }) => ({
143
- [h.success("名称")]: s,
144
- [h.success("带系列名称")]: i,
145
- [h.success("绝对路径")]: p.resolve(
142
+ a.map(({ name: r, fullName: i, nameKebab: d }) => ({
143
+ [b.greenBright("名称")]: r,
144
+ [b.greenBright("带系列名称")]: i,
145
+ [b.greenBright("绝对路径")]: p.resolve(
146
146
  n.componentDir,
147
147
  d
148
148
  )
149
149
  }))
150
150
  ), e && c) {
151
- const s = p.resolve(c), i = p.dirname(s);
152
- u.existsSync(i) || u.mkdirSync(i, { recursive: !0 }), m.stage(`输出组件名列表到${s}`), u.writeFileSync(s, JSON.stringify(a, null, 2));
151
+ const r = p.resolve(c), i = p.dirname(r);
152
+ l.existsSync(i) || l.mkdirSync(i, { recursive: !0 }), m.stage(`输出组件名列表到${r}`), l.writeFileSync(r, JSON.stringify(a, null, 2));
153
153
  }
154
- }, U = {
155
- command: l.LIST,
154
+ }, H = {
155
+ command: u.LIST,
156
156
  describe: "展示组件列表",
157
- options: H(),
158
- handler: k
159
- }, W = () => ({
157
+ options: Z(),
158
+ handler: R
159
+ }, U = () => ({
160
160
  name: {
161
161
  describe: "组件名称",
162
162
  type: "string"
@@ -180,17 +180,17 @@ const _ = (e, t) => {
180
180
  name: t
181
181
  }).nameKebab === a)
182
182
  return m.error(`组件${a}已存在, 不能再次创建${t}组件`), process.exit(1);
183
- return R({
183
+ return k({
184
184
  name: t,
185
185
  config: n,
186
- command: l.ADD
186
+ command: u.ADD
187
187
  });
188
- }, Y = {
189
- command: `${l.ADD} <name>`,
188
+ }, W = {
189
+ command: `${u.ADD} <name>`,
190
190
  describe: "新增一个组件",
191
- positionals: W(),
191
+ positionals: U(),
192
192
  handler: A
193
- }, q = () => ({
193
+ }, Y = () => ({
194
194
  name: {
195
195
  describe: "组件名称",
196
196
  type: "string"
@@ -215,55 +215,55 @@ const _ = (e, t) => {
215
215
  series: c,
216
216
  name: o
217
217
  }).nameKebab === a) {
218
- await R({
218
+ await k({
219
219
  name: o,
220
220
  config: t,
221
- command: l.REMOVE
222
- }), u.rmdirSync(p.resolve(t.componentDir, a));
221
+ command: u.REMOVE
222
+ }), l.rmdirSync(p.resolve(t.componentDir, a));
223
223
  return;
224
224
  }
225
225
  return m.error(`组件${o}不存在`), process.exit(1);
226
- }, B = {
227
- command: `${l.REMOVE} [name]`,
226
+ }, q = {
227
+ command: `${u.REMOVE} [name]`,
228
228
  describe: "删除一个组件",
229
- positionals: q(),
229
+ positionals: Y(),
230
230
  handler: M
231
231
  }, ce = async (e, t) => {
232
232
  switch (e) {
233
- case l.ADD:
233
+ case u.ADD:
234
234
  return A(t);
235
- case l.REMOVE:
235
+ case u.REMOVE:
236
236
  return M(t);
237
- case l.LIST:
238
- return k(t);
237
+ case u.LIST:
238
+ return R(t);
239
239
  default:
240
240
  throw new Error(`不支持的命令 ${e}`);
241
241
  }
242
- }, { version: G, description: Q } = g, L = {
242
+ }, { version: G, description: Q } = g, j = {
243
243
  describe: Q,
244
244
  version: G,
245
245
  subcommands: [
246
- Y,
247
- B,
248
- U
246
+ W,
247
+ q,
248
+ H
249
249
  ].map(O),
250
250
  demandCommandCount: 1,
251
251
  rootScriptName: V({ packageJson: g })
252
252
  }, {
253
253
  cliConfig: { moduleName: P }
254
- } = g, j = (e = !1) => {
254
+ } = g, F = (e = !1) => {
255
255
  const t = e ? P : void 0, n = `$0${e ? ` ${P}` : ""} <command> [options]`;
256
256
  return { command: t, usage: n };
257
257
  }, me = async () => J({
258
- ...L,
259
- ...j()
260
- }), ue = () => O({
261
- ...L,
262
- ...j(!0)
258
+ ...j,
259
+ ...F()
260
+ }), le = () => O({
261
+ ...j,
262
+ ...F(!0)
263
263
  });
264
264
  export {
265
- l as S,
266
- ue as a,
265
+ u as S,
266
+ le as a,
267
267
  me as c,
268
268
  ce as h
269
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-26ea3160.js";
2
+ import { S as u, a as b, h as c } from "./index-1913b07b.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/cli-component",
3
- "version": "0.4.10-alpha.1",
3
+ "version": "0.4.11-alpha.0",
4
4
  "description": "组件命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -21,10 +21,7 @@
21
21
  "types"
22
22
  ],
23
23
  "scripts": {
24
- "clean": "rimraf es lib types",
25
- "predev": "pnpm run clean",
26
- "dev": "vite build --watch",
27
- "prebuild": "pnpm run clean",
24
+ "dev": "vite build -w -m hotBuild",
28
25
  "build": "vite build",
29
26
  "prepack": "pnpm build"
30
27
  },
@@ -41,7 +38,7 @@
41
38
  "license": "MIT",
42
39
  "sideEffects": false,
43
40
  "devDependencies": {
44
- "@done-coding/cli-inject": "0.5.21-alpha.1",
41
+ "@done-coding/cli-inject": "0.5.22-alpha.0",
45
42
  "@types/lodash.camelcase": "^4.3.8",
46
43
  "@types/lodash.kebabcase": "^4.1.8",
47
44
  "@types/lodash.lowerfirst": "^4.3.8",
@@ -49,22 +46,21 @@
49
46
  "@types/lodash.upperfirst": "^4.3.8",
50
47
  "@types/node": "^18.0.0",
51
48
  "@types/yargs": "^17.0.28",
52
- "rimraf": "^6.0.1",
53
49
  "typescript": "^5.8.3",
54
50
  "vite": "^4.4.11",
55
51
  "vite-plugin-dts": "^3.6.0"
56
52
  },
57
- "engines": {
58
- "node": ">=18.0.0"
59
- },
60
53
  "dependencies": {
61
- "@done-coding/cli-template": "0.8.8-alpha.1",
62
- "@done-coding/cli-utils": "0.8.2-alpha.1",
54
+ "@done-coding/cli-template": "0.8.9-alpha.0",
55
+ "@done-coding/cli-utils": "0.8.3-alpha.0",
63
56
  "lodash.camelcase": "^4.3.0",
64
57
  "lodash.kebabcase": "^4.1.1",
65
58
  "lodash.lowerfirst": "^4.3.1",
66
59
  "lodash.template": "^4.5.0",
67
60
  "lodash.upperfirst": "^4.3.1"
68
61
  },
69
- "gitHead": "660e39fc523e4eba1ea621e3c59122f98015a2de"
62
+ "engines": {
63
+ "node": ">=18.0.0"
64
+ },
65
+ "gitHead": "906b7683d9e4dc75fb07806b12e5507827122a16"
70
66
  }