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