@done-coding/cli-component 0.2.0 → 0.2.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/es/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as r } from "./index-78f9044a.js";
2
+ import { c as r } from "./index-8e0a0575.js";
3
3
  import "chalk";
4
4
  import "node:path";
5
5
  import "node:fs";
@@ -13,17 +13,17 @@ import { OutputModeEnum as $, handler as C } from "@done-coding/cli-template";
13
13
  import k from "yargs";
14
14
  import { hideBin as T } from "yargs/helpers";
15
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) => {
16
+ var i = /* @__PURE__ */ ((e) => (e.ADD = "add", e.REMOVE = "remove", e.LIST = "list", e))(i || {});
17
+ const _ = (e, n) => {
18
18
  if (!/^[a-zA-Z]+[a-zA-Z0-9-]*$/.test(e))
19
19
  return console.log(r.red("组件名只能包含字母、数字、中划线")), process.exit(1);
20
- const { nameExcludes: t } = o;
20
+ const { nameExcludes: t } = n;
21
21
  return t.includes(e) ? (console.log(
22
22
  r.red(`组件名: ${e}是保留名称。
23
23
  保留名称: ${t.join(",")}`)
24
24
  ), process.exit(1)) : !0;
25
25
  }, f = {
26
- version: "0.2.0",
26
+ version: "0.2.1",
27
27
  name: "@done-coding/cli-component",
28
28
  description: "组件命令行工具",
29
29
  cliConfig: {
@@ -34,13 +34,13 @@ const _ = (e, o) => {
34
34
  execDir: process.cwd(),
35
35
  templateDir: w()
36
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);
37
+ const { series: n, name: t } = e, s = E(y(t)), c = L(s), a = x(s), l = n ? E(y(n)) : "", o = l ? `${l}${s}` : "", p = x(o);
38
38
  return {
39
39
  series: l,
40
40
  name: s,
41
- nameLowerFirst: i,
41
+ nameLowerFirst: c,
42
42
  nameKebab: a,
43
- fullName: n,
43
+ fullName: o,
44
44
  fullNameKebab: p,
45
45
  cls: p
46
46
  };
@@ -61,62 +61,62 @@ const _ = (e, o) => {
61
61
  );
62
62
  if (!u.existsSync(s))
63
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;
64
+ const c = I.parse(u.readFileSync(s, "utf-8")), a = M();
65
+ return c.componentDir = d(c.componentDir)(a), c;
66
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)) : "";
67
+ const { componentDir: n, nameExcludes: t } = e;
68
+ return u.statSync(n).isDirectory() ? u.readdirSync(n).map((l) => {
69
+ const o = m.join(n, l);
70
+ return u.statSync(o).isDirectory() ? (console.log("filePath:", o, m.basename(o)), m.basename(o)) : "";
71
71
  }).filter((l) => !(!l || t.includes(l))) : (console.log(r.red("组件源码路径不是目录")), process.exit(1));
72
72
  }, K = async () => {
73
73
  console.log(r.blue("展示列表"));
74
- const e = h(), o = v(e);
74
+ const e = h(), n = v(e);
75
75
  console.table(
76
- o.map((t) => {
77
- const { name: s, fullName: i } = g({
76
+ n.map((t) => {
77
+ const { name: s, fullName: c } = g({
78
78
  ...e,
79
79
  name: t
80
80
  });
81
81
  return {
82
82
  [r.green("名称")]: s,
83
- [r.green("带系列名称")]: i,
83
+ [r.green("带系列名称")]: c,
84
84
  [r.green("绝对路径")]: m.resolve(e.componentDir, t)
85
85
  };
86
86
  })
87
87
  );
88
88
  }, N = async ({
89
89
  name: e,
90
- config: o,
90
+ config: n,
91
91
  command: t
92
92
  }) => {
93
- if (![c.ADD, c.REMOVE].includes(t))
93
+ if (![i.ADD, i.REMOVE].includes(t))
94
94
  return console.log(r.red(`不支持组件${t}操作`)), process.exit(1);
95
95
  const s = F({
96
- ...o,
96
+ ...n,
97
97
  name: e
98
- }), i = JSON.stringify(s);
99
- for (const { entry: a, index: l } of o.list) {
98
+ }), c = JSON.stringify(s);
99
+ for (const { entry: a, index: l } of n.list) {
100
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));
101
+ const o = a;
102
+ o != null && o.input && (o.input = d(o.input)(s)), o != null && o.output && (o.output = d(o.output)(s));
103
103
  const p = {
104
104
  ...a,
105
- envData: i,
105
+ envData: c,
106
106
  mode: $.APPEND,
107
- rollback: t === c.REMOVE,
107
+ rollback: t === i.REMOVE,
108
108
  dealMarkdown: !0
109
109
  };
110
110
  await C(p);
111
111
  }
112
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));
113
+ const o = l;
114
+ o != null && o.input && (o.input = d(o.input)(s)), o != null && o.output && (o.output = d(o.output)(s));
115
115
  const p = {
116
116
  ...l,
117
- envData: i,
117
+ envData: c,
118
118
  mode: $.OVERWRITE,
119
- rollback: t === c.REMOVE,
119
+ rollback: t === i.REMOVE,
120
120
  dealMarkdown: !0
121
121
  };
122
122
  await C(p);
@@ -124,29 +124,29 @@ const _ = (e, o) => {
124
124
  }
125
125
  }, U = async ({ name: e }) => {
126
126
  console.log(r.blue("添加组件"));
127
- let o;
128
- e ? o = e : o = (await S({
127
+ let n;
128
+ e ? n = e : n = (await S({
129
129
  type: "text",
130
130
  name: "name",
131
131
  message: "请输入组件名"
132
132
  })).name;
133
133
  const t = h();
134
- _(o, t);
135
- const { series: s } = t, i = await v(t);
136
- for (let a of i)
134
+ _(n, t);
135
+ const { series: s } = t, c = await v(t);
136
+ for (let a of c)
137
137
  if (g({
138
138
  series: s,
139
- name: o
139
+ name: n
140
140
  }).nameKebab === a)
141
- return console.log(r.red(`组件${a}已存在, 不能再次创建${o}组件`)), process.exit(1);
141
+ return console.log(r.red(`组件${a}已存在, 不能再次创建${n}组件`)), process.exit(1);
142
142
  return N({
143
- name: o,
143
+ name: n,
144
144
  config: t,
145
- command: c.ADD
145
+ command: i.ADD
146
146
  });
147
147
  }, z = async ({ name: e }) => {
148
148
  console.log(r.blue("移除组件"));
149
- const o = h(), t = await v(o);
149
+ const n = h(), t = await v(n);
150
150
  if (t.length === 0)
151
151
  return console.log(r.red("组件列表为空")), process.exit(1);
152
152
  let s;
@@ -156,45 +156,44 @@ const _ = (e, o) => {
156
156
  message: "请选择要移除的组件",
157
157
  choices: t.map((a) => ({ title: a, value: a }))
158
158
  })).name;
159
- const { series: i } = o;
159
+ const { series: c } = n;
160
160
  for (let a of t)
161
161
  if (g({
162
- series: i,
162
+ series: c,
163
163
  name: s
164
164
  }).nameKebab === a) {
165
165
  await N({
166
166
  name: s,
167
- config: o,
168
- command: c.REMOVE
169
- }), u.rmdirSync(m.resolve(o.componentDir, a));
167
+ config: n,
168
+ command: i.REMOVE
169
+ }), u.rmdirSync(m.resolve(n.componentDir, a));
170
170
  return;
171
171
  }
172
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);
173
+ }, b = async (e, n) => (console.log("com", n), e === i.ADD ? U(n) : e === i.REMOVE ? z(n) : e === i.LIST ? K() : (console.log(r.red(`无效的命令: ${e}`)), process.exit(1))), R = async (e) => {
174
+ }, P = f.cliConfig.moduleName, H = (e, n) => {
175
+ console.log(e ? r.red(e) : r.red(n.message)), process.exit(1);
177
176
  }, J = f.description, Z = `Usage: $0 ${P} <command> [options]`, B = "Usage: $0 <command> [options]", O = (e) => e.command({
178
- command: `${c.ADD} <name>`,
177
+ command: `${i.ADD} <name>`,
179
178
  describe: "新增一个组件",
180
- builder: (o) => o.positional("name", {
179
+ builder: (n) => n.positional("name", {
181
180
  describe: "组件名称",
182
181
  type: "string"
183
182
  }),
184
- handler: D(b)(c.ADD)
183
+ handler: D(b)(i.ADD)
185
184
  }).command({
186
- command: `${c.REMOVE} [name]`,
185
+ command: `${i.REMOVE} [name]`,
187
186
  describe: "删除一个组件",
188
- builder: (o) => o.positional("name", {
187
+ builder: (n) => n.positional("name", {
189
188
  describe: "组件名称",
190
189
  type: "string"
191
190
  }),
192
- handler: D(b)(c.REMOVE)
191
+ handler: D(b)(i.REMOVE)
193
192
  }).command({
194
- command: c.LIST,
193
+ command: i.LIST,
195
194
  describe: "展示组件列表",
196
- handler: D(b)(c.LIST)
197
- }).demandCommand(1), V = (e, o = !1) => o ? O(e.strict().usage(Z)) : O(
195
+ handler: D(b)(i.LIST)
196
+ }).demandCommand(1), V = (e, n = !1) => n ? O(e.strict().usage(Z)) : O(
198
197
  e.strict().usage(B).help("help").version(f.version).alias("v", "version").alias("h", "help")
199
198
  ).fail(H).argv, W = (e) => V(e, !0), me = {
200
199
  command: P,
@@ -202,8 +201,8 @@ const _ = (e, o) => {
202
201
  builder: W,
203
202
  handler: R
204
203
  }, ue = async () => {
205
- const e = k(T(process.argv)), o = await V(e);
206
- return R(o);
204
+ const e = k(T(process.argv));
205
+ return await V(e), R();
207
206
  };
208
207
  export {
209
208
  me as a,
package/es/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as u, h as v } from "./index-78f9044a.js";
2
+ import { a as u, h as v } from "./index-8e0a0575.js";
3
3
  import "chalk";
4
4
  import "node:path";
5
5
  import "node:fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-component",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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.4",
44
+ "@done-coding/cli-inject": "^0.4.5",
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.5.0",
65
+ "@done-coding/cli-template": "^0.5.1",
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": "383ec04131808af21ca8fdf3652daa48d86cab1c"
78
+ "gitHead": "465ac238437ab8bd3803c5e6fe8ac5a30bc445f3"
79
79
  }
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- "version": "0.2.0",
2
+ "version": "0.2.1",
3
3
  "name": "@done-coding/cli-component",
4
4
  "description": "组件命令行工具",
5
5
  "cliConfig": {