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