mine-auto-cli 2.3.3 → 2.4.1-beta.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # mine-auto-cli
2
2
 
3
- 一个将多个命令简化成一个命令的项目 😆
3
+ 一个将多个命令简化成一个命令的工具 😆
4
4
 
5
5
  <h2 align="center">
6
6
  <a href="https://www.npmjs.com/package/mine-auto-cli"><img src="https://img.shields.io/npm/v/mine-auto-cli.svg?logo=npm" alt="版本" /></a>
@@ -11,11 +11,13 @@
11
11
 
12
12
  ## 特性
13
13
 
14
+ - [x] [初始化配置文件](#初始化配置文件)
14
15
  - [x] [简化 `Git` 提交命令](#简化-git-提交命令)
15
16
  - [x] [简化打包提交命令](#简化打包提交命令)
16
17
  - [x] [简化手动更改版本号命令](#简化手动更改版本号命令)
17
18
  - [x] [生成工作目录结构文件](#生成工作目录结构文件)
18
19
  - [x] [检查 `package.json` 依赖版本](#检查-packagejson-依赖版本)
20
+ - [x] [生成依赖注释文件](#生成依赖注释文件)
19
21
 
20
22
  ## 全局安装
21
23
 
@@ -37,6 +39,50 @@ auto -v
37
39
  auto -h
38
40
  ```
39
41
 
42
+ ### 初始化配置文件
43
+
44
+ - 自动生成初始化 `auto-cli.jsonc` 文件
45
+ - 带上 `-y` 或者 `--yml` 生成 `auto-cli.yml`
46
+ - 如果两个文件都存在,则合并优先于 `auto-cli.jsonc` 文件
47
+ - 初始化的所有字段仅是默认值和可选值,可以自定义删除
48
+
49
+ ```sh
50
+ auto init
51
+ ```
52
+
53
+ - 字段解析:
54
+
55
+ - `prefix`: 版本前缀,默认为 `^`
56
+ - `registry`: 依赖来源,默认为 `https://registry.npmmirror.com/`
57
+ - `check`: 是否更新 `package.json` 文件,为 `true` 时等同于 `auto check -u`, `-u` 优先级最高, 默认为 `false`
58
+ - `reject`: 拒绝检查的依赖,默认为 `[]`
59
+ - `resolve`: 指定版本检查的标签,默认为 `[]`,例如:['mine-auto-cli@beta'],默认标签为 `latest`
60
+ - `comment`: 配置依赖解析说明预设
61
+
62
+ - auto-cli.jsonc
63
+
64
+ ```json
65
+ {
66
+ "prefix": "^",
67
+ "registry": "https://registry.npmmirror.com/",
68
+ "check": false,
69
+ "reject": [],
70
+ "resolve": [],
71
+ "comment": {}
72
+ }
73
+ ```
74
+
75
+ - auto-cli.yml
76
+
77
+ ```yml
78
+ prefix: ^
79
+ registry: https://registry.npmmirror.com/
80
+ check: false
81
+ reject: []
82
+ resolve: []
83
+ comment: {}
84
+ ```
85
+
40
86
  ### 简化 Git 提交命令
41
87
 
42
88
  ```sh
@@ -108,36 +154,38 @@ auto check
108
154
 
109
155
  ![img](./assets/check.png)
110
156
 
111
- #### `check.config.json`
157
+ ### 生成依赖注释文件
112
158
 
113
- - 自动生成初始化 `check.config.json` 文件
159
+ - 可以在工作目录生成 `comment.md` 文件
114
160
 
115
161
  ```sh
116
- npm check -i
162
+ auto comment
117
163
  ```
118
164
 
119
- - 字段解析:
120
- - `prefix`: 版本前缀,默认为 `^`
121
- - `registry`: 依赖来源,默认为 `https://registry.npmmirror.com/`
122
- - `check`: 是否更新 `package.json` 文件,为 `true` 时等同于 `auto check -u`, `-u` 优先级最高, 默认为 `false`
123
- - `reject`: 拒绝检查的依赖,默认为 `[]`
124
- - `resolve`: 指定版本检查的标签,默认为 `[]`,例如:['mine-auto-cli@beta'],默认标签为 `latest`
165
+ - `comment.md`
166
+ - 可以在 `auto-cli.jsonc` 配置 `comment` 用来设置预设值,不设置的话默认为空
125
167
 
126
- ```json
127
- {
128
- "prefix": "^",
129
- "registry": "https://registry.npmmirror.com/",
130
- "check": false,
131
- "reject": [],
132
- "resolve": []
133
- }
168
+ ```MD
169
+ ### 依赖解析
170
+
171
+ #### dependencies
172
+
173
+ - `mine-h5-ui`:
174
+
175
+ #### devDependencies
176
+
177
+ - `mine-auto-cli`:
178
+
179
+ #### optionalDependencies
180
+
181
+ - `@rollup/rollup-linux-x64-gnu`:
134
182
  ```
135
183
 
136
184
  ### 技术栈
137
185
 
138
- - `Vite` + `TypeScript` + `Node`
186
+ - `Vite` + `TypeScript` + `NodeJs`
139
187
 
140
- ### 依赖特性
188
+ ### 依赖解析
141
189
 
142
190
  #### dependencies
143
191
 
@@ -160,4 +208,4 @@ npm check -i
160
208
 
161
209
  ## 贡献者们
162
210
 
163
- [![贡献者](https://contrib.rocks/image?repo=biaov/mine-auto-cli)](https://github.com/biaov/mine-auto-cli/graphs/contributors)
211
+ [![贡献者们](https://contrib.rocks/image?repo=biaov/mine-auto-cli)](https://github.com/biaov/mine-auto-cli/graphs/contributors)
@@ -3,5 +3,6 @@
3
3
  "registry": "https://registry.npmmirror.com/", // 依赖来源,默认为 `https://registry.npmmirror.com/`
4
4
  "check": false, // 是否更新 `package.json` 文件,为 `true` 时等同于 `auto check -u`, `-u` 优先级最 高, 默认为 `false`
5
5
  "reject": [], // 拒绝检查的依赖,默认为 `[]`
6
- "resolve": [] // 指定版本检查的标签,默认为 `[]`,例如:['mine-auto-cli@beta'],默认标签为 `latest`
6
+ "resolve": [], // 指定版本检查的标签,默认为 `[]`,例如:['mine-auto-cli@beta'],默认标签为 `latest`
7
+ "comment": {} // 配置依赖解析说明预设
7
8
  }
package/dist/index.js CHANGED
@@ -1,244 +1,299 @@
1
- import W from "update-notifier";
1
+ import { program as g } from "commander";
2
2
  import a from "chalk";
3
- import { program as m } from "commander";
4
- import X from "ora";
5
- import { execSync as Y } from "child_process";
6
- import { readFileSync as v, writeFileSync as k, existsSync as O, readdirSync as Z } from "fs";
7
- import { join as b, resolve as q } from "path";
8
- import F from "log-symbols";
9
- import ee from "pacote";
10
- import R from "strip-json-comments";
11
- const U = "mine-auto-cli", G = "2.3.3", te = "./dist/index.js", ne = "./dist/index.js", oe = "module", se = {
3
+ import { readFileSync as h, writeFileSync as v, existsSync as b, readdirSync as ee } from "fs";
4
+ import { join as w, resolve as j } from "path";
5
+ import R from "log-symbols";
6
+ import te from "ora";
7
+ import { execSync as ne } from "child_process";
8
+ import oe from "js-yaml";
9
+ import se from "strip-json-comments";
10
+ import re from "pacote";
11
+ import ce from "update-notifier";
12
+ const G = "mine-auto-cli", _ = "2.4.1-beta.0", ie = "./dist/index.js", ae = "./dist/index.js", le = "module", pe = {
12
13
  auto: "bin/mine-auto-cli.js"
13
- }, re = {
14
+ }, me = {
14
15
  name: "biaov",
15
16
  email: "biaov@qq.com",
16
17
  url: "https://biaov.cn"
17
- }, ie = "一个将多个命令简化成一个命令的项目 😆", ce = {
18
+ }, ge = "一个将多个命令简化成一个命令的工具 😆", ue = {
18
19
  start: "npm run dev",
19
20
  dev: "npm run build -- --watch",
20
- build: "node scripts/build && vite build",
21
+ build: "vite build",
21
22
  prettier: "prettier --write '**/*.{js,ts,md,json}'",
22
23
  tag: "node scripts/tag"
23
- }, ae = {
24
+ }, de = {
24
25
  registry: "https://registry.npmjs.org/",
25
26
  "engine-strict": !0,
26
27
  provenance: !0
27
- }, pe = {
28
+ }, fe = {
28
29
  node: ">=20.12"
29
- }, le = [
30
+ }, he = [
30
31
  "auto",
31
32
  "cli",
32
33
  "vite",
33
34
  "typescript"
34
- ], ge = {
35
+ ], ye = {
35
36
  type: "git",
36
37
  url: "git+https://github.com/biaov/mine-auto-cli.git"
37
- }, me = "https://github.com/biaov/mine-auto-cli.git", de = {
38
+ }, $e = "https://github.com/biaov/mine-auto-cli.git", ve = {
38
39
  url: "https://github.com/biaov/mine-auto-cli/issues"
39
- }, ue = "ISC", fe = [
40
+ }, be = "ISC", je = [
40
41
  {
41
42
  name: "biaov",
42
43
  email: "biaov@qq.com"
43
44
  }
44
- ], he = {
45
+ ], ke = {
45
46
  chalk: "^5.3.0",
46
47
  commander: "^12.0.0",
48
+ "js-yaml": "^4.1.0",
47
49
  "log-symbols": "^6.0.0",
48
50
  ora: "^8.0.1",
49
51
  pacote: "^18.0.6",
50
52
  "strip-json-comments": "^5.0.1",
51
53
  "update-notifier": "^7.0.0"
52
- }, ye = {
53
- "@types/node": "^20.12.11",
54
+ }, we = {
55
+ "@types/js-yaml": "^4.0.9",
56
+ "@types/node": "^20.12.12",
54
57
  "@types/pacote": "^11.1.8",
55
58
  "@types/update-notifier": "^6.0.8",
56
59
  prettier: "^3.2.5",
57
60
  typescript: "^5.4.5",
58
61
  vite: "^5.2.11"
59
- }, x = {
60
- name: U,
62
+ }, O = {
63
+ name: G,
61
64
  private: !1,
62
- version: G,
63
- exports: te,
64
- main: ne,
65
- type: oe,
66
- bin: se,
67
- author: re,
68
- description: ie,
69
- scripts: ce,
70
- publishConfig: ae,
71
- engines: pe,
72
- keywords: le,
73
- repository: ge,
74
- homepage: me,
75
- bugs: de,
76
- license: ue,
77
- contributors: fe,
78
- dependencies: he,
79
- devDependencies: ye
80
- }, h = (e) => {
81
- console.log(`${F.success} ${a.green("SUCCESS")} ${e}`);
82
- }, L = (e) => {
83
- console.log(`${U} ${F.error} ${a.red("ERROR")} ${e}`);
84
- }, p = (e) => {
65
+ version: _,
66
+ exports: ie,
67
+ main: ae,
68
+ type: le,
69
+ bin: pe,
70
+ author: me,
71
+ description: ge,
72
+ scripts: ue,
73
+ publishConfig: de,
74
+ engines: fe,
75
+ keywords: he,
76
+ repository: ye,
77
+ homepage: $e,
78
+ bugs: ve,
79
+ license: be,
80
+ contributors: je,
81
+ dependencies: ke,
82
+ devDependencies: we
83
+ }, d = (e) => {
84
+ console.log(`${R.success} ${a.green("SUCCESS")} ${e}`);
85
+ }, J = (e) => {
86
+ console.log(`${G} ${R.error} ${a.red("ERROR")} ${e}`);
87
+ }, l = (e) => {
85
88
  console.log(e ?? "");
86
- }, $e = (e) => ["git add -A", `git commit -m ${e}`, "git push"], ve = (e, t) => [`npm run ${e}`, "git add -A", `git commit -m ${t}`, "git push"], _ = (e) => {
87
- p(`开始执行 ${a.cyanBright(e)} 命令`);
88
- const t = X({ text: "正在执行命令中...", color: "yellow" });
89
+ }, B = (e) => {
90
+ l(`开始执行 ${a.cyanBright(e)} 命令`);
91
+ const t = te({ text: "正在执行命令中...", color: "yellow" });
89
92
  t.start();
90
- const i = Y(e, { cwd: process.cwd() });
91
- p(i.toString()), t.succeed(`${a.green(e)} 命令执行成功`), p();
92
- }, be = async (e = "更新代码") => {
93
- p(), p(`${a.yellow(">>")} 开始依次执行命令...`), p(), $e(e).forEach(_), h("全部命令执行完成"), p();
94
- }, ke = async (e, t = "打包") => {
95
- p(), p(`${a.yellow(">>")} 开始依次执行命令...`), p(), ve(e, t).map(_), h("全部命令执行完成"), p();
96
- }, D = (e) => {
97
- p(), L(`\`${e}\` 命令错误,请检查你的命令`), p(), m.help();
98
- }, I = (e) => {
99
- const t = ["package.json", "README.md"].map((s) => {
100
- const r = b(process.cwd(), s), c = v(r).toString();
101
- return { path: r, content: c };
102
- }), [i, n] = t, o = JSON.parse(i.content);
93
+ const o = ne(e, { cwd: process.cwd() });
94
+ l(o.toString()), t.succeed(`${a.green(e)} 命令执行成功`), l();
95
+ }, Se = (e) => ["git add -A", `git commit -m ${e}`, "git push"], Ce = (e, t) => [`npm run ${e}`, "git add -A", `git commit -m ${t}`, "git push"], xe = async (e, t = "打包") => {
96
+ l(), l(`${a.yellow(">>")} 开始依次执行命令...`), l(), Ce(e, t).map(B), d("全部命令执行完成"), l();
97
+ }, V = (e) => {
98
+ l(), J(`\`${e}\` 命令错误,请检查你的命令`), l(), g.help();
99
+ }, L = (e) => {
100
+ const t = ["package.json", "README.md"].map((r) => {
101
+ const c = w(process.cwd(), r), i = h(c).toString();
102
+ return { path: c, content: i };
103
+ }), [o, n] = t, s = JSON.parse(o.content);
103
104
  if (e)
104
- o.version = e;
105
+ s.version = e;
105
106
  else {
106
- const s = o.version.split(".").reduce((r, c, l, g) => r + (l === g.length - 1 ? +c + 1 : `${c}.`), "");
107
- o.version = s;
107
+ const r = s.version.split(".").reduce((c, i, p, m) => c + (p === m.length - 1 ? +i + 1 : `${i}.`), "");
108
+ s.version = r;
108
109
  }
109
- k(i.path, JSON.stringify(o, null, 2)), n.content = n.content.replace(/version\-v.+\-blue/, () => `version-v${o.version}-blue`), k(n.path, n.content);
110
- }, we = async (e) => {
110
+ v(o.path, JSON.stringify(s, null, 2)), n.content = n.content.replace(/version\-v.+\-blue/, () => `version-v${s.version}-blue`), v(n.path, n.content);
111
+ }, Oe = async (e) => {
111
112
  const t = e.split("version")[1];
112
113
  if (!t)
113
- return D(e);
114
- const i = JSON.parse(v(b(process.cwd(), "package.json"), "utf-8"));
114
+ return V(e);
115
+ const o = JSON.parse(h(w(process.cwd(), "package.json")).toString());
115
116
  if (t === "++") {
116
- const o = i.version.split(".").reduce((s, r, c, l) => s + (c === l.length - 1 ? +r + 1 : `${r}.`), "");
117
- I(o), p(), h("命令执行完成");
117
+ const s = o.version.split(".").reduce((r, c, i, p) => r + (i === p.length - 1 ? +c + 1 : `${c}.`), "");
118
+ L(s), l(), d("命令执行完成");
118
119
  return;
119
120
  }
120
121
  const n = t.split("@")[1];
121
- n ? (I(n), p(), h("命令执行完成")) : D(e);
122
- }, Se = (e, t) => {
122
+ n ? (L(n), l(), d("命令执行完成")) : V(e);
123
+ }, Je = (e, t) => {
123
124
  if (e.includes("build"))
124
- return ke(e, t);
125
+ return xe(e, t);
125
126
  if (e.includes("version"))
126
- return we(e);
127
- L(a.hex("#f56c6c")(`\`auto ${e}${t ? ` ${t}` : ""}\` 命令不存在`)), m.help();
128
- }, A = ["dist", "node_modules", ".git", "miniprogram_npm"];
129
- let V = 0, B = !1, J = !1, z = 20;
130
- const P = ({ prev: e, i: t, index: i, arr: n, curText: o }) => {
131
- const s = Array.from({ length: t }).reduce((g) => g + `${t === 1 && i === n.length - 1 ? "└ " : "│ "} `, ""), r = e + s, c = (s + o).length, l = Array.from({ length: z + V - c }).reduce((g) => `${g}-`, " ");
132
- return !B && (V = Math.max(V, c)), `${r}${o}${J ? l : ""}
127
+ return Oe(e);
128
+ J(a.hex("#f56c6c")(`\`auto ${e}${t ? ` ${t}` : ""}\` 命令不存在`)), g.help();
129
+ }, $ = "https://gitee.com/biaovorg/project-template.git", Ne = {
130
+ vue: $,
131
+ react: $,
132
+ "uni-app": $,
133
+ electron: $,
134
+ node: $,
135
+ "node-simple": $
136
+ }, Ee = Object.keys(Ne);
137
+ Ee.reduce((e, t, o) => e + (o ? ", " : "") + t, "");
138
+ const f = (e = "jsonc") => `auto-cli.${e}`;
139
+ j(import.meta.dirname, "./presetData.json");
140
+ const Y = (e, t = !1) => {
141
+ if (!b(e))
142
+ return t ? {} : "";
143
+ const o = h(e).toString();
144
+ return t ? JSON.parse(se(o)) : o;
145
+ }, Pe = (e) => {
146
+ if (!b(e))
147
+ return {};
148
+ const t = h(e).toString();
149
+ try {
150
+ return oe.load(t);
151
+ } catch {
152
+ return {};
153
+ }
154
+ }, z = (e = !1) => Y(j(import.meta.dirname, f()), e), H = () => {
155
+ const [e, t] = [f(), f("yml")].map((n) => j(process.cwd(), n)), o = z(!0);
156
+ try {
157
+ Object.assign(o, Pe(t), Y(e, !0));
158
+ } catch {
159
+ }
160
+ return o;
161
+ }, De = (e, t = !1) => {
162
+ let o = z(t);
163
+ return t && (o = JSON.stringify(o, null, 2)), e.includes(".yml") ? o.trim().split(`
164
+ `).slice(1, -1).reduce((n, s) => n + s.trim().replace(/[",]/g, "").replace("// ", "# ") + `
165
+ `, "") : o;
166
+ }, Me = ({ yml: e, uncomment: t, force: o }) => {
167
+ l();
168
+ const n = f(e ? "yml" : "jsonc"), s = j(process.cwd(), n);
169
+ if (b(s) && !o) {
170
+ l(a.yellow(`${n} 文件已存在`)), l(), l(a.yellow(`文件目录 ${s}`));
171
+ return;
172
+ }
173
+ v(s, De(n, t)), d(`${n} 文件创建成功`), l(), l(a.green(`文件目录 ${s}`));
174
+ };
175
+ g.command("init").option("-f, --force", `强制替换 ${f()} 文件内容`, !1).option("-unc, --uncomment", `取消生成 ${f()} 带注释`, !1).option("-y, --yml", `生成 ${f("yml")} 文件`, !1).description("初始化配置文件").action(Me);
176
+ const Ve = async (e = "更新代码") => {
177
+ l(), l(`${a.yellow(">>")} 开始依次执行命令...`), l(), Se(e).forEach(B), d("全部命令执行完成"), l();
178
+ };
179
+ g.command("git [描述]").description("简化 Git 提交命令").action(Ve);
180
+ const A = ["dist", "node_modules", ".git", "miniprogram_npm"];
181
+ let N = 0, K = !1, P = !1, Q = 20;
182
+ const I = ({ prev: e, i: t, index: o, arr: n, curText: s }) => {
183
+ const r = Array.from({ length: t }).reduce((m) => m + `${t === 1 && o === n.length - 1 ? "└ " : "│ "} `, ""), c = e + r, i = (r + s).length, p = Array.from({ length: Q + N - i }).reduce((m) => `${m}-`, " ");
184
+ return !K && (N = Math.max(N, i)), `${c}${s}${P ? p : ""}
133
185
  `;
134
- }, E = (e, t = 0) => e.reduce((i, n, o, s) => {
135
- let r;
136
- return n.children ? (r = `├── ${n.name}`, P({ prev: i, i: t, index: o, arr: s, curText: r }) + E(n.children, t + 1)) : (r = `${o === s.length - 1 ? "└── " : "├── "}${n.name}`, P({ prev: i, i: t, index: o, arr: s, curText: r }));
137
- }, ""), M = (e) => Z(e, { withFileTypes: !0 }).sort((t, i) => +i.isDirectory() - +t.isDirectory()), je = ({ line: e, name: t }) => {
138
- J = !!e, typeof e == "string" && (z = +e);
139
- const i = process.cwd(), n = b(i, ".gitignore");
140
- if (O(n)) {
141
- const l = v(n, { encoding: "utf-8" }).split(`\r
186
+ }, D = (e, t = 0) => e.reduce((o, n, s, r) => {
187
+ let c;
188
+ return n.children ? (c = `├── ${n.name}`, I({ prev: o, i: t, index: s, arr: r, curText: c }) + D(n.children, t + 1)) : (c = `${s === r.length - 1 ? "└── " : "├── "}${n.name}`, I({ prev: o, i: t, index: s, arr: r, curText: c }));
189
+ }, ""), F = (e) => ee(e, { withFileTypes: !0 }).sort((t, o) => +o.isDirectory() - +t.isDirectory()), Le = ({ line: e, name: t }) => {
190
+ P = !!e, typeof e == "string" && (Q = +e);
191
+ const o = process.cwd(), n = w(o, ".gitignore");
192
+ if (b(n)) {
193
+ const p = h(n).toString().split(`\r
142
194
  `);
143
- A.push(...l);
195
+ A.push(...p);
144
196
  }
145
- const o = i.split("\\").at(-1), r = M(i).map((l) => {
146
- const { name: g } = l, d = { name: g };
147
- return !A.includes(g) && l.isDirectory() && (d.children = M(b(l.path, g)).map(({ name: u }) => ({ name: u }))), d;
148
- }), c = [{ name: o, children: r }];
149
- J && (E(c), B = !0), k(b(i, `${typeof t == "string" && t || "directory"}.md`), E(c));
197
+ const s = o.split("\\").at(-1), c = F(o).map((p) => {
198
+ const { name: m } = p, u = { name: m };
199
+ return !A.includes(m) && p.isDirectory() && (u.children = F(w(p.path, m)).map(({ name: k }) => ({ name: k }))), u;
200
+ }), i = [{ name: s, children: c }];
201
+ P && (D(i), K = !0), v(w(o, `${typeof t == "string" && t || "directory"}.md`), D(i));
150
202
  };
151
- m.command("mkdir").option("-l, --line [数量]", "数量", !1).option("-n, --name [文件名称]", "文件名称", !1).option("-d, --depth [深度值]", "深度值", "3").description("生成目录结构文件").action(je);
152
- const T = { encoding: "utf-8" }, H = v(q(import.meta.dirname, "./check.config.jsonc")).toString(), f = JSON.parse(R(H.toString())), w = "check.config.jsonc", xe = [w, "package.json"], [$, C] = xe.map((e) => q(process.cwd(), e)), Oe = () => {
153
- if (p(), O($)) {
154
- p(a.yellow(`${w} 文件已存在`)), p(), p(a.yellow(`文件目录 ${$}`));
155
- return;
156
- }
157
- k($, H), h(`${w} 文件创建成功`), p(), p(a.green(`文件目录 ${$}`));
158
- }, Ve = (e, t) => {
159
- const i = Array.from({ length: t }, (r, c) => c < e ? "=" : " ").join(""), n = ~~(e / t * 100), o = `\r查找进度:[${i}] ${e}/${t} ${n}%\r`, s = e === t ? a.green(o) : a.yellow(o);
160
- process.stdout.write(s);
161
- }, Ce = (e, t, i) => {
203
+ g.command("mkdir").option("-l, --line [数量]", "数量", !1).option("-n, --name [文件名称]", "文件名称", !1).option("-d, --depth [深度值]", "深度值", "3").description("生成目录结构文件").action(Le);
204
+ const S = H(), [E] = ["package.json"].map((e) => j(process.cwd(), e)), Ae = (e, t) => {
205
+ const o = Array.from({ length: t }, (c, i) => i < e ? "=" : " ").join(""), n = ~~(e / t * 100), s = `\r查找进度:[${o}] ${e}/${t} ${n}%\r`, r = e === t ? a.green(s) : a.yellow(s);
206
+ process.stdout.write(r);
207
+ }, Ie = (e, t, o) => {
162
208
  let n = "latest";
163
- f.resolve.some((s) => {
164
- const r = s.lastIndexOf("@");
165
- if (r <= 0)
209
+ S.resolve.some((r) => {
210
+ const c = r.lastIndexOf("@");
211
+ if (c <= 0)
166
212
  return !0;
167
- const c = s.slice(0, r), l = s.slice(r + 1);
168
- if (e === c)
169
- return n = l, !0;
213
+ const i = r.slice(0, c), p = r.slice(c + 1);
214
+ if (e === i)
215
+ return n = p, !0;
170
216
  });
171
- const o = f.prefix + i[n];
172
- return { name: e, value: t, newVersion: o, tag: n };
173
- }, Je = (e, t) => Array.from({ length: t - e }, () => " ").join(""), Ee = (e, t) => (+!t + 1) * e.length, Le = (e, t) => {
174
- const i = e.match(/\d.+/g)[0].split("."), n = t.match(/\d.+/g)[0].split("."), o = n.slice(0, -1).findIndex((r, c) => +r > +i[c]), s = f.prefix + n[0];
175
- switch (o) {
176
- case 0:
177
- return a.red(t);
178
- case 1:
179
- return `${s}.${a.yellow(n[1])}.${a.yellow(n[2])}`;
180
- default:
181
- const r = i.at(-1), c = n.at(-1);
182
- return r !== c && parseInt(c) >= parseInt(r) ? `${s}.${n[1]}.${a.green(n[2])}` : !1;
183
- }
184
- }, Ne = (e) => {
217
+ const s = S.prefix + o[n];
218
+ return { name: e, value: t, newVersion: s, tag: n };
219
+ }, Fe = (e, t) => Array.from({ length: t - e }, () => " ").join(""), Te = (e, t) => (+!t + 1) * e.length, T = (e) => {
220
+ const [t = 0, o = 0, n = 0] = e.match(/\d.+/g)[0].split(".");
221
+ return [+t, +o, +n];
222
+ }, Ue = (e, t) => {
223
+ const [o, n, s] = T(e), [r, c, i] = T(t);
224
+ return r > o ? a.red(t) : r < o ? !1 : c > n ? `${r}.${a.yellow(c)}.${a.yellow(i)}` : c < n ? !1 : i > s ? `${r}.${c}.${a.green(i)}` : !1;
225
+ }, qe = (e) => {
185
226
  const t = {};
186
227
  e.forEach((n) => {
187
- Object.entries(n).forEach(([o, s]) => {
188
- t[o] = Math.max(s.length, t[o] ?? 0);
228
+ Object.entries(n).forEach(([s, r]) => {
229
+ t[s] = Math.max(r.length, t[s] ?? 0);
189
230
  });
190
231
  }), e.unshift({ name: "包名", value: "版本", newVersion: "新版本", tag: "标签" });
191
- const i = [];
192
- e.forEach(({ name: n, value: o, newVersion: s, tag: r }, c) => {
193
- const [l, g, d, u] = Object.entries({ name: n, value: o, newVersion: s, tag: r }).map(([S, Q]) => Je(Ee(Q, c), t[S]));
194
- let y = a.yellow("→"), N = !0;
195
- if (c) {
196
- const S = Le(o, s);
197
- S ? s = S : N = !1;
232
+ const o = [];
233
+ e.forEach(({ name: n, value: s, newVersion: r, tag: c }, i) => {
234
+ const [p, m, u, k] = Object.entries({ name: n, value: s, newVersion: r, tag: c }).map(([C, Z]) => Fe(Te(Z, i), t[C]));
235
+ let y = a.yellow("→"), M = !0;
236
+ if (i) {
237
+ const C = Ue(s, r);
238
+ C ? r = C : M = !1;
198
239
  } else
199
- n = a.green(n), o = a.green(o), s = a.green(s), r = a.green(r), y = " ";
200
- const K = `${n + l} ${g + o} ${y} ${d + s} ${u + r}`;
201
- N && i.push(K);
202
- }), i.length > 1 ? i.forEach(p) : h("所有版本已是最新");
203
- }, De = async (e, t, i) => {
204
- p();
240
+ n = a.green(n), s = a.green(s), r = a.green(r), c = a.green(c), y = " ";
241
+ const X = `${n + p} ${m + s} ${y} ${u + r} ${k + c}`;
242
+ M && o.push(X);
243
+ }), o.length > 1 ? o.forEach(l) : d("所有版本已是最新");
244
+ }, Re = async (e, t, o) => {
245
+ l();
205
246
  let n = 0;
206
- const o = [], s = Object.entries(e), r = s.map(async ([c, l]) => {
207
- const g = await ee.packument(c, { registry: f.registry }), d = Ce(c, l, g["dist-tags"]);
208
- o.push(d), t.forEach((u) => {
209
- const y = i[u];
210
- y && y[c] && (y[c] = d.newVersion);
211
- }), n++, await Ve(n, s.length);
247
+ const s = [], r = Object.entries(e), c = r.map(async ([i, p]) => {
248
+ const m = await re.packument(i, { registry: S.registry }), u = Ie(i, p, m["dist-tags"]);
249
+ s.push(u), t.forEach((k) => {
250
+ const y = o[k];
251
+ y && y[i] && (y[i] = u.newVersion);
252
+ }), n++, await Ae(n, r.length);
212
253
  });
213
- return await Promise.all(r), p(), p(), o;
214
- }, Ie = async ({ update: e, init: t }) => {
215
- if (t)
216
- return Oe();
217
- if (!O(C))
218
- return L("package.json 文件不存在");
219
- O($) && Object.assign(f, JSON.parse(R(v($, T).toString())));
220
- const i = e || f.check, n = v(C, T).toString(), o = JSON.parse(n), s = ["dependencies", "devDependencies", "optionalDependencies"], r = {}, c = JSON.parse(n);
221
- s.forEach((g) => {
222
- o[g] && Object.entries(o[g]).forEach(([d, u]) => {
223
- !f.reject.includes(d) && (r[d] = u);
254
+ return await Promise.all(c), l(), l(), s;
255
+ }, Ge = async ({ update: e }) => {
256
+ if (!b(E))
257
+ return J("package.json 文件不存在");
258
+ const t = e || S.check, o = h(E).toString(), n = JSON.parse(o), s = ["dependencies", "devDependencies", "optionalDependencies"], r = {}, c = JSON.parse(o);
259
+ s.forEach((p) => {
260
+ n[p] && Object.entries(n[p]).forEach(([m, u]) => {
261
+ !S.reject.includes(m) && (r[m] = u);
224
262
  });
225
263
  });
226
- const l = await De(r, s, c);
227
- i && (k(C, JSON.stringify(c, null, 2)), h("文件 package.json 已更新"), p()), Ne(l);
264
+ const i = await Re(r, s, c);
265
+ t && (v(E, JSON.stringify(c, null, 2)), d("文件 package.json 已更新"), l()), qe(i);
266
+ };
267
+ g.command("check").option("-u, --update", "更新 package.json 依赖内容", !1).description("升级 package.json 依赖版本").action(Ge);
268
+ const _e = H(), W = "comment.md", Be = ["package.json", W], [U, q] = Be.map((e) => j(process.cwd(), e)), Ye = () => {
269
+ if (!b(U))
270
+ return J("package.json 文件不存在");
271
+ const e = h(U).toString(), t = JSON.parse(e), o = ["dependencies", "devDependencies", "optionalDependencies"];
272
+ let n = `### 依赖解析
273
+
274
+ `;
275
+ o.forEach((s) => {
276
+ t[s] && (n += `#### ${s}
277
+
278
+ `, Object.keys(t[s]).forEach((r) => {
279
+ n += `- \`${r}\`: ${_e.comment[r] || ""}
280
+ `;
281
+ }), n += `
282
+ `);
283
+ }), n = n.slice(0, -1), v(q, n), l(), d(`${W} 文件创建成功`), l(), l(a.green(`文件目录 ${q}`));
228
284
  };
229
- m.command("check").option("-u, --update", `更新 package.json 依赖内容 或者配置 ${w} 文件`, !1).option("-i, --init", `仅初始化 ${w} 文件,不检查依赖版本`, !1).description("升级 package.json 依赖版本").action(Ie);
230
- m.usage("[commands] [options]").version(G, "-v, --version", "输出版本号").helpOption("-h, --help", "输出所有命令");
231
- m.command("git [描述]").description("简化 Git 提交命令").action(be);
232
- m.command("build[:环境] [描述]").description("简化打包提交命令");
233
- m.command("version<[++]|[@<版本号>]>").description("例如:version++ 或者 version@1.0.0;自动更新 package.json 版本号,自动更新 `README.md` 中的 `version-v<version>-blue` 图标版本");
234
- m.arguments("<cmd> [env]").action((e, t) => {
235
- Se(e, t);
285
+ g.command("comment").description("生成依赖注释文件").action(Ye);
286
+ g.usage("[commands] [options]").version(_, "-v, --version", "输出版本号").helpOption("-h, --help", "输出所有命令");
287
+ g.command("build[:环境] [描述]").description("简化打包提交命令");
288
+ g.command("version<[++]|[@<版本号>]>").description("例如:version++ 或者 version@1.0.0;自动更新 package.json 版本号,自动更新 `README.md` 中的 `version-v<version>-blue` 图标版本");
289
+ g.arguments("<cmd> [env]").action((e, t) => {
290
+ Je(e, t);
236
291
  });
237
- process.argv.length < 3 ? m.help() : m.parse(process.argv);
238
- const j = W({ pkg: x });
239
- if (j.update && j.update.latest !== x.version) {
292
+ process.argv.length < 3 ? g.help() : g.parse(process.argv);
293
+ const x = ce({ pkg: O, updateCheckInterval: 1e3 * 1 });
294
+ if (x.update && x.update.latest !== O.version) {
240
295
  let e = "";
241
- switch (j.update.type) {
296
+ switch (x.update.type) {
242
297
  case "major":
243
298
  e = a.red("{latestVersion}");
244
299
  break;
@@ -249,12 +304,12 @@ if (j.update && j.update.latest !== x.version) {
249
304
  e = a.green("{latestVersion}");
250
305
  break;
251
306
  }
252
- const t = `https://github.com/biaov/${x.name}/compare/v${x.version}...v{latestVersion}`;
253
- j.notify({
307
+ const t = `https://github.com/biaov/${O.name}/compare/v${O.version}...v{latestVersion}`;
308
+ x.notify({
254
309
  defer: !1,
255
310
  isGlobal: !0,
256
311
  message: `有更新 ${a.dim("{currentVersion}")}${a.reset(" → ")}${e}
257
- 运行 ${a.cyan("{updateCommand}")} 命令更新
312
+ 运行 ${a.cyan("{updateCommand}@latest")} 命令更新
258
313
  ${a.dim.underline(t)}`
259
314
  });
260
315
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mine-auto-cli",
3
3
  "private": false,
4
- "version": "2.3.3",
4
+ "version": "2.4.1-beta.0",
5
5
  "exports": "./dist/index.js",
6
6
  "main": "./dist/index.js",
7
7
  "type": "module",
@@ -13,7 +13,7 @@
13
13
  "email": "biaov@qq.com",
14
14
  "url": "https://biaov.cn"
15
15
  },
16
- "description": "一个将多个命令简化成一个命令的项目 😆",
16
+ "description": "一个将多个命令简化成一个命令的工具 😆",
17
17
  "scripts": {},
18
18
  "publishConfig": {
19
19
  "registry": "https://registry.npmjs.org/",
@@ -47,6 +47,7 @@
47
47
  "dependencies": {
48
48
  "chalk": "^5.3.0",
49
49
  "commander": "^12.0.0",
50
+ "js-yaml": "^4.1.0",
50
51
  "log-symbols": "^6.0.0",
51
52
  "ora": "^8.0.1",
52
53
  "pacote": "^18.0.6",