mine-auto-cli 2.5.0 → 2.6.2

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.
Files changed (3) hide show
  1. package/README.md +28 -1
  2. package/dist/index.js +265 -215
  3. package/package.json +9 -8
package/README.md CHANGED
@@ -18,6 +18,8 @@
18
18
  - [x] [生成工作目录结构文件](#生成工作目录结构文件)
19
19
  - [x] [检查 `package.json` 依赖版本](#检查-packagejson-依赖版本)
20
20
  - [x] [生成依赖注释文件](#生成依赖注释文件)
21
+ - [x] [更新 `.vscode` 文件](#更新-vscode-文件)
22
+ - [x] [切换 Node 版本](#切换-node-版本)
21
23
 
22
24
  ## 全局安装
23
25
 
@@ -181,6 +183,27 @@ auto comment
181
183
  - `@rollup/rollup-linux-x64-gnu`:
182
184
  ```
183
185
 
186
+ ### 更新 `.vscode` 文件
187
+
188
+ ```sh
189
+ auto vscode-config
190
+ ```
191
+
192
+ ### 切换 Node 版本
193
+
194
+ - 基于 nvm 快速切换 node 版本
195
+ - 当我们运行的项目过多并且版本还不一致时,此命令可以用于快速切换
196
+ - 默认选择第一个版本号
197
+
198
+ ```sh
199
+ # 命令
200
+ auto node [版本号]
201
+ # 切换为 20 开头的版本
202
+ auto node 20
203
+ # 切换为 20.12.1 的版本
204
+ auto node 20.12.1
205
+ ```
206
+
184
207
  ### 技术栈
185
208
 
186
209
  - `Vite` + `TypeScript` + `NodeJs`
@@ -191,15 +214,19 @@ auto comment
191
214
 
192
215
  - `chalk`: 字体颜色
193
216
  - `commander`: 命令
217
+ - `download-git-repo`: 下载 Git 仓库
218
+ - `inquirer`: 用户交互
219
+ - `js-yaml`: 解析 .yml 文件
194
220
  - `log-symbols`: 图标
195
221
  - `ora`: 动画效果
196
- - `semver-utils`: 解析包版本
197
222
  - `pacote`: 包信息请求器
223
+ - `semver-utils`: 解析包版本
198
224
  - `strip-json-comments`: 移除 json 注释
199
225
  - `update-notifier`: 检查更新
200
226
 
201
227
  #### devDependencies
202
228
 
229
+ - `@types/js-yaml`: `js-yaml` 类型
203
230
  - `@types/node`: `node` 类型
204
231
  - `@types/pacote`: `pacote` 类型
205
232
  - `@types/semver-utils`: `semver-utils` 类型
package/dist/index.js CHANGED
@@ -1,319 +1,369 @@
1
- import { program as g } from "commander";
2
- import a from "chalk";
3
- import { readFileSync as y, writeFileSync as b, existsSync as w, readdirSync as te, cpSync as oe, rmSync as ne } from "fs";
4
- import { join as u, resolve as j } from "path";
5
- import G from "log-symbols";
6
- import se from "ora";
7
- import { execSync as re } from "child_process";
8
- import ce from "js-yaml";
9
- import ie from "strip-json-comments";
10
- import ae from "pacote";
11
- import { parseRange as le } from "semver-utils";
12
- import pe from "download-git-repo";
13
- import me from "update-notifier";
14
- const _ = "mine-auto-cli", B = "2.5.0", ge = "./dist/index.js", de = "./dist/index.js", ue = "module", fe = {
1
+ import { program as u } from "commander";
2
+ import l from "chalk";
3
+ import { readFileSync as y, writeFileSync as b, existsSync as j, readdirSync as ce, cpSync as ae, rmSync as le } from "fs";
4
+ import { join as g, resolve as w } from "path";
5
+ import H from "log-symbols";
6
+ import pe from "ora";
7
+ import { execSync as N } from "child_process";
8
+ import me from "js-yaml";
9
+ import de from "strip-json-comments";
10
+ import ue from "pacote";
11
+ import { parseRange as V } from "semver-utils";
12
+ import ge from "download-git-repo";
13
+ import A from "inquirer";
14
+ import fe from "update-notifier";
15
+ const K = "mine-auto-cli", Q = "2.6.2", he = "./dist/index.js", ye = "./dist/index.js", $e = "module", ve = {
15
16
  auto: "bin/mine-auto-cli.js"
16
- }, he = {
17
+ }, be = {
17
18
  name: "biaov",
18
19
  email: "biaov@qq.com",
19
20
  url: "https://biaov.cn"
20
- }, ye = "一个将多个命令简化成一个命令的工具 😆", $e = {
21
+ }, je = "一个将多个命令简化成一个命令的工具 😆", we = {
21
22
  start: "npm run dev",
22
23
  dev: "npm run build -- --watch",
23
24
  build: "vite build",
24
25
  prettier: "prettier --write '**/*.{js,ts,md,json}'",
25
26
  tag: "node scripts/tag"
26
- }, ve = {
27
+ }, Se = {
27
28
  registry: "https://registry.npmjs.org/",
28
29
  "engine-strict": !0,
29
30
  provenance: !0
30
- }, be = {
31
- node: ">=20.12"
32
- }, we = [
31
+ }, ke = {
32
+ node: ">=22.11"
33
+ }, Ce = [
33
34
  "auto",
34
35
  "cli",
35
36
  "vite",
36
37
  "typescript"
37
- ], je = {
38
+ ], xe = {
38
39
  type: "git",
39
40
  url: "git+https://github.com/biaov/mine-auto-cli.git"
40
- }, ke = "https://github.com/biaov/mine-auto-cli.git", Se = {
41
+ }, Oe = "https://github.com/biaov/mine-auto-cli.git", Ne = {
41
42
  url: "https://github.com/biaov/mine-auto-cli/issues"
42
- }, Ce = "ISC", xe = [
43
+ }, Je = "ISC", Pe = [
43
44
  {
44
45
  name: "biaov",
45
46
  email: "biaov@qq.com"
46
47
  }
47
- ], Oe = {
48
- chalk: "^5.3.0",
49
- commander: "^12.1.0",
48
+ ], De = {
49
+ chalk: "^5.4.1",
50
+ commander: "^13.0.0",
50
51
  "download-git-repo": "^3.0.2",
52
+ inquirer: "^12.3.2",
51
53
  "js-yaml": "^4.1.0",
52
- "log-symbols": "^6.0.0",
53
- ora: "^8.0.1",
54
- pacote: "^18.0.6",
54
+ "log-symbols": "^7.0.0",
55
+ ora: "^8.1.1",
56
+ pacote: "^21.0.0",
55
57
  "semver-utils": "^1.1.4",
56
58
  "strip-json-comments": "^5.0.1",
57
- "update-notifier": "^7.1.0"
58
- }, Je = {
59
+ "update-notifier": "^7.3.1"
60
+ }, Ee = {
59
61
  "@types/js-yaml": "^4.0.9",
60
- "@types/node": "^20.14.12",
62
+ "@types/node": "^22.10.6",
61
63
  "@types/pacote": "^11.1.8",
62
64
  "@types/semver-utils": "^1.1.3",
63
65
  "@types/update-notifier": "^6.0.8",
64
- prettier: "^3.3.3",
65
- typescript: "^5.5.4",
66
- vite: "^5.3.4"
66
+ prettier: "^3.4.2",
67
+ typescript: "^5.7.3",
68
+ vite: "^5.4.11"
67
69
  }, O = {
68
- name: _,
70
+ name: K,
69
71
  private: !1,
70
- version: B,
71
- exports: ge,
72
- main: de,
73
- type: ue,
74
- bin: fe,
75
- author: he,
76
- description: ye,
77
- scripts: $e,
78
- publishConfig: ve,
79
- engines: be,
80
- keywords: we,
81
- repository: je,
82
- homepage: ke,
83
- bugs: Se,
84
- license: Ce,
85
- contributors: xe,
86
- dependencies: Oe,
87
- devDependencies: Je
72
+ version: Q,
73
+ exports: he,
74
+ main: ye,
75
+ type: $e,
76
+ bin: ve,
77
+ author: be,
78
+ description: je,
79
+ scripts: we,
80
+ publishConfig: Se,
81
+ engines: ke,
82
+ keywords: Ce,
83
+ repository: xe,
84
+ homepage: Oe,
85
+ bugs: Ne,
86
+ license: Je,
87
+ contributors: Pe,
88
+ dependencies: De,
89
+ devDependencies: Ee
88
90
  }, f = (e) => {
89
- console.log(`${G.success} ${a.green("SUCCESS")} ${e}`);
91
+ console.log(`${H.success} ${l.green("SUCCESS")} ${e}`);
90
92
  }, J = (e) => {
91
- console.log(`${_} ${G.error} ${a.red("ERROR")} ${e}`);
92
- }, l = (e) => {
93
+ console.log(`${K} ${H.error} ${l.red("ERROR")} ${e}`);
94
+ }, a = (e) => {
93
95
  console.log(e ?? "");
94
- }, Y = (e) => {
95
- l(`开始执行 ${a.cyanBright(e)} 命令`);
96
- const t = se({ text: "正在执行命令中...", color: "yellow" });
96
+ }, W = (e) => {
97
+ a(`开始执行 ${l.cyanBright(e)} 命令`);
98
+ const t = pe({ text: "正在执行命令中...", color: "yellow" });
97
99
  t.start();
98
- const n = re(e, { cwd: process.cwd() });
99
- l(n.toString()), t.succeed(`${a.green(e)} 命令执行成功`), l();
100
- }, Ne = (e) => ["git add -A", `git commit -m ${e}`, "git push"], Pe = (e, t) => [`npm run ${e}`, "git add -A", `git commit -m ${t}`, "git push"], De = async (e, t = "打包") => {
101
- l(), l(`${a.yellow(">>")} 开始依次执行命令...`), l(), Pe(e, t).map(Y), f("全部命令执行完成"), l();
102
- }, M = (e) => {
103
- l(), J(`\`${e}\` 命令错误,请检查你的命令`), l(), g.help();
104
- }, L = (e) => {
105
- const t = ["package.json", "README.md"].map((r) => {
106
- const c = u(process.cwd(), r), i = y(c).toString();
107
- return { path: c, content: i };
108
- }), [n, o] = t, s = JSON.parse(n.content);
100
+ const o = N(e, { cwd: process.cwd() });
101
+ a(o.toString()), t.succeed(`${l.green(e)} 命令执行成功`), a();
102
+ }, Ve = (e) => ["git add -A", `git commit -m ${e}`, "git push"], Me = (e, t) => [`npm run ${e}`, "git add -A", `git commit -m ${t}`, "git push"], Ie = async (e, t = "打包") => {
103
+ a(), a(`${l.yellow(">>")} 开始依次执行命令...`), a(), Me(e, t).map(W), f("全部命令执行完成"), a();
104
+ }, F = (e) => {
105
+ a(), J(`\`${e}\` 命令错误,请检查你的命令`), a(), u.help();
106
+ }, R = (e) => {
107
+ const t = ["package.json", "README.md"].map((i) => {
108
+ const r = g(process.cwd(), i), c = y(r).toString();
109
+ return { path: r, content: c };
110
+ }), [o, n] = t, s = JSON.parse(o.content);
109
111
  if (e)
110
112
  s.version = e;
111
113
  else {
112
- const r = s.version.split(".").reduce((c, i, p, m) => c + (p === m.length - 1 ? +i + 1 : `${i}.`), "");
113
- s.version = r;
114
+ const i = s.version.split(".").reduce((r, c, p, m) => r + (p === m.length - 1 ? +c + 1 : `${c}.`), "");
115
+ s.version = i;
114
116
  }
115
- b(n.path, JSON.stringify(s, null, 2)), o.content = o.content.replace(/version\-v.+\-blue/, () => `version-v${s.version}-blue`), b(o.path, o.content);
116
- }, Ee = async (e) => {
117
+ b(o.path, JSON.stringify(s, null, 2)), n.content = n.content.replace(/version\-v.+\-blue/, () => `version-v${s.version}-blue`), b(n.path, n.content);
118
+ }, Le = async (e) => {
117
119
  const t = e.split("version")[1];
118
- if (!t) return M(e);
119
- const n = JSON.parse(y(u(process.cwd(), "package.json")).toString());
120
+ if (!t) return F(e);
121
+ const o = JSON.parse(y(g(process.cwd(), "package.json")).toString());
120
122
  if (t === "++") {
121
- const s = n.version.split(".").reduce((r, c, i, p) => r + (i === p.length - 1 ? +c + 1 : `${c}.`), "");
122
- L(s), l(), f("命令执行完成");
123
+ const s = o.version.split(".").reduce((i, r, c, p) => i + (c === p.length - 1 ? +r + 1 : `${r}.`), "");
124
+ R(s), a(), f("命令执行完成");
123
125
  return;
124
126
  }
125
- const o = t.split("@")[1];
126
- o ? (L(o), l(), f("命令执行完成")) : M(e);
127
- }, Ve = (e, t) => {
128
- if (e.includes("build")) return De(e, t);
129
- if (e.includes("version")) return Ee(e);
130
- J(a.hex("#f56c6c")(`\`auto ${e}${t ? ` ${t}` : ""}\` 命令不存在`)), g.help();
131
- }, v = "https://gitee.com/biaovorg/project-template.git", Me = {
127
+ const n = t.split("@")[1];
128
+ n ? (R(n), a(), f("命令执行完成")) : F(e);
129
+ }, Ae = (e, t) => {
130
+ if (e.includes("build")) return Ie(e, t);
131
+ if (e.includes("version")) return Le(e);
132
+ J(l.hex("#f56c6c")(`\`auto ${e}${t ? ` ${t}` : ""}\` 命令不存在`)), u.help();
133
+ }, v = "https://gitee.com/biaovorg/project-template.git", Fe = {
132
134
  vue: v,
133
135
  react: v,
134
136
  "uni-app": v,
135
137
  electron: v,
136
138
  node: v,
137
139
  "node-simple": v
138
- }, Le = Object.keys(Me);
139
- Le.reduce((e, t, n) => e + (n ? ", " : "") + t, "");
140
+ }, Re = Object.keys(Fe);
141
+ Re.reduce((e, t, o) => e + (o ? ", " : "") + t, "");
140
142
  const h = (e = "jsonc") => `auto-cli.${e}`;
141
- j(import.meta.dirname, "./presetData.json");
142
- const z = (e, t = !1) => {
143
- if (!w(e)) return t ? {} : "";
144
- const n = y(e).toString();
145
- return t ? JSON.parse(ie(n)) : n;
146
- }, Ae = (e) => {
147
- if (!w(e)) return {};
143
+ w(import.meta.dirname, "./presetData.json");
144
+ const X = (e, t = !1) => {
145
+ if (!j(e)) return t ? {} : "";
146
+ const o = y(e).toString();
147
+ return t ? JSON.parse(de(o)) : o;
148
+ }, Te = (e) => {
149
+ if (!j(e)) return {};
148
150
  const t = y(e).toString();
149
151
  try {
150
- return ce.load(t);
152
+ return me.load(t);
151
153
  } catch {
152
154
  return {};
153
155
  }
154
- }, H = (e = !1) => z(j(import.meta.dirname, h()), e), K = () => {
155
- const [e, t] = [h(), h("yml")].map((o) => j(process.cwd(), o)), n = H(!0);
156
+ }, Z = (e = !1) => X(w(import.meta.dirname, h()), e), ee = () => {
157
+ const [e, t] = [h(), h("yml")].map((n) => w(process.cwd(), n)), o = Z(!0);
156
158
  try {
157
- Object.assign(n, Ae(t), z(e, !0));
159
+ Object.assign(o, Te(t), X(e, !0));
158
160
  } catch {
159
161
  }
160
- return n;
161
- }, Ie = (e, t = !1) => {
162
- let n = H(t);
163
- return t && (n = JSON.stringify(n, null, 2)), e.includes(".yml") ? n.trim().split(`
164
- `).slice(1, -1).reduce((o, s) => o + s.trim().replace(/[",]/g, "").replace("// ", "# ") + `
165
- `, "") : n;
166
- }, Fe = ({ yml: e, uncomment: t, force: n }) => {
167
- l();
168
- const o = h(e ? "yml" : "jsonc"), s = j(process.cwd(), o);
169
- if (w(s) && !n) {
170
- l(a.yellow(`${o} 文件已存在`)), l(), l(a.yellow(`文件目录 ${s}`));
162
+ return o;
163
+ }, qe = (e, t = !1) => {
164
+ let o = Z(t);
165
+ return t && (o = JSON.stringify(o, null, 2)), e.includes(".yml") ? o.trim().split(`
166
+ `).slice(1, -1).reduce((n, s) => n + s.trim().replace(/[",]/g, "").replace("// ", "# ") + `
167
+ `, "") : o;
168
+ }, Ue = ({ yml: e, uncomment: t, force: o }) => {
169
+ a();
170
+ const n = h(e ? "yml" : "jsonc"), s = w(process.cwd(), n);
171
+ if (j(s) && !o) {
172
+ a(l.yellow(`${n} 文件已存在`)), a(), a(l.yellow(`文件目录 ${s}`));
171
173
  return;
172
174
  }
173
- b(s, Ie(o, t)), f(`${o} 文件创建成功`), l(), l(a.green(`文件目录 ${s}`));
175
+ b(s, qe(n, t)), f(`${n} 文件创建成功`), a(), a(l.green(`文件目录 ${s}`));
174
176
  };
175
- g.command("init").option("-f, --force", `强制替换 ${h()} 文件内容`, !1).option("-unc, --uncomment", `取消生成 ${h()} 带注释`, !1).option("-y, --yml", `生成 ${h("yml")} 文件`, !1).description("初始化配置文件").action(Fe);
176
- const Re = async (e = "更新代码") => {
177
- l(), l(`${a.yellow(">>")} 开始依次执行命令...`), l(), Ne(e).forEach(Y), f("全部命令执行完成"), l();
177
+ u.command("init").option("-f, --force", `强制替换 ${h()} 文件内容`, !1).option("-unc, --uncomment", `取消生成 ${h()} 带注释`, !1).option("-y, --yml", `生成 ${h("yml")} 文件`, !1).description("初始化配置文件").action(Ue);
178
+ const Ge = async (e = "更新代码") => {
179
+ a(), a(`${l.yellow(">>")} 开始依次执行命令...`), a(), Ve(e).forEach(W), f("全部命令执行完成"), a();
178
180
  };
179
- g.command("git [描述]").description("简化 Git 提交命令").action(Re);
180
- const A = ["dist", "node_modules", ".git", "miniprogram_npm"];
181
- let N = 0, Q = !1, D = !1, W = 20;
182
- const I = ({ prev: e, i: t, index: n, arr: o, curText: s }) => {
183
- const r = Array.from({ length: t }).reduce((m) => m + `${t === 1 && n === o.length - 1 ? "└ " : "│ "} `, ""), c = e + r, i = (r + s).length, p = Array.from({ length: W + N - i }).reduce((m) => `${m}-`, " ");
184
- return !Q && (N = Math.max(N, i)), `${c}${s}${D ? p : ""}
181
+ u.command("git [描述]").description("简化 Git 提交命令").action(Ge);
182
+ const T = ["dist", "node_modules", ".git", "miniprogram_npm"];
183
+ let P = 0, te = !1, M = !1, ne = 20;
184
+ const q = ({ prev: e, i: t, index: o, arr: n, curText: s }) => {
185
+ const i = Array.from({ length: t }).reduce((m) => m + `${t === 1 && o === n.length - 1 ? "└ " : "│ "} `, ""), r = e + i, c = (i + s).length, p = Array.from({ length: ne + P - c }).reduce((m) => `${m}-`, " ");
186
+ return !te && (P = Math.max(P, c)), `${r}${s}${M ? p : ""}
185
187
  `;
186
- }, E = (e, t = 0) => e.reduce((n, o, s, r) => {
187
- let c;
188
- return o.children ? (c = `├── ${o.name}`, I({ prev: n, i: t, index: s, arr: r, curText: c }) + E(o.children, t + 1)) : (c = `${s === r.length - 1 ? "└── " : "├── "}${o.name}`, I({ prev: n, i: t, index: s, arr: r, curText: c }));
189
- }, ""), F = (e) => te(e, { withFileTypes: !0 }).sort((t, n) => +n.isDirectory() - +t.isDirectory()), Te = ({ line: e, name: t }) => {
190
- D = !!e, typeof e == "string" && (W = +e);
191
- const n = process.cwd(), o = u(n, ".gitignore");
192
- if (w(o)) {
193
- const p = y(o).toString().split(`\r
188
+ }, I = (e, t = 0) => e.reduce((o, n, s, i) => {
189
+ let r;
190
+ return n.children ? (r = `├── ${n.name}`, q({ prev: o, i: t, index: s, arr: i, curText: r }) + I(n.children, t + 1)) : (r = `${s === i.length - 1 ? "└── " : "├── "}${n.name}`, q({ prev: o, i: t, index: s, arr: i, curText: r }));
191
+ }, ""), U = (e) => ce(e, { withFileTypes: !0 }).sort((t, o) => +o.isDirectory() - +t.isDirectory()), _e = ({ line: e, name: t }) => {
192
+ M = !!e, typeof e == "string" && (ne = +e);
193
+ const o = process.cwd(), n = g(o, ".gitignore");
194
+ if (j(n)) {
195
+ const p = y(n).toString().split(`\r
194
196
  `);
195
- A.push(...p);
197
+ T.push(...p);
196
198
  }
197
- const s = n.split("\\").at(-1), c = F(n).map((p) => {
199
+ const s = o.split("\\").at(-1), r = U(o).map((p) => {
198
200
  const { name: m } = p, d = { name: m };
199
- return !A.includes(m) && p.isDirectory() && (d.children = F(u(p.path, m)).map(({ name: k }) => ({ name: k }))), d;
200
- }), i = [{ name: s, children: c }];
201
- D && (E(i), Q = !0), b(u(n, `${typeof t == "string" && t || "directory"}.md`), E(i));
201
+ return !T.includes(m) && p.isDirectory() && (d.children = U(g(p.path, m)).map(({ name: S }) => ({ name: S }))), d;
202
+ }), c = [{ name: s, children: r }];
203
+ M && (I(c), te = !0), b(g(o, `${typeof t == "string" && t || "directory"}.md`), I(c));
202
204
  };
203
- g.command("mkdir").option("-l, --line [数量]", "数量", !1).option("-n, --name [文件名称]", "文件名称", !1).option("-d, --depth [深度值]", "深度值", "3").description("生成目录结构文件").action(Te);
204
- const S = K(), [P] = ["package.json"].map((e) => j(process.cwd(), e)), Ue = (e, t) => {
205
- const n = Array.from({ length: t }, (c, i) => i < e ? "=" : " ").join(""), o = ~~(e / t * 100), s = `\r查找进度:[${n}] ${e}/${t} ${o}%\r`, r = e === t ? a.green(s) : a.yellow(s);
206
- process.stdout.write(r);
207
- }, qe = (e, t, n) => {
208
- let o = "latest";
209
- S.resolve.some((r) => {
210
- const c = r.lastIndexOf("@");
211
- if (c <= 0) return !0;
212
- const i = r.slice(0, c), p = r.slice(c + 1);
213
- if (e === i)
214
- return o = p, !0;
205
+ u.command("mkdir").option("-l, --line [数量]", "数量", !1).option("-n, --name [文件名称]", "文件名称", !1).option("-d, --depth [深度值]", "深度值", "3").description("生成目录结构文件").action(_e);
206
+ const k = ee(), [D] = ["package.json"].map((e) => w(process.cwd(), e)), Be = (e, t) => {
207
+ const o = Array.from({ length: t }, (r, c) => c < e ? "=" : " ").join(""), n = ~~(e / t * 100), s = `\r查找进度:[${o}] ${e}/${t} ${n}%\r`, i = e === t ? l.green(s) : l.yellow(s);
208
+ process.stdout.write(i);
209
+ }, Ye = (e, t, o) => {
210
+ let n = "latest";
211
+ k.resolve.some((i) => {
212
+ const r = i.lastIndexOf("@");
213
+ if (r <= 0) return !0;
214
+ const c = i.slice(0, r), p = i.slice(r + 1);
215
+ if (e === c)
216
+ return n = p, !0;
215
217
  });
216
- const s = S.prefix + n[o];
217
- return { name: e, value: t, newVersion: s, tag: o };
218
- }, Ge = (e, t) => Array.from({ length: t - e }, () => " ").join(""), _e = (e, t) => (+!t + 1) * e.length, R = (e) => {
219
- const [{ major: t = 0, minor: n = 0, patch: o = 0, release: s = "" }] = le(e);
220
- return [+t, +n, +o, s];
221
- }, Be = (e, t) => {
222
- const [n, o, s, r] = R(e), [c, i, p, m] = R(t);
223
- return c > n ? a.red(t) : c < n ? !1 : i > o ? `${c}.${a.yellow(i)}.${a.yellow(p)}` : i < o ? !1 : p > s ? `${c}.${i}.${a.green(p)}` : p === s && m && m !== r ? `${c}.${i}.${p}-${a.green(m)}` : !1;
224
- }, Ye = (e) => {
218
+ const s = k.prefix + o[n];
219
+ return { name: e, value: t, newVersion: s, tag: n };
220
+ }, ze = (e, t) => Array.from({ length: t - e }, () => " ").join(""), He = (e, t) => (+!t + 1) * e.length, G = (e) => {
221
+ const [{ major: t = 0, minor: o = 0, patch: n = 0, release: s = "" }] = V(e);
222
+ return [+t, +o, +n, s];
223
+ }, Ke = (e, t) => {
224
+ const [o, n, s, i] = G(e), [r, c, p, m] = G(t);
225
+ return r > o ? l.red(t) : r < o ? !1 : c > n ? `${r}.${l.yellow(c)}.${l.yellow(p)}` : c < n ? !1 : p > s ? `${r}.${c}.${l.green(p)}` : p === s && m && m !== i ? `${r}.${c}.${p}-${l.green(m)}` : !1;
226
+ }, Qe = (e) => {
225
227
  const t = {};
226
- e.forEach((o) => {
227
- Object.entries(o).forEach(([s, r]) => {
228
- t[s] = Math.max(r.length, t[s] ?? 0);
228
+ e.forEach((n) => {
229
+ Object.entries(n).forEach(([s, i]) => {
230
+ t[s] = Math.max(i.length, t[s] ?? 0);
229
231
  });
230
232
  }), e.unshift({ name: "包名", value: "版本", newVersion: "新版本", tag: "标签" });
231
- const n = [];
232
- e.forEach(({ name: o, value: s, newVersion: r, tag: c }, i) => {
233
- const [p, m, d, k] = Object.entries({ name: o, value: s, newVersion: r, tag: c }).map(([C, ee]) => Ge(_e(ee, i), t[C]));
234
- let $ = a.yellow("→"), V = !0;
235
- if (i) {
236
- const C = Be(s, r);
237
- C ? r = C : V = !1;
233
+ const o = [];
234
+ e.forEach(({ name: n, value: s, newVersion: i, tag: r }, c) => {
235
+ const [p, m, d, S] = Object.entries({ name: n, value: s, newVersion: i, tag: r }).map(([C, ie]) => ze(He(ie, c), t[C]));
236
+ let $ = l.yellow("→"), L = !0;
237
+ if (c) {
238
+ const C = Ke(s, i);
239
+ C ? i = C : L = !1;
238
240
  } else
239
- o = a.green(o), s = a.green(s), r = a.green(r), c = a.green(c), $ = " ";
240
- const Z = `${o + p} ${m + s} ${$} ${d + r} ${k + c}`;
241
- V && n.push(Z);
242
- }), n.length > 1 ? n.forEach(l) : f("所有版本已是最新");
243
- }, ze = async (e, t, n) => {
244
- l();
245
- let o = 0;
246
- const s = [], r = Object.entries(e), c = r.map(async ([i, p]) => {
247
- const m = await ae.packument(i, { registry: S.registry }), d = qe(i, p, m["dist-tags"]);
248
- s.push(d), t.forEach((k) => {
249
- const $ = n[k];
250
- $ && $[i] && ($[i] = d.newVersion);
251
- }), o++, await Ue(o, r.length);
241
+ n = l.green(n), s = l.green(s), i = l.green(i), r = l.green(r), $ = " ";
242
+ const re = `${n + p} ${m + s} ${$} ${d + i} ${S + r}`;
243
+ L && o.push(re);
244
+ }), o.length > 1 ? o.forEach(a) : f("所有版本已是最新");
245
+ }, We = async (e, t, o) => {
246
+ a();
247
+ let n = 0;
248
+ const s = [], i = Object.entries(e), r = i.map(async ([c, p]) => {
249
+ const m = await ue.packument(c, { registry: k.registry }), d = Ye(c, p, m["dist-tags"]);
250
+ s.push(d), t.forEach((S) => {
251
+ const $ = o[S];
252
+ $ && $[c] && ($[c] = d.newVersion);
253
+ }), n++, await Be(n, i.length);
252
254
  });
253
- return await Promise.all(c), l(), l(), s;
254
- }, He = async ({ update: e }) => {
255
- if (!w(P)) return J("package.json 文件不存在");
256
- const t = e || S.check, n = y(P).toString(), o = JSON.parse(n), s = ["dependencies", "devDependencies", "optionalDependencies"], r = {}, c = JSON.parse(n);
255
+ return await Promise.all(r), a(), a(), s;
256
+ }, Xe = async ({ update: e }) => {
257
+ if (!j(D)) return J("package.json 文件不存在");
258
+ const t = e || k.check, o = y(D).toString(), n = JSON.parse(o), s = ["dependencies", "devDependencies", "optionalDependencies"], i = {}, r = JSON.parse(o);
257
259
  s.forEach((p) => {
258
- o[p] && Object.entries(o[p]).forEach(([m, d]) => {
259
- !S.reject.includes(m) && (r[m] = d);
260
+ n[p] && Object.entries(n[p]).forEach(([m, d]) => {
261
+ !k.reject.includes(m) && (i[m] = d);
260
262
  });
261
263
  });
262
- const i = await ze(r, s, c);
263
- t ? (b(P, JSON.stringify(c, null, 2)), f("文件 package.json 已更新"), l()) : Ye(i);
264
+ const c = await We(i, s, r);
265
+ t ? (b(D, JSON.stringify(r, null, 2)), f("文件 package.json 已更新"), a()) : Qe(c);
264
266
  };
265
- g.command("check").option("-u, --update", "更新 package.json 依赖内容", !1).description("升级 package.json 依赖版本").action(He);
266
- const Ke = K(), X = "comment.md", Qe = ["package.json", X], [T, U] = Qe.map((e) => j(process.cwd(), e)), We = () => {
267
- if (!w(T)) return J("package.json 文件不存在");
268
- const e = y(T).toString(), t = JSON.parse(e), n = ["dependencies", "devDependencies", "optionalDependencies"];
269
- let o = `### 依赖解析
267
+ u.command("check").option("-u, --update", "更新 package.json 依赖内容", !1).description("升级 package.json 依赖版本").action(Xe);
268
+ const Ze = ee(), oe = "comment.md", et = ["package.json", oe], [_, B] = et.map((e) => w(process.cwd(), e)), tt = () => {
269
+ if (!j(_)) return J("package.json 文件不存在");
270
+ const e = y(_).toString(), t = JSON.parse(e), o = ["dependencies", "devDependencies", "optionalDependencies"];
271
+ let n = `### 依赖解析
270
272
 
271
273
  `;
272
- n.forEach((s) => {
273
- t[s] && (o += `#### ${s}
274
+ o.forEach((s) => {
275
+ t[s] && (n += `#### ${s}
274
276
 
275
- `, Object.keys(t[s]).forEach((r) => {
276
- o += `- \`${r}\`: ${Ke.comment[r] || ""}
277
+ `, Object.keys(t[s]).forEach((i) => {
278
+ n += `- \`${i}\`: ${Ze.comment[i] || ""}
277
279
  `;
278
- }), o += `
280
+ }), n += `
279
281
  `);
280
- }), o = o.slice(0, -1), b(U, o), l(), f(`${X} 文件创建成功`), l(), l(a.green(`文件目录 ${U}`));
282
+ }), n = n.slice(0, -1), b(B, n), a(), f(`${oe} 文件创建成功`), a(), a(l.green(`文件目录 ${B}`));
283
+ };
284
+ u.command("comment").description("生成依赖注释文件").action(tt);
285
+ const Y = { recursive: !0, force: !0 }, nt = () => {
286
+ const e = `${+/* @__PURE__ */ new Date()}`, t = g(process.cwd()), o = g(t, e);
287
+ ge("direct:https://gitee.com/biaovorg/vscode-config.git#master", o, { clone: !0 }, async (n) => {
288
+ !n && ae(g(o, ".vscode"), g(t, ".vscode"), Y), le(o, Y);
289
+ });
281
290
  };
282
- g.command("comment").description("生成依赖注释文件").action(We);
283
- const q = { recursive: !0, force: !0 }, Xe = () => {
284
- const e = `${+/* @__PURE__ */ new Date()}`, t = u(process.cwd()), n = u(t, e);
285
- pe("direct:https://gitee.com/biaovorg/vscode-config.git#master", n, { clone: !0 }, async (o) => {
286
- !o && oe(u(n, ".vscode"), u(t, ".vscode"), q), ne(n, q);
291
+ u.command("vscode-config").description("更新 .vscode 配置文件").action(nt);
292
+ const se = (e, t, o) => {
293
+ const n = Object.entries(t), s = n.findIndex(([c]) => e === c), [i, r] = n[s];
294
+ if (r) {
295
+ if (o[i] === r) return s === n.length - 1 ? !0 : se(n[s + 1][0], t, o);
296
+ } else
297
+ return !0;
298
+ }, z = (e) => {
299
+ e && (N(`nvm use ${e}`), a(), f(`切换成功 当前版本:${e}`), a());
300
+ }, E = (e) => {
301
+ e && N(`nvm install ${e}`);
302
+ }, ot = (e, t) => {
303
+ const o = N("nvm ls").toString(), n = V(o), [{ major: s, minor: i, patch: r }] = V(e), c = [], p = n.find((m) => {
304
+ if (m.major === s)
305
+ return c.push(m), se("minor", { minor: i, patch: r }, m);
287
306
  });
307
+ if (p)
308
+ z(p.semver);
309
+ else if (a(), a(l.red(`输入的版本 ${e} 不存在`)), a(), c.length) {
310
+ const m = c.map((d) => d.semver);
311
+ A.prompt({
312
+ type: "list",
313
+ name: "preset",
314
+ message: "请选择相似版本或输入版本进行安装:",
315
+ choices: [...m, e, "取消"]
316
+ }).then(({ preset: d }) => {
317
+ if (d !== "取消")
318
+ if (d === e) {
319
+ if (!r) return;
320
+ E(d);
321
+ } else
322
+ z(d);
323
+ });
324
+ } else {
325
+ if (!r) return;
326
+ if (t.install) {
327
+ E(e);
328
+ return;
329
+ }
330
+ A.prompt({
331
+ type: "confirm",
332
+ name: "isInstall",
333
+ message: `是否安装 ${e}?`
334
+ }).then(({ isInstall: m }) => {
335
+ m && E(e);
336
+ });
337
+ }
288
338
  };
289
- g.command("vscode-config").description("更新 .vscode 配置文件").action(Xe);
290
- g.usage("[commands] [options]").version(B, "-v, --version", "输出版本号").helpOption("-h, --help", "输出所有命令");
291
- g.command("build[:环境] [描述]").description("简化打包提交命令");
292
- g.command("version<[++]|[@<版本号>]>").description("例如:version++ 或者 version@1.0.0;自动更新 package.json 版本号,自动更新 `README.md` 中的 `version-v<version>-blue` 图标版本");
293
- g.arguments("<cmd> [env]").action((e, t) => {
294
- Ve(e, t);
339
+ u.command("node [版本号]").option("-i, --install", "是否安装此版本", !1).description("切换 node 版本,默认选择第一个版本").action(ot);
340
+ u.usage("[commands] [options]").version(Q, "-v, --version", "输出版本号").helpOption("-h, --help", "输出所有命令");
341
+ u.command("build[:环境] [描述]").description("简化打包提交命令");
342
+ u.command("version<[++]|[@<版本号>]>").description("例如:version++ 或者 version@1.0.0;自动更新 package.json 版本号,自动更新 `README.md` 中的 `version-v<version>-blue` 图标版本");
343
+ u.arguments("<cmd> [env]").action((e, t) => {
344
+ Ae(e, t);
295
345
  });
296
- process.argv.length < 3 ? g.help() : g.parse(process.argv);
297
- const x = me({ pkg: O, updateCheckInterval: 1e3 * 1 });
346
+ process.argv.length < 3 ? u.help() : u.parse(process.argv);
347
+ const x = fe({ pkg: O, updateCheckInterval: 1e3 * 1 });
298
348
  if (x.update && x.update.latest !== O.version) {
299
349
  let e = "";
300
350
  switch (x.update.type) {
301
351
  case "major":
302
- e = a.red("{latestVersion}");
352
+ e = l.red("{latestVersion}");
303
353
  break;
304
354
  case "minor":
305
- e = a.yellow("{latestVersion}");
355
+ e = l.yellow("{latestVersion}");
306
356
  break;
307
357
  default:
308
- e = a.green("{latestVersion}");
358
+ e = l.green("{latestVersion}");
309
359
  break;
310
360
  }
311
361
  const t = `https://github.com/biaov/${O.name}/compare/v${O.version}...v{latestVersion}`;
312
362
  x.notify({
313
363
  defer: !1,
314
364
  isGlobal: !0,
315
- message: `有更新 ${a.dim("{currentVersion}")}${a.reset(" → ")}${e}
316
- 运行 ${a.cyan("{updateCommand}@latest")} 命令更新
317
- ${a.dim.underline(t)}`
365
+ message: `有更新 ${l.dim("{currentVersion}")}${l.reset(" → ")}${e}
366
+ 运行 ${l.cyan("{updateCommand}@latest")} 命令更新
367
+ ${l.dim.underline(t)}`
318
368
  });
319
369
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mine-auto-cli",
3
3
  "private": false,
4
- "version": "2.5.0",
4
+ "version": "2.6.2",
5
5
  "exports": "./dist/index.js",
6
6
  "main": "./dist/index.js",
7
7
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  "provenance": true
22
22
  },
23
23
  "engines": {
24
- "node": ">=20.12"
24
+ "node": ">=22.11"
25
25
  },
26
26
  "keywords": [
27
27
  "auto",
@@ -45,16 +45,17 @@
45
45
  }
46
46
  ],
47
47
  "dependencies": {
48
- "chalk": "^5.3.0",
49
- "commander": "^12.1.0",
48
+ "chalk": "^5.4.1",
49
+ "commander": "^13.0.0",
50
50
  "download-git-repo": "^3.0.2",
51
+ "inquirer": "^12.3.2",
51
52
  "js-yaml": "^4.1.0",
52
- "log-symbols": "^6.0.0",
53
- "ora": "^8.0.1",
54
- "pacote": "^18.0.6",
53
+ "log-symbols": "^7.0.0",
54
+ "ora": "^8.1.1",
55
+ "pacote": "^21.0.0",
55
56
  "semver-utils": "^1.1.4",
56
57
  "strip-json-comments": "^5.0.1",
57
- "update-notifier": "^7.1.0"
58
+ "update-notifier": "^7.3.1"
58
59
  },
59
60
  "devDependencies": {}
60
61
  }