mine-auto-cli 2.3.2 → 2.3.3
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/dist/index.js +77 -77
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -4,22 +4,22 @@ import { program as m } from "commander";
|
|
|
4
4
|
import X from "ora";
|
|
5
5
|
import { execSync as Y } from "child_process";
|
|
6
6
|
import { readFileSync as v, writeFileSync as k, existsSync as O, readdirSync as Z } from "fs";
|
|
7
|
-
import { join as b, resolve as
|
|
8
|
-
import
|
|
7
|
+
import { join as b, resolve as q } from "path";
|
|
8
|
+
import F from "log-symbols";
|
|
9
9
|
import ee from "pacote";
|
|
10
10
|
import R from "strip-json-comments";
|
|
11
|
-
const U = "mine-auto-cli", G = "2.3.
|
|
11
|
+
const U = "mine-auto-cli", G = "2.3.3", te = "./dist/index.js", ne = "./dist/index.js", oe = "module", se = {
|
|
12
12
|
auto: "bin/mine-auto-cli.js"
|
|
13
|
-
},
|
|
13
|
+
}, re = {
|
|
14
14
|
name: "biaov",
|
|
15
15
|
email: "biaov@qq.com",
|
|
16
16
|
url: "https://biaov.cn"
|
|
17
|
-
},
|
|
17
|
+
}, ie = "一个将多个命令简化成一个命令的项目 😆", ce = {
|
|
18
18
|
start: "npm run dev",
|
|
19
19
|
dev: "npm run build -- --watch",
|
|
20
20
|
build: "node scripts/build && vite build",
|
|
21
21
|
prettier: "prettier --write '**/*.{js,ts,md,json}'",
|
|
22
|
-
|
|
22
|
+
tag: "node scripts/tag"
|
|
23
23
|
}, ae = {
|
|
24
24
|
registry: "https://registry.npmjs.org/",
|
|
25
25
|
"engine-strict": !0,
|
|
@@ -34,9 +34,9 @@ const U = "mine-auto-cli", G = "2.3.2", te = "./dist/index.js", ne = "./dist/ind
|
|
|
34
34
|
], ge = {
|
|
35
35
|
type: "git",
|
|
36
36
|
url: "git+https://github.com/biaov/mine-auto-cli.git"
|
|
37
|
-
}, me = "https://github.com/biaov/mine-auto-cli.git",
|
|
37
|
+
}, me = "https://github.com/biaov/mine-auto-cli.git", de = {
|
|
38
38
|
url: "https://github.com/biaov/mine-auto-cli/issues"
|
|
39
|
-
},
|
|
39
|
+
}, ue = "ISC", fe = [
|
|
40
40
|
{
|
|
41
41
|
name: "biaov",
|
|
42
42
|
email: "biaov@qq.com"
|
|
@@ -46,16 +46,16 @@ const U = "mine-auto-cli", G = "2.3.2", te = "./dist/index.js", ne = "./dist/ind
|
|
|
46
46
|
commander: "^12.0.0",
|
|
47
47
|
"log-symbols": "^6.0.0",
|
|
48
48
|
ora: "^8.0.1",
|
|
49
|
-
pacote: "^18.0.
|
|
49
|
+
pacote: "^18.0.6",
|
|
50
50
|
"strip-json-comments": "^5.0.1",
|
|
51
51
|
"update-notifier": "^7.0.0"
|
|
52
52
|
}, ye = {
|
|
53
|
-
"@types/node": "^20.12.
|
|
53
|
+
"@types/node": "^20.12.11",
|
|
54
54
|
"@types/pacote": "^11.1.8",
|
|
55
55
|
"@types/update-notifier": "^6.0.8",
|
|
56
56
|
prettier: "^3.2.5",
|
|
57
57
|
typescript: "^5.4.5",
|
|
58
|
-
vite: "^5.2.
|
|
58
|
+
vite: "^5.2.11"
|
|
59
59
|
}, x = {
|
|
60
60
|
name: U,
|
|
61
61
|
private: !1,
|
|
@@ -64,56 +64,56 @@ const U = "mine-auto-cli", G = "2.3.2", te = "./dist/index.js", ne = "./dist/ind
|
|
|
64
64
|
main: ne,
|
|
65
65
|
type: oe,
|
|
66
66
|
bin: se,
|
|
67
|
-
author:
|
|
68
|
-
description:
|
|
67
|
+
author: re,
|
|
68
|
+
description: ie,
|
|
69
69
|
scripts: ce,
|
|
70
70
|
publishConfig: ae,
|
|
71
71
|
engines: pe,
|
|
72
72
|
keywords: le,
|
|
73
73
|
repository: ge,
|
|
74
74
|
homepage: me,
|
|
75
|
-
bugs:
|
|
76
|
-
license:
|
|
75
|
+
bugs: de,
|
|
76
|
+
license: ue,
|
|
77
77
|
contributors: fe,
|
|
78
78
|
dependencies: he,
|
|
79
79
|
devDependencies: ye
|
|
80
80
|
}, h = (e) => {
|
|
81
|
-
console.log(`${
|
|
82
|
-
},
|
|
83
|
-
console.log(`${U} ${
|
|
81
|
+
console.log(`${F.success} ${a.green("SUCCESS")} ${e}`);
|
|
82
|
+
}, L = (e) => {
|
|
83
|
+
console.log(`${U} ${F.error} ${a.red("ERROR")} ${e}`);
|
|
84
84
|
}, p = (e) => {
|
|
85
85
|
console.log(e ?? "");
|
|
86
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
87
|
p(`开始执行 ${a.cyanBright(e)} 命令`);
|
|
88
88
|
const t = X({ text: "正在执行命令中...", color: "yellow" });
|
|
89
89
|
t.start();
|
|
90
|
-
const
|
|
91
|
-
p(
|
|
90
|
+
const i = Y(e, { cwd: process.cwd() });
|
|
91
|
+
p(i.toString()), t.succeed(`${a.green(e)} 命令执行成功`), p();
|
|
92
92
|
}, be = async (e = "更新代码") => {
|
|
93
93
|
p(), p(`${a.yellow(">>")} 开始依次执行命令...`), p(), $e(e).forEach(_), h("全部命令执行完成"), p();
|
|
94
94
|
}, ke = async (e, t = "打包") => {
|
|
95
95
|
p(), p(`${a.yellow(">>")} 开始依次执行命令...`), p(), ve(e, t).map(_), h("全部命令执行完成"), p();
|
|
96
96
|
}, D = (e) => {
|
|
97
|
-
p(),
|
|
97
|
+
p(), L(`\`${e}\` 命令错误,请检查你的命令`), p(), m.help();
|
|
98
98
|
}, I = (e) => {
|
|
99
99
|
const t = ["package.json", "README.md"].map((s) => {
|
|
100
|
-
const
|
|
101
|
-
return { path:
|
|
102
|
-
}), [
|
|
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);
|
|
103
103
|
if (e)
|
|
104
104
|
o.version = e;
|
|
105
105
|
else {
|
|
106
|
-
const s = o.version.split(".").reduce((
|
|
106
|
+
const s = o.version.split(".").reduce((r, c, l, g) => r + (l === g.length - 1 ? +c + 1 : `${c}.`), "");
|
|
107
107
|
o.version = s;
|
|
108
108
|
}
|
|
109
|
-
k(
|
|
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
110
|
}, we = async (e) => {
|
|
111
111
|
const t = e.split("version")[1];
|
|
112
112
|
if (!t)
|
|
113
113
|
return D(e);
|
|
114
|
-
const
|
|
114
|
+
const i = JSON.parse(v(b(process.cwd(), "package.json"), "utf-8"));
|
|
115
115
|
if (t === "++") {
|
|
116
|
-
const o =
|
|
116
|
+
const o = i.version.split(".").reduce((s, r, c, l) => s + (c === l.length - 1 ? +r + 1 : `${r}.`), "");
|
|
117
117
|
I(o), p(), h("命令执行完成");
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
@@ -124,107 +124,107 @@ const U = "mine-auto-cli", G = "2.3.2", te = "./dist/index.js", ne = "./dist/ind
|
|
|
124
124
|
return ke(e, t);
|
|
125
125
|
if (e.includes("version"))
|
|
126
126
|
return we(e);
|
|
127
|
-
|
|
127
|
+
L(a.hex("#f56c6c")(`\`auto ${e}${t ? ` ${t}` : ""}\` 命令不存在`)), m.help();
|
|
128
128
|
}, A = ["dist", "node_modules", ".git", "miniprogram_npm"];
|
|
129
129
|
let V = 0, B = !1, J = !1, z = 20;
|
|
130
|
-
const P = ({ prev: e, i: t, index:
|
|
131
|
-
const s = Array.from({ length: t }).reduce((g) => g + `${t === 1 &&
|
|
132
|
-
return !B && (V = Math.max(V, c)), `${
|
|
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 : ""}
|
|
133
133
|
`;
|
|
134
|
-
}, E = (e, t = 0) => e.reduce((
|
|
135
|
-
let
|
|
136
|
-
return n.children ? (
|
|
137
|
-
}, ""), M = (e) => Z(e, { withFileTypes: !0 }).sort((t,
|
|
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
138
|
J = !!e, typeof e == "string" && (z = +e);
|
|
139
|
-
const
|
|
139
|
+
const i = process.cwd(), n = b(i, ".gitignore");
|
|
140
140
|
if (O(n)) {
|
|
141
141
|
const l = v(n, { encoding: "utf-8" }).split(`\r
|
|
142
142
|
`);
|
|
143
143
|
A.push(...l);
|
|
144
144
|
}
|
|
145
|
-
const o =
|
|
146
|
-
const { name: g } = l,
|
|
147
|
-
return !A.includes(g) && l.isDirectory() && (
|
|
148
|
-
}), c = [{ name: o, children:
|
|
149
|
-
J && (E(c), B = !0), k(b(
|
|
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));
|
|
150
150
|
};
|
|
151
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(
|
|
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
153
|
if (p(), O($)) {
|
|
154
154
|
p(a.yellow(`${w} 文件已存在`)), p(), p(a.yellow(`文件目录 ${$}`));
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
157
|
k($, H), h(`${w} 文件创建成功`), p(), p(a.green(`文件目录 ${$}`));
|
|
158
158
|
}, Ve = (e, t) => {
|
|
159
|
-
const
|
|
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
160
|
process.stdout.write(s);
|
|
161
|
-
}, Ce = (e, t,
|
|
161
|
+
}, Ce = (e, t, i) => {
|
|
162
162
|
let n = "latest";
|
|
163
163
|
f.resolve.some((s) => {
|
|
164
|
-
const
|
|
165
|
-
if (
|
|
164
|
+
const r = s.lastIndexOf("@");
|
|
165
|
+
if (r <= 0)
|
|
166
166
|
return !0;
|
|
167
|
-
const c = s.slice(0,
|
|
167
|
+
const c = s.slice(0, r), l = s.slice(r + 1);
|
|
168
168
|
if (e === c)
|
|
169
169
|
return n = l, !0;
|
|
170
170
|
});
|
|
171
|
-
const o = f.prefix +
|
|
171
|
+
const o = f.prefix + i[n];
|
|
172
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,
|
|
174
|
-
const
|
|
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
175
|
switch (o) {
|
|
176
176
|
case 0:
|
|
177
177
|
return a.red(t);
|
|
178
178
|
case 1:
|
|
179
179
|
return `${s}.${a.yellow(n[1])}.${a.yellow(n[2])}`;
|
|
180
180
|
default:
|
|
181
|
-
const
|
|
182
|
-
return
|
|
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
183
|
}
|
|
184
|
-
},
|
|
184
|
+
}, Ne = (e) => {
|
|
185
185
|
const t = {};
|
|
186
186
|
e.forEach((n) => {
|
|
187
187
|
Object.entries(n).forEach(([o, s]) => {
|
|
188
188
|
t[o] = Math.max(s.length, t[o] ?? 0);
|
|
189
189
|
});
|
|
190
190
|
}), e.unshift({ name: "包名", value: "版本", newVersion: "新版本", tag: "标签" });
|
|
191
|
-
const
|
|
192
|
-
e.forEach(({ name: n, value: o, newVersion: s, tag:
|
|
193
|
-
const [l, g,
|
|
194
|
-
let y = a.yellow("→"),
|
|
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
195
|
if (c) {
|
|
196
|
-
const S =
|
|
197
|
-
S ? s = S :
|
|
196
|
+
const S = Le(o, s);
|
|
197
|
+
S ? s = S : N = !1;
|
|
198
198
|
} else
|
|
199
|
-
n = a.green(n), o = a.green(o), s = a.green(s),
|
|
200
|
-
const K = `${n + l} ${g + o} ${y} ${
|
|
201
|
-
|
|
202
|
-
}),
|
|
203
|
-
}, De = async (e, t,
|
|
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
204
|
p();
|
|
205
205
|
let n = 0;
|
|
206
|
-
const o = [], s = Object.entries(e),
|
|
207
|
-
const g = await ee.packument(c, { registry: f.registry }),
|
|
208
|
-
o.push(
|
|
209
|
-
const y =
|
|
210
|
-
y && y[c] && (y[c] =
|
|
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
211
|
}), n++, await Ve(n, s.length);
|
|
212
212
|
});
|
|
213
|
-
return await Promise.all(
|
|
213
|
+
return await Promise.all(r), p(), p(), o;
|
|
214
214
|
}, Ie = async ({ update: e, init: t }) => {
|
|
215
215
|
if (t)
|
|
216
216
|
return Oe();
|
|
217
217
|
if (!O(C))
|
|
218
|
-
return
|
|
218
|
+
return L("package.json 文件不存在");
|
|
219
219
|
O($) && Object.assign(f, JSON.parse(R(v($, T).toString())));
|
|
220
|
-
const
|
|
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
221
|
s.forEach((g) => {
|
|
222
|
-
o[g] && Object.entries(o[g]).forEach(([
|
|
223
|
-
!f.reject.includes(
|
|
222
|
+
o[g] && Object.entries(o[g]).forEach(([d, u]) => {
|
|
223
|
+
!f.reject.includes(d) && (r[d] = u);
|
|
224
224
|
});
|
|
225
225
|
});
|
|
226
|
-
const l = await De(
|
|
227
|
-
|
|
226
|
+
const l = await De(r, s, c);
|
|
227
|
+
i && (k(C, JSON.stringify(c, null, 2)), h("文件 package.json 已更新"), p()), Ne(l);
|
|
228
228
|
};
|
|
229
229
|
m.command("check").option("-u, --update", `更新 package.json 依赖内容 或者配置 ${w} 文件`, !1).option("-i, --init", `仅初始化 ${w} 文件,不检查依赖版本`, !1).description("升级 package.json 依赖版本").action(Ie);
|
|
230
230
|
m.usage("[commands] [options]").version(G, "-v, --version", "输出版本号").helpOption("-h, --help", "输出所有命令");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mine-auto-cli",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.3.
|
|
4
|
+
"version": "2.3.3",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"type": "module",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"scripts": {},
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"registry": "https://registry.npmjs.org/",
|
|
20
|
-
"
|
|
20
|
+
"engine-strict": true,
|
|
21
|
+
"provenance": true
|
|
21
22
|
},
|
|
22
23
|
"engines": {
|
|
23
24
|
"node": ">=20.12"
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"commander": "^12.0.0",
|
|
49
50
|
"log-symbols": "^6.0.0",
|
|
50
51
|
"ora": "^8.0.1",
|
|
51
|
-
"pacote": "^18.0.
|
|
52
|
+
"pacote": "^18.0.6",
|
|
52
53
|
"strip-json-comments": "^5.0.1",
|
|
53
54
|
"update-notifier": "^7.0.0"
|
|
54
55
|
},
|