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.
- package/README.md +28 -1
- package/dist/index.js +255 -204
- 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
|
|
2
|
-
import
|
|
3
|
-
import { readFileSync as
|
|
4
|
-
import { join as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { execSync as
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { parseRange as
|
|
12
|
-
import
|
|
13
|
-
|
|
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
|
-
},
|
|
17
|
+
}, be = {
|
|
16
18
|
name: "biaov",
|
|
17
19
|
email: "biaov@qq.com",
|
|
18
20
|
url: "https://biaov.cn"
|
|
19
|
-
},
|
|
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
|
-
},
|
|
27
|
+
}, Se = {
|
|
26
28
|
registry: "https://registry.npmjs.org/",
|
|
27
29
|
"engine-strict": !0,
|
|
28
30
|
provenance: !0
|
|
29
|
-
},
|
|
31
|
+
}, ke = {
|
|
30
32
|
node: ">=20.12"
|
|
31
|
-
},
|
|
33
|
+
}, Ce = [
|
|
32
34
|
"auto",
|
|
33
35
|
"cli",
|
|
34
36
|
"vite",
|
|
35
37
|
"typescript"
|
|
36
|
-
],
|
|
38
|
+
], xe = {
|
|
37
39
|
type: "git",
|
|
38
40
|
url: "git+https://github.com/biaov/mine-auto-cli.git"
|
|
39
|
-
},
|
|
41
|
+
}, Oe = "https://github.com/biaov/mine-auto-cli.git", Ne = {
|
|
40
42
|
url: "https://github.com/biaov/mine-auto-cli/issues"
|
|
41
|
-
},
|
|
43
|
+
}, Je = "ISC", Pe = [
|
|
42
44
|
{
|
|
43
45
|
name: "biaov",
|
|
44
46
|
email: "biaov@qq.com"
|
|
45
47
|
}
|
|
46
|
-
],
|
|
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": "^
|
|
51
|
-
ora: "^8.0
|
|
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.
|
|
56
|
-
},
|
|
59
|
+
"update-notifier": "^7.3.1"
|
|
60
|
+
}, Ee = {
|
|
57
61
|
"@types/js-yaml": "^4.0.9",
|
|
58
|
-
"@types/node": "^
|
|
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.
|
|
63
|
-
typescript: "^5.
|
|
64
|
-
vite: "^5.
|
|
66
|
+
prettier: "^3.3.3",
|
|
67
|
+
typescript: "^5.6.2",
|
|
68
|
+
vite: "^5.4.6"
|
|
65
69
|
}, O = {
|
|
66
|
-
name:
|
|
70
|
+
name: K,
|
|
67
71
|
private: !1,
|
|
68
|
-
version:
|
|
69
|
-
exports:
|
|
70
|
-
main:
|
|
71
|
-
type:
|
|
72
|
-
bin:
|
|
73
|
-
author:
|
|
74
|
-
description:
|
|
75
|
-
scripts:
|
|
76
|
-
publishConfig:
|
|
77
|
-
engines:
|
|
78
|
-
keywords:
|
|
79
|
-
repository:
|
|
80
|
-
homepage:
|
|
81
|
-
bugs:
|
|
82
|
-
license:
|
|
83
|
-
contributors:
|
|
84
|
-
dependencies:
|
|
85
|
-
devDependencies:
|
|
86
|
-
},
|
|
87
|
-
console.log(`${
|
|
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(`${
|
|
90
|
-
},
|
|
93
|
+
console.log(`${K} ${H.error} ${l.red("ERROR")} ${e}`);
|
|
94
|
+
}, a = (e) => {
|
|
91
95
|
console.log(e ?? "");
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
const t =
|
|
96
|
+
}, W = (e) => {
|
|
97
|
+
a(`开始执行 ${l.cyanBright(e)} 命令`);
|
|
98
|
+
const t = pe({ text: "正在执行命令中...", color: "yellow" });
|
|
95
99
|
t.start();
|
|
96
|
-
const o =
|
|
97
|
-
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
},
|
|
103
|
-
const t = ["package.json", "README.md"].map((
|
|
104
|
-
const
|
|
105
|
-
return { path:
|
|
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
|
|
111
|
-
s.version =
|
|
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
|
-
|
|
114
|
-
},
|
|
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
|
-
|
|
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((
|
|
121
|
-
|
|
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 ? (
|
|
126
|
-
},
|
|
127
|
-
if (e.includes("build"))
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
j(
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
|
152
|
+
return me.load(t);
|
|
154
153
|
} catch {
|
|
155
154
|
return {};
|
|
156
155
|
}
|
|
157
|
-
},
|
|
158
|
-
const [e, t] = [
|
|
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,
|
|
159
|
+
Object.assign(o, Te(t), X(e, !0));
|
|
161
160
|
} catch {
|
|
162
161
|
}
|
|
163
162
|
return o;
|
|
164
|
-
},
|
|
165
|
-
let o =
|
|
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
|
-
},
|
|
170
|
-
|
|
171
|
-
const n =
|
|
172
|
-
if (
|
|
173
|
-
l
|
|
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
|
-
|
|
175
|
+
b(s, qe(n, t)), f(`${n} 文件创建成功`), a(), a(l.green(`文件目录 ${s}`));
|
|
177
176
|
};
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
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
|
-
|
|
183
|
-
const
|
|
184
|
-
let
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
return !
|
|
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
|
-
},
|
|
190
|
-
let
|
|
191
|
-
return n.children ? (
|
|
192
|
-
}, ""),
|
|
193
|
-
|
|
194
|
-
const o = process.cwd(), n =
|
|
195
|
-
if (
|
|
196
|
-
const p =
|
|
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
|
-
|
|
197
|
+
T.push(...p);
|
|
199
198
|
}
|
|
200
|
-
const s = o.split("\\").at(-1),
|
|
201
|
-
const { name: m } = p,
|
|
202
|
-
return !
|
|
203
|
-
}), c = [{ name: s, children:
|
|
204
|
-
|
|
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
|
-
|
|
207
|
-
const
|
|
208
|
-
const o = Array.from({ length: t }, (
|
|
209
|
-
process.stdout.write(
|
|
210
|
-
},
|
|
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
|
-
|
|
213
|
-
const
|
|
214
|
-
if (
|
|
215
|
-
|
|
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 =
|
|
218
|
+
const s = k.prefix + o[n];
|
|
221
219
|
return { name: e, value: t, newVersion: s, tag: n };
|
|
222
|
-
},
|
|
223
|
-
const [{ major: t = 0, minor: o = 0, patch: n = 0, release: s = "" }] =
|
|
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
|
-
},
|
|
226
|
-
const [o, n, s,
|
|
227
|
-
return
|
|
228
|
-
},
|
|
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,
|
|
232
|
-
t[s] = Math.max(
|
|
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:
|
|
237
|
-
const [p, m,
|
|
238
|
-
let
|
|
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 =
|
|
241
|
-
C ?
|
|
238
|
+
const C = Ke(s, i);
|
|
239
|
+
C ? i = C : L = !1;
|
|
242
240
|
} else
|
|
243
|
-
n =
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
}), o.length > 1 ? o.forEach(
|
|
247
|
-
},
|
|
248
|
-
|
|
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 = [],
|
|
251
|
-
const m = await
|
|
252
|
-
s.push(
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
}), n++, await
|
|
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(
|
|
258
|
-
},
|
|
259
|
-
if (!
|
|
260
|
-
|
|
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,
|
|
264
|
-
!
|
|
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
|
|
268
|
-
t ? (
|
|
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
|
-
|
|
271
|
-
const
|
|
272
|
-
if (!
|
|
273
|
-
|
|
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((
|
|
282
|
-
n += `- \`${
|
|
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),
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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 ?
|
|
296
|
-
const x =
|
|
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 =
|
|
352
|
+
e = l.red("{latestVersion}");
|
|
302
353
|
break;
|
|
303
354
|
case "minor":
|
|
304
|
-
e =
|
|
355
|
+
e = l.yellow("{latestVersion}");
|
|
305
356
|
break;
|
|
306
357
|
default:
|
|
307
|
-
e =
|
|
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: `有更新 ${
|
|
315
|
-
运行 ${
|
|
316
|
-
${
|
|
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
|
+
"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": "^
|
|
52
|
-
"ora": "^8.0
|
|
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.
|
|
58
|
+
"update-notifier": "^7.3.1"
|
|
57
59
|
},
|
|
58
60
|
"devDependencies": {}
|
|
59
61
|
}
|