mine-auto-cli 2.3.1 → 2.3.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.
- package/dist/index.js +260 -0
- package/package.json +4 -18
- package/.github/workflows/publish.yml +0 -26
- package/.prettierignore +0 -12
- package/.prettierrc +0 -12
- package/.vscode/settings.json +0 -3
- package/assets/check.png +0 -0
- package/scripts/build.js +0 -9
- package/scripts/hooks.js +0 -61
- package/scripts/path.js +0 -15
- package/scripts/rollup-plugin-copy.ts +0 -12
- package/src/commander/actions.ts +0 -127
- package/src/commander/cmds.ts +0 -9
- package/src/commander/commands/check.ts +0 -233
- package/src/commander/commands/index.ts +0 -3
- package/src/commander/commands/mkdir.ts +0 -94
- package/src/commander/index.ts +0 -24
- package/src/commander/types.ts +0 -20
- package/src/config/config.ts +0 -38
- package/src/config/index.ts +0 -19
- package/src/index.ts +0 -29
- package/src/module.d.ts +0 -1
- package/src/types.ts +0 -26
- package/src/utils/functions.ts +0 -56
- package/src/utils/log.ts +0 -24
- package/src/utils/types.ts +0 -10
- package/tsconfig.json +0 -26
- package/vite.config.ts +0 -35
- /package/{src/config → dist}/check.config.jsonc +0 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import W from "update-notifier";
|
|
2
|
+
import a from "chalk";
|
|
3
|
+
import { program as m } from "commander";
|
|
4
|
+
import X from "ora";
|
|
5
|
+
import { execSync as Y } from "child_process";
|
|
6
|
+
import { readFileSync as v, writeFileSync as k, existsSync as O, readdirSync as Z } from "fs";
|
|
7
|
+
import { join as b, resolve as F } from "path";
|
|
8
|
+
import q from "log-symbols";
|
|
9
|
+
import ee from "pacote";
|
|
10
|
+
import R from "strip-json-comments";
|
|
11
|
+
const U = "mine-auto-cli", G = "2.3.2", te = "./dist/index.js", ne = "./dist/index.js", oe = "module", se = {
|
|
12
|
+
auto: "bin/mine-auto-cli.js"
|
|
13
|
+
}, ie = {
|
|
14
|
+
name: "biaov",
|
|
15
|
+
email: "biaov@qq.com",
|
|
16
|
+
url: "https://biaov.cn"
|
|
17
|
+
}, re = "一个将多个命令简化成一个命令的项目 😆", ce = {
|
|
18
|
+
start: "npm run dev",
|
|
19
|
+
dev: "npm run build -- --watch",
|
|
20
|
+
build: "node scripts/build && vite build",
|
|
21
|
+
prettier: "prettier --write '**/*.{js,ts,md,json}'",
|
|
22
|
+
ncu: "ncu --configFileName .ncurc.json && npm i"
|
|
23
|
+
}, ae = {
|
|
24
|
+
registry: "https://registry.npmjs.org/",
|
|
25
|
+
"engine-strict": !0,
|
|
26
|
+
provenance: !0
|
|
27
|
+
}, pe = {
|
|
28
|
+
node: ">=20.12"
|
|
29
|
+
}, le = [
|
|
30
|
+
"auto",
|
|
31
|
+
"cli",
|
|
32
|
+
"vite",
|
|
33
|
+
"typescript"
|
|
34
|
+
], ge = {
|
|
35
|
+
type: "git",
|
|
36
|
+
url: "git+https://github.com/biaov/mine-auto-cli.git"
|
|
37
|
+
}, me = "https://github.com/biaov/mine-auto-cli.git", ue = {
|
|
38
|
+
url: "https://github.com/biaov/mine-auto-cli/issues"
|
|
39
|
+
}, de = "ISC", fe = [
|
|
40
|
+
{
|
|
41
|
+
name: "biaov",
|
|
42
|
+
email: "biaov@qq.com"
|
|
43
|
+
}
|
|
44
|
+
], he = {
|
|
45
|
+
chalk: "^5.3.0",
|
|
46
|
+
commander: "^12.0.0",
|
|
47
|
+
"log-symbols": "^6.0.0",
|
|
48
|
+
ora: "^8.0.1",
|
|
49
|
+
pacote: "^18.0.2",
|
|
50
|
+
"strip-json-comments": "^5.0.1",
|
|
51
|
+
"update-notifier": "^7.0.0"
|
|
52
|
+
}, ye = {
|
|
53
|
+
"@types/node": "^20.12.7",
|
|
54
|
+
"@types/pacote": "^11.1.8",
|
|
55
|
+
"@types/update-notifier": "^6.0.8",
|
|
56
|
+
prettier: "^3.2.5",
|
|
57
|
+
typescript: "^5.4.5",
|
|
58
|
+
vite: "^5.2.10"
|
|
59
|
+
}, x = {
|
|
60
|
+
name: U,
|
|
61
|
+
private: !1,
|
|
62
|
+
version: G,
|
|
63
|
+
exports: te,
|
|
64
|
+
main: ne,
|
|
65
|
+
type: oe,
|
|
66
|
+
bin: se,
|
|
67
|
+
author: ie,
|
|
68
|
+
description: re,
|
|
69
|
+
scripts: ce,
|
|
70
|
+
publishConfig: ae,
|
|
71
|
+
engines: pe,
|
|
72
|
+
keywords: le,
|
|
73
|
+
repository: ge,
|
|
74
|
+
homepage: me,
|
|
75
|
+
bugs: ue,
|
|
76
|
+
license: de,
|
|
77
|
+
contributors: fe,
|
|
78
|
+
dependencies: he,
|
|
79
|
+
devDependencies: ye
|
|
80
|
+
}, h = (e) => {
|
|
81
|
+
console.log(`${q.success} ${a.green("SUCCESS")} ${e}`);
|
|
82
|
+
}, N = (e) => {
|
|
83
|
+
console.log(`${U} ${q.error} ${a.red("ERROR")} ${e}`);
|
|
84
|
+
}, p = (e) => {
|
|
85
|
+
console.log(e ?? "");
|
|
86
|
+
}, $e = (e) => ["git add -A", `git commit -m ${e}`, "git push"], ve = (e, t) => [`npm run ${e}`, "git add -A", `git commit -m ${t}`, "git push"], _ = (e) => {
|
|
87
|
+
p(`开始执行 ${a.cyanBright(e)} 命令`);
|
|
88
|
+
const t = X({ text: "正在执行命令中...", color: "yellow" });
|
|
89
|
+
t.start();
|
|
90
|
+
const r = Y(e, { cwd: process.cwd() });
|
|
91
|
+
p(r.toString()), t.succeed(`${a.green(e)} 命令执行成功`), p();
|
|
92
|
+
}, be = async (e = "更新代码") => {
|
|
93
|
+
p(), p(`${a.yellow(">>")} 开始依次执行命令...`), p(), $e(e).forEach(_), h("全部命令执行完成"), p();
|
|
94
|
+
}, ke = async (e, t = "打包") => {
|
|
95
|
+
p(), p(`${a.yellow(">>")} 开始依次执行命令...`), p(), ve(e, t).map(_), h("全部命令执行完成"), p();
|
|
96
|
+
}, D = (e) => {
|
|
97
|
+
p(), N(`\`${e}\` 命令错误,请检查你的命令`), p(), m.help();
|
|
98
|
+
}, I = (e) => {
|
|
99
|
+
const t = ["package.json", "README.md"].map((s) => {
|
|
100
|
+
const i = b(process.cwd(), s), c = v(i).toString();
|
|
101
|
+
return { path: i, content: c };
|
|
102
|
+
}), [r, n] = t, o = JSON.parse(r.content);
|
|
103
|
+
if (e)
|
|
104
|
+
o.version = e;
|
|
105
|
+
else {
|
|
106
|
+
const s = o.version.split(".").reduce((i, c, l, g) => i + (l === g.length - 1 ? +c + 1 : `${c}.`), "");
|
|
107
|
+
o.version = s;
|
|
108
|
+
}
|
|
109
|
+
k(r.path, JSON.stringify(o, null, 2)), n.content = n.content.replace(/version\-v.+\-blue/, () => `version-v${o.version}-blue`), k(n.path, n.content);
|
|
110
|
+
}, we = async (e) => {
|
|
111
|
+
const t = e.split("version")[1];
|
|
112
|
+
if (!t)
|
|
113
|
+
return D(e);
|
|
114
|
+
const r = JSON.parse(v(b(process.cwd(), "package.json"), "utf-8"));
|
|
115
|
+
if (t === "++") {
|
|
116
|
+
const o = r.version.split(".").reduce((s, i, c, l) => s + (c === l.length - 1 ? +i + 1 : `${i}.`), "");
|
|
117
|
+
I(o), p(), h("命令执行完成");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const n = t.split("@")[1];
|
|
121
|
+
n ? (I(n), p(), h("命令执行完成")) : D(e);
|
|
122
|
+
}, Se = (e, t) => {
|
|
123
|
+
if (e.includes("build"))
|
|
124
|
+
return ke(e, t);
|
|
125
|
+
if (e.includes("version"))
|
|
126
|
+
return we(e);
|
|
127
|
+
N(a.hex("#f56c6c")(`\`auto ${e}${t ? ` ${t}` : ""}\` 命令不存在`)), m.help();
|
|
128
|
+
}, A = ["dist", "node_modules", ".git", "miniprogram_npm"];
|
|
129
|
+
let V = 0, B = !1, J = !1, z = 20;
|
|
130
|
+
const P = ({ prev: e, i: t, index: r, arr: n, curText: o }) => {
|
|
131
|
+
const s = Array.from({ length: t }).reduce((g) => g + `${t === 1 && r === n.length - 1 ? "└ " : "│ "} `, ""), i = e + s, c = (s + o).length, l = Array.from({ length: z + V - c }).reduce((g) => `${g}-`, " ");
|
|
132
|
+
return !B && (V = Math.max(V, c)), `${i}${o}${J ? l : ""}
|
|
133
|
+
`;
|
|
134
|
+
}, E = (e, t = 0) => e.reduce((r, n, o, s) => {
|
|
135
|
+
let i;
|
|
136
|
+
return n.children ? (i = `├── ${n.name}`, P({ prev: r, i: t, index: o, arr: s, curText: i }) + E(n.children, t + 1)) : (i = `${o === s.length - 1 ? "└── " : "├── "}${n.name}`, P({ prev: r, i: t, index: o, arr: s, curText: i }));
|
|
137
|
+
}, ""), M = (e) => Z(e, { withFileTypes: !0 }).sort((t, r) => +r.isDirectory() - +t.isDirectory()), je = ({ line: e, name: t }) => {
|
|
138
|
+
J = !!e, typeof e == "string" && (z = +e);
|
|
139
|
+
const r = process.cwd(), n = b(r, ".gitignore");
|
|
140
|
+
if (O(n)) {
|
|
141
|
+
const l = v(n, { encoding: "utf-8" }).split(`\r
|
|
142
|
+
`);
|
|
143
|
+
A.push(...l);
|
|
144
|
+
}
|
|
145
|
+
const o = r.split("\\").at(-1), i = M(r).map((l) => {
|
|
146
|
+
const { name: g } = l, u = { name: g };
|
|
147
|
+
return !A.includes(g) && l.isDirectory() && (u.children = M(b(l.path, g)).map(({ name: d }) => ({ name: d }))), u;
|
|
148
|
+
}), c = [{ name: o, children: i }];
|
|
149
|
+
J && (E(c), B = !0), k(b(r, `${typeof t == "string" && t || "directory"}.md`), E(c));
|
|
150
|
+
};
|
|
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(F(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) => F(process.cwd(), e)), Oe = () => {
|
|
153
|
+
if (p(), O($)) {
|
|
154
|
+
p(a.yellow(`${w} 文件已存在`)), p(), p(a.yellow(`文件目录 ${$}`));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
k($, H), h(`${w} 文件创建成功`), p(), p(a.green(`文件目录 ${$}`));
|
|
158
|
+
}, Ve = (e, t) => {
|
|
159
|
+
const r = Array.from({ length: t }, (i, c) => c < e ? "=" : " ").join(""), n = ~~(e / t * 100), o = `\r查找进度:[${r}] ${e}/${t} ${n}%\r`, s = e === t ? a.green(o) : a.yellow(o);
|
|
160
|
+
process.stdout.write(s);
|
|
161
|
+
}, Ce = (e, t, r) => {
|
|
162
|
+
let n = "latest";
|
|
163
|
+
f.resolve.some((s) => {
|
|
164
|
+
const i = s.lastIndexOf("@");
|
|
165
|
+
if (i <= 0)
|
|
166
|
+
return !0;
|
|
167
|
+
const c = s.slice(0, i), l = s.slice(i + 1);
|
|
168
|
+
if (e === c)
|
|
169
|
+
return n = l, !0;
|
|
170
|
+
});
|
|
171
|
+
const o = f.prefix + r[n];
|
|
172
|
+
return { name: e, value: t, newVersion: o, tag: n };
|
|
173
|
+
}, Je = (e, t) => Array.from({ length: t - e }, () => " ").join(""), Ee = (e, t) => (+!t + 1) * e.length, Ne = (e, t) => {
|
|
174
|
+
const r = e.match(/\d.+/g)[0].split("."), n = t.match(/\d.+/g)[0].split("."), o = n.slice(0, -1).findIndex((i, c) => +i > +r[c]), s = f.prefix + n[0];
|
|
175
|
+
switch (o) {
|
|
176
|
+
case 0:
|
|
177
|
+
return a.red(t);
|
|
178
|
+
case 1:
|
|
179
|
+
return `${s}.${a.yellow(n[1])}.${a.yellow(n[2])}`;
|
|
180
|
+
default:
|
|
181
|
+
const i = r.at(-1), c = n.at(-1);
|
|
182
|
+
return i !== c && parseInt(c) >= parseInt(i) ? `${s}.${n[1]}.${a.green(n[2])}` : !1;
|
|
183
|
+
}
|
|
184
|
+
}, Le = (e) => {
|
|
185
|
+
const t = {};
|
|
186
|
+
e.forEach((n) => {
|
|
187
|
+
Object.entries(n).forEach(([o, s]) => {
|
|
188
|
+
t[o] = Math.max(s.length, t[o] ?? 0);
|
|
189
|
+
});
|
|
190
|
+
}), e.unshift({ name: "包名", value: "版本", newVersion: "新版本", tag: "标签" });
|
|
191
|
+
const r = [];
|
|
192
|
+
e.forEach(({ name: n, value: o, newVersion: s, tag: i }, c) => {
|
|
193
|
+
const [l, g, u, d] = Object.entries({ name: n, value: o, newVersion: s, tag: i }).map(([S, Q]) => Je(Ee(Q, c), t[S]));
|
|
194
|
+
let y = a.yellow("→"), L = !0;
|
|
195
|
+
if (c) {
|
|
196
|
+
const S = Ne(o, s);
|
|
197
|
+
S ? s = S : L = !1;
|
|
198
|
+
} else
|
|
199
|
+
n = a.green(n), o = a.green(o), s = a.green(s), i = a.green(i), y = " ";
|
|
200
|
+
const K = `${n + l} ${g + o} ${y} ${u + s} ${d + i}`;
|
|
201
|
+
L && r.push(K);
|
|
202
|
+
}), r.length > 1 ? r.forEach(p) : h("所有版本已是最新");
|
|
203
|
+
}, De = async (e, t, r) => {
|
|
204
|
+
p();
|
|
205
|
+
let n = 0;
|
|
206
|
+
const o = [], s = Object.entries(e), i = s.map(async ([c, l]) => {
|
|
207
|
+
const g = await ee.packument(c, { registry: f.registry }), u = Ce(c, l, g["dist-tags"]);
|
|
208
|
+
o.push(u), t.forEach((d) => {
|
|
209
|
+
const y = r[d];
|
|
210
|
+
y && y[c] && (y[c] = u.newVersion);
|
|
211
|
+
}), n++, await Ve(n, s.length);
|
|
212
|
+
});
|
|
213
|
+
return await Promise.all(i), p(), p(), o;
|
|
214
|
+
}, Ie = async ({ update: e, init: t }) => {
|
|
215
|
+
if (t)
|
|
216
|
+
return Oe();
|
|
217
|
+
if (!O(C))
|
|
218
|
+
return N("package.json 文件不存在");
|
|
219
|
+
O($) && Object.assign(f, JSON.parse(R(v($, T).toString())));
|
|
220
|
+
const r = e || f.check, n = v(C, T).toString(), o = JSON.parse(n), s = ["dependencies", "devDependencies", "optionalDependencies"], i = {}, c = JSON.parse(n);
|
|
221
|
+
s.forEach((g) => {
|
|
222
|
+
o[g] && Object.entries(o[g]).forEach(([u, d]) => {
|
|
223
|
+
!f.reject.includes(u) && (i[u] = d);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
const l = await De(i, s, c);
|
|
227
|
+
r && (k(C, JSON.stringify(c, null, 2)), h("文件 package.json 已更新"), p()), Le(l);
|
|
228
|
+
};
|
|
229
|
+
m.command("check").option("-u, --update", `更新 package.json 依赖内容 或者配置 ${w} 文件`, !1).option("-i, --init", `仅初始化 ${w} 文件,不检查依赖版本`, !1).description("升级 package.json 依赖版本").action(Ie);
|
|
230
|
+
m.usage("[commands] [options]").version(G, "-v, --version", "输出版本号").helpOption("-h, --help", "输出所有命令");
|
|
231
|
+
m.command("git [描述]").description("简化 Git 提交命令").action(be);
|
|
232
|
+
m.command("build[:环境] [描述]").description("简化打包提交命令");
|
|
233
|
+
m.command("version<[++]|[@<版本号>]>").description("例如:version++ 或者 version@1.0.0;自动更新 package.json 版本号,自动更新 `README.md` 中的 `version-v<version>-blue` 图标版本");
|
|
234
|
+
m.arguments("<cmd> [env]").action((e, t) => {
|
|
235
|
+
Se(e, t);
|
|
236
|
+
});
|
|
237
|
+
process.argv.length < 3 ? m.help() : m.parse(process.argv);
|
|
238
|
+
const j = W({ pkg: x });
|
|
239
|
+
if (j.update && j.update.latest !== x.version) {
|
|
240
|
+
let e = "";
|
|
241
|
+
switch (j.update.type) {
|
|
242
|
+
case "major":
|
|
243
|
+
e = a.red("{latestVersion}");
|
|
244
|
+
break;
|
|
245
|
+
case "minor":
|
|
246
|
+
e = a.yellow("{latestVersion}");
|
|
247
|
+
break;
|
|
248
|
+
default:
|
|
249
|
+
e = a.green("{latestVersion}");
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
const t = `https://github.com/biaov/${x.name}/compare/v${x.version}...v{latestVersion}`;
|
|
253
|
+
j.notify({
|
|
254
|
+
defer: !1,
|
|
255
|
+
isGlobal: !0,
|
|
256
|
+
message: `有更新 ${a.dim("{currentVersion}")}${a.reset(" → ")}${e}
|
|
257
|
+
运行 ${a.cyan("{updateCommand}")} 命令更新
|
|
258
|
+
${a.dim.underline(t)}`
|
|
259
|
+
});
|
|
260
|
+
}
|
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.2",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"type": "module",
|
|
@@ -14,17 +14,10 @@
|
|
|
14
14
|
"url": "https://biaov.cn"
|
|
15
15
|
},
|
|
16
16
|
"description": "一个将多个命令简化成一个命令的项目 😆",
|
|
17
|
-
"scripts": {
|
|
18
|
-
"start": "npm run dev",
|
|
19
|
-
"dev": "npm run build -- --watch",
|
|
20
|
-
"build": "node scripts/build && vite build",
|
|
21
|
-
"prettier": "prettier --write '**/*.{js,ts,md,json}'",
|
|
22
|
-
"ncu": "ncu --configFileName .ncurc.json && npm i"
|
|
23
|
-
},
|
|
17
|
+
"scripts": {},
|
|
24
18
|
"publishConfig": {
|
|
25
19
|
"registry": "https://registry.npmjs.org/",
|
|
26
|
-
"
|
|
27
|
-
"provenance": true
|
|
20
|
+
"provenance": false
|
|
28
21
|
},
|
|
29
22
|
"engines": {
|
|
30
23
|
"node": ">=20.12"
|
|
@@ -59,12 +52,5 @@
|
|
|
59
52
|
"strip-json-comments": "^5.0.1",
|
|
60
53
|
"update-notifier": "^7.0.0"
|
|
61
54
|
},
|
|
62
|
-
"devDependencies": {
|
|
63
|
-
"@types/node": "^20.12.7",
|
|
64
|
-
"@types/pacote": "^11.1.8",
|
|
65
|
-
"@types/update-notifier": "^6.0.8",
|
|
66
|
-
"prettier": "^3.2.5",
|
|
67
|
-
"typescript": "^5.4.5",
|
|
68
|
-
"vite": "^5.2.10"
|
|
69
|
-
}
|
|
55
|
+
"devDependencies": {}
|
|
70
56
|
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
name: Publish Package to npmjs
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
tags:
|
|
6
|
-
- 'v*'
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
build:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
permissions:
|
|
12
|
-
contents: read
|
|
13
|
-
id-token: write
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v4
|
|
16
|
-
- uses: actions/setup-node@v4
|
|
17
|
-
with:
|
|
18
|
-
node-version: '20.x'
|
|
19
|
-
registry-url: 'https://registry.npmjs.org'
|
|
20
|
-
- run: npm install -g npm
|
|
21
|
-
- run: npm ci
|
|
22
|
-
- run: npm run build
|
|
23
|
-
- run: cd dist
|
|
24
|
-
- run: npm publish
|
|
25
|
-
env:
|
|
26
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/.vscode/settings.json
DELETED
package/assets/check.png
DELETED
|
Binary file
|
package/scripts/build.js
DELETED
package/scripts/hooks.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { writeFileSync, copyFileSync, existsSync, readdirSync, mkdirSync, statSync, unlinkSync } from 'fs'
|
|
2
|
-
import { join } from 'path'
|
|
3
|
-
import { resetPath } from './path.js'
|
|
4
|
-
import packageJson from '../package.json' assert { type: 'json' }
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 重写 package.json
|
|
8
|
-
*/
|
|
9
|
-
export const rewritePackage = () => {
|
|
10
|
-
/**
|
|
11
|
-
* 重置输出目录
|
|
12
|
-
*/
|
|
13
|
-
const output = resetPath('@/dist')
|
|
14
|
-
!existsSync(output) && mkdirSync(output)
|
|
15
|
-
|
|
16
|
-
packageJson.devDependencies = packageJson.scripts = {}
|
|
17
|
-
/**
|
|
18
|
-
* 写入最新的
|
|
19
|
-
*/
|
|
20
|
-
writeFileSync(resetPath('@/dist/package.json'), JSON.stringify(packageJson, null, 2))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 拷贝目录
|
|
25
|
-
*/
|
|
26
|
-
const copyDirectory = (source, destination) => {
|
|
27
|
-
const stat = statSync(source)
|
|
28
|
-
if (stat.isFile()) {
|
|
29
|
-
/**
|
|
30
|
-
* 复制文件
|
|
31
|
-
*/
|
|
32
|
-
existsSync(destination) && unlinkSync(destination)
|
|
33
|
-
copyFileSync(source, destination)
|
|
34
|
-
} else if (stat.isDirectory()) {
|
|
35
|
-
/**
|
|
36
|
-
* 创建目录
|
|
37
|
-
*/
|
|
38
|
-
!existsSync(destination) && mkdirSync(destination)
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 原有目录
|
|
42
|
-
*/
|
|
43
|
-
const directory = readdirSync(source)
|
|
44
|
-
directory.forEach(file => {
|
|
45
|
-
copyDirectory(join(source, file), join(destination, file))
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 复制资源
|
|
52
|
-
*/
|
|
53
|
-
export const copyAssets = () => {
|
|
54
|
-
/**
|
|
55
|
-
* 根目录需要复制的文件和目录
|
|
56
|
-
*/
|
|
57
|
-
const filePaths = ['bin', 'README.md', 'LICENSE']
|
|
58
|
-
filePaths.forEach(path => {
|
|
59
|
-
copyDirectory(resetPath(`@/${path}`), resetPath(`@/dist/${path}`))
|
|
60
|
-
})
|
|
61
|
-
}
|
package/scripts/path.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { resolve, dirname } from 'path'
|
|
2
|
-
import { fileURLToPath } from 'url'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 相对目录
|
|
6
|
-
*/
|
|
7
|
-
export const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 重置路径, @ 表示根目录
|
|
11
|
-
*/
|
|
12
|
-
export const resetPath = (filePath, defaultPrefix = '../') => {
|
|
13
|
-
const prefix = filePath.slice(0, 1) === '@' ? defaultPrefix : ''
|
|
14
|
-
return resolve(__dirname, prefix + filePath.slice(1))
|
|
15
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { copyFileSync } from 'fs'
|
|
2
|
-
|
|
3
|
-
const fileName = 'check.config.jsonc'
|
|
4
|
-
const inputPath = `./src/config/${fileName}`
|
|
5
|
-
const outputPath = `./dist/dist/${fileName}`
|
|
6
|
-
|
|
7
|
-
export default () => ({
|
|
8
|
-
name: 'rollup-plugin-copy',
|
|
9
|
-
closeBundle: () => {
|
|
10
|
-
copyFileSync(inputPath, outputPath)
|
|
11
|
-
}
|
|
12
|
-
})
|
package/src/commander/actions.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { program } from 'commander'
|
|
2
|
-
import chalk from 'chalk'
|
|
3
|
-
import ora from 'ora'
|
|
4
|
-
import { execSync } from 'child_process'
|
|
5
|
-
import { readFileSync, writeFileSync } from 'fs'
|
|
6
|
-
import { join } from 'path'
|
|
7
|
-
import { success, info, error } from '@/utils/log'
|
|
8
|
-
import { gitCmds, buildCmds } from './cmds'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 执行命令
|
|
12
|
-
*/
|
|
13
|
-
const execCommand = (cmd: string) => {
|
|
14
|
-
info(`开始执行 ${chalk.cyanBright(cmd)} 命令`)
|
|
15
|
-
const spinner = ora({ text: '正在执行命令中...', color: 'yellow' })
|
|
16
|
-
spinner.start()
|
|
17
|
-
const childProcess = execSync(cmd, { cwd: process.cwd() })
|
|
18
|
-
info(childProcess.toString())
|
|
19
|
-
spinner.succeed(`${chalk.green(cmd)} 命令执行成功`)
|
|
20
|
-
info()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 简化 Git 提交命令
|
|
25
|
-
*/
|
|
26
|
-
export const simplifyGit = async (desc = '更新代码') => {
|
|
27
|
-
info()
|
|
28
|
-
info(`${chalk.yellow('>>')} 开始依次执行命令...`)
|
|
29
|
-
info()
|
|
30
|
-
gitCmds(desc).forEach(execCommand)
|
|
31
|
-
success('全部命令执行完成')
|
|
32
|
-
info()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 简化打包提交命令
|
|
37
|
-
*/
|
|
38
|
-
export const simplifyBuild = async (cmd: string, desc = '打包') => {
|
|
39
|
-
info()
|
|
40
|
-
info(`${chalk.yellow('>>')} 开始依次执行命令...`)
|
|
41
|
-
info()
|
|
42
|
-
buildCmds(cmd, desc).map(execCommand)
|
|
43
|
-
success('全部命令执行完成')
|
|
44
|
-
info()
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const errorTips = (cmd: string) => {
|
|
48
|
-
info()
|
|
49
|
-
error(`\`${cmd}\` 命令错误,请检查你的命令`)
|
|
50
|
-
info()
|
|
51
|
-
program.help()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 更新版本号
|
|
56
|
-
*/
|
|
57
|
-
const updateVersion = (customVersion: string) => {
|
|
58
|
-
const fileList: Record<string, string>[] = ['package.json', 'README.md'].map(name => {
|
|
59
|
-
const path = join(process.cwd(), name)
|
|
60
|
-
const content = readFileSync(path).toString()
|
|
61
|
-
return { path, content }
|
|
62
|
-
})
|
|
63
|
-
const [packageJsonItem, readmeItem] = fileList
|
|
64
|
-
const packageJson = JSON.parse(packageJsonItem.content)
|
|
65
|
-
|
|
66
|
-
// 修改 package.json
|
|
67
|
-
if (customVersion) {
|
|
68
|
-
packageJson.version = customVersion
|
|
69
|
-
} else {
|
|
70
|
-
const newVersion = packageJson.version.split('.').reduce((prev: string, item: string, i: number, arr: string[]) => prev + (i === arr.length - 1 ? +item + 1 : `${item}.`), '')
|
|
71
|
-
packageJson.version = newVersion
|
|
72
|
-
}
|
|
73
|
-
writeFileSync(packageJsonItem.path, JSON.stringify(packageJson, null, 2))
|
|
74
|
-
|
|
75
|
-
// 修改 README.md
|
|
76
|
-
readmeItem.content = readmeItem.content.replace(/version\-v.+\-blue/, () => `version-v${packageJson.version}-blue`)
|
|
77
|
-
writeFileSync(readmeItem.path, readmeItem.content)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 简化手动修改版本号命令
|
|
82
|
-
*/
|
|
83
|
-
export const simplifyVersion = async (cmd: string) => {
|
|
84
|
-
const arg = cmd.split('version')[1]
|
|
85
|
-
if (!arg) return errorTips(cmd)
|
|
86
|
-
|
|
87
|
-
const packageJson = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf-8'))
|
|
88
|
-
if (arg === '++') {
|
|
89
|
-
const newVersion = packageJson.version.split('.').reduce((prev: string, item: string, i: number, arr: string[]) => prev + (i === arr.length - 1 ? +item + 1 : `${item}.`), '')
|
|
90
|
-
updateVersion(newVersion)
|
|
91
|
-
info()
|
|
92
|
-
success('命令执行完成')
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
const customVersion = arg.split('@')[1]
|
|
96
|
-
if (customVersion) {
|
|
97
|
-
updateVersion(customVersion)
|
|
98
|
-
info()
|
|
99
|
-
success('命令执行完成')
|
|
100
|
-
} else {
|
|
101
|
-
errorTips(cmd)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* 定义顶级命令的 action
|
|
107
|
-
*/
|
|
108
|
-
export const handleArguments = (cmd: string, env?: string) => {
|
|
109
|
-
/**
|
|
110
|
-
* 处理 build[:环境] 命令
|
|
111
|
-
*/
|
|
112
|
-
if (cmd.includes('build')) return simplifyBuild(cmd, env)
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* 处理 version[++][@<版本> 命令
|
|
116
|
-
*/
|
|
117
|
-
if (cmd.includes('version')) return simplifyVersion(cmd)
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* 输出错误
|
|
121
|
-
*/
|
|
122
|
-
error(chalk.hex('#f56c6c')(`\`auto ${cmd}${env ? ` ${env}` : ''}\` 命令不存在`))
|
|
123
|
-
/**
|
|
124
|
-
* 显示全部命令
|
|
125
|
-
*/
|
|
126
|
-
program.help()
|
|
127
|
-
}
|
package/src/commander/cmds.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* git 命令集合
|
|
3
|
-
*/
|
|
4
|
-
export const gitCmds = (desc: string) => ['git add -A', `git commit -m ${desc}`, 'git push']
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 打包的命令
|
|
8
|
-
*/
|
|
9
|
-
export const buildCmds = (suffix: string, desc: string) => [`npm run ${suffix}`, 'git add -A', `git commit -m ${desc}`, 'git push']
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { program } from 'commander'
|
|
2
|
-
import { readFileSync, existsSync, writeFileSync } from 'fs'
|
|
3
|
-
import { resolve } from 'path'
|
|
4
|
-
import chalk from 'chalk'
|
|
5
|
-
import pacote from 'pacote'
|
|
6
|
-
import stripJsonComments from 'strip-json-comments'
|
|
7
|
-
import { success, error, info } from '@/utils/log'
|
|
8
|
-
import type { NPMResponse } from '@/types'
|
|
9
|
-
import type { DefaultConfig, VersionLog } from '../types'
|
|
10
|
-
|
|
11
|
-
const fileOption: Record<string, string> = { encoding: 'utf-8' }
|
|
12
|
-
|
|
13
|
-
const checkConfigDefault = readFileSync(resolve(import.meta.dirname, './check.config.jsonc')).toString()
|
|
14
|
-
const defaultConfig: DefaultConfig = JSON.parse(stripJsonComments(checkConfigDefault.toString()))
|
|
15
|
-
const checkConfigName = 'check.config.jsonc'
|
|
16
|
-
const jsonFiles = [checkConfigName, 'package.json']
|
|
17
|
-
const [checkConfigPath, packagePath] = jsonFiles.map(name => resolve(process.cwd(), name))
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 初始化
|
|
21
|
-
*/
|
|
22
|
-
const initConfigJson = () => {
|
|
23
|
-
info()
|
|
24
|
-
if (existsSync(checkConfigPath)) {
|
|
25
|
-
info(chalk.yellow(`${checkConfigName} 文件已存在`))
|
|
26
|
-
info()
|
|
27
|
-
info(chalk.yellow(`文件目录 ${checkConfigPath}`))
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
writeFileSync(checkConfigPath, checkConfigDefault)
|
|
31
|
-
success(`${checkConfigName} 文件创建成功`)
|
|
32
|
-
info()
|
|
33
|
-
info(chalk.green(`文件目录 ${checkConfigPath}`))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 进度条日志
|
|
38
|
-
*/
|
|
39
|
-
const progressLog = (progress: number, total: number) => {
|
|
40
|
-
const equal = Array.from({ length: total }, (_, i) => (i < progress ? '=' : ' ')).join('')
|
|
41
|
-
const percentage = ~~((progress / total) * 100)
|
|
42
|
-
const text = `\r查找进度:[${equal}] ${progress}/${total} ${percentage}%\r`
|
|
43
|
-
const outText = progress === total ? chalk.green(text) : chalk.yellow(text)
|
|
44
|
-
process.stdout.write(outText)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 获取版本日志
|
|
49
|
-
*/
|
|
50
|
-
const getVersionLog = (name: string, value: string, distTags: NPMResponse['dist-tags']) => {
|
|
51
|
-
let tag = 'latest'
|
|
52
|
-
defaultConfig.resolve.some(item => {
|
|
53
|
-
const spaceIndex = item.lastIndexOf('@')
|
|
54
|
-
if (spaceIndex <= 0) return true
|
|
55
|
-
const curName = item.slice(0, spaceIndex)
|
|
56
|
-
const curTag = item.slice(spaceIndex + 1)
|
|
57
|
-
if (name === curName) {
|
|
58
|
-
tag = curTag
|
|
59
|
-
return true
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
const newVersion = defaultConfig.prefix + distTags[tag]
|
|
63
|
-
return { name, value, newVersion, tag }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 获取空格
|
|
68
|
-
*/
|
|
69
|
-
const getSpace = (length: number, maxLength: number) => Array.from({ length: maxLength - length }, () => ' ').join('')
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 获取长度
|
|
73
|
-
*/
|
|
74
|
-
const getValueLength = (value: string, i: number) => (+!i + 1) * value.length
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 格式化版本
|
|
78
|
-
*/
|
|
79
|
-
export const formatterVersion = (oldVersion: string, newVersion: string): string | false => {
|
|
80
|
-
const oldV = oldVersion.match(/\d.+/g)![0].split('.')
|
|
81
|
-
const newV = newVersion.match(/\d.+/g)![0].split('.')
|
|
82
|
-
const index = newV.slice(0, -1).findIndex((item, i) => +item > +oldV[i])
|
|
83
|
-
const mainName = defaultConfig.prefix + newV[0]
|
|
84
|
-
switch (index) {
|
|
85
|
-
case 0:
|
|
86
|
-
return chalk.red(newVersion)
|
|
87
|
-
case 1:
|
|
88
|
-
return `${mainName}.${chalk.yellow(newV[1])}.${chalk.yellow(newV[2])}`
|
|
89
|
-
default:
|
|
90
|
-
const oldVLast = oldV.at(-1) as string
|
|
91
|
-
const newVLast = newV.at(-1) as string
|
|
92
|
-
return oldVLast !== newVLast && parseInt(newVLast) >= parseInt(oldVLast) ? `${mainName}.${newV[1]}.${chalk.green(newV[2])}` : false
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 计算版本日志
|
|
98
|
-
*/
|
|
99
|
-
const outVersionLog = (versionLogs: VersionLog[]) => {
|
|
100
|
-
const fieldMax: Record<string, number> = {}
|
|
101
|
-
versionLogs.forEach(item => {
|
|
102
|
-
Object.entries(item).forEach(([key, value]) => {
|
|
103
|
-
fieldMax[key] = Math.max(value.length, fieldMax[key] ?? 0)
|
|
104
|
-
})
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
versionLogs.unshift({ name: '包名', value: '版本', newVersion: '新版本', tag: '标签' })
|
|
108
|
-
|
|
109
|
-
const outLog: string[] = []
|
|
110
|
-
versionLogs.forEach(({ name, value, newVersion, tag }, i) => {
|
|
111
|
-
const [nameSpace, valueSpace, newVersionSpace, tagSpace] = Object.entries({ name, value, newVersion, tag }).map(([key, value]) => getSpace(getValueLength(value, i), fieldMax[key]))
|
|
112
|
-
let spacer = chalk.yellow('→')
|
|
113
|
-
let showLog = true
|
|
114
|
-
if (i) {
|
|
115
|
-
const formatVer = formatterVersion(value, newVersion)
|
|
116
|
-
if (formatVer) {
|
|
117
|
-
newVersion = formatVer
|
|
118
|
-
} else {
|
|
119
|
-
showLog = false
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
name = chalk.green(name)
|
|
123
|
-
value = chalk.green(value)
|
|
124
|
-
newVersion = chalk.green(newVersion)
|
|
125
|
-
tag = chalk.green(tag)
|
|
126
|
-
spacer = ' '
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const text = `${name + nameSpace} ${valueSpace + value} ${spacer} ${newVersionSpace + newVersion} ${tagSpace + tag}`
|
|
130
|
-
showLog && outLog.push(text)
|
|
131
|
-
})
|
|
132
|
-
if (outLog.length > 1) {
|
|
133
|
-
outLog.forEach(info)
|
|
134
|
-
} else {
|
|
135
|
-
success('所有版本已是最新')
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* 进度条任务
|
|
141
|
-
*/
|
|
142
|
-
const taskProgress = async (allPackages: Record<string, string>, keys: string[], newPackages: Record<string, any>) => {
|
|
143
|
-
info()
|
|
144
|
-
/**
|
|
145
|
-
* 进度条
|
|
146
|
-
*/
|
|
147
|
-
let progress = 0
|
|
148
|
-
const versionLogs: VersionLog[] = []
|
|
149
|
-
const allPackagesArray = Object.entries(allPackages)
|
|
150
|
-
const packageTask = allPackagesArray.map(async ([name, value]) => {
|
|
151
|
-
/**
|
|
152
|
-
* 获取包最新消息
|
|
153
|
-
*/
|
|
154
|
-
const data = await pacote.packument(name, { registry: defaultConfig.registry })
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* 获取日志信息
|
|
158
|
-
*/
|
|
159
|
-
const logItem = getVersionLog(name, value, data['dist-tags'])
|
|
160
|
-
versionLogs.push(logItem)
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* 收集新包信息
|
|
164
|
-
*/
|
|
165
|
-
keys.forEach(key => {
|
|
166
|
-
const item = newPackages[key]
|
|
167
|
-
item && item[name] && (item[name] = logItem.newVersion)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 开启进度条
|
|
172
|
-
*/
|
|
173
|
-
progress++
|
|
174
|
-
await progressLog(progress, allPackagesArray.length)
|
|
175
|
-
})
|
|
176
|
-
await Promise.all(packageTask)
|
|
177
|
-
info()
|
|
178
|
-
info()
|
|
179
|
-
return versionLogs
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* 升级
|
|
184
|
-
*/
|
|
185
|
-
const simplifyUpgrade = async ({ update, init }: Record<string, boolean>) => {
|
|
186
|
-
if (init) return initConfigJson()
|
|
187
|
-
if (!existsSync(packagePath)) return error('package.json 文件不存在')
|
|
188
|
-
|
|
189
|
-
existsSync(checkConfigPath) && Object.assign(defaultConfig, JSON.parse(stripJsonComments(readFileSync(checkConfigPath, fileOption).toString())))
|
|
190
|
-
|
|
191
|
-
const newUpdate = update || defaultConfig.check
|
|
192
|
-
const packageJsonString = readFileSync(packagePath, fileOption).toString()
|
|
193
|
-
const packageJson: Record<string, any> = JSON.parse(packageJsonString)
|
|
194
|
-
const keys = ['dependencies', 'devDependencies', 'optionalDependencies']
|
|
195
|
-
const allPackages: Record<string, string> = {}
|
|
196
|
-
const newPackages = JSON.parse(packageJsonString)
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* 收集所有的包
|
|
200
|
-
*/
|
|
201
|
-
keys.forEach(key => {
|
|
202
|
-
if (!packageJson[key]) return
|
|
203
|
-
Object.entries(packageJson[key]).forEach(([key, value]) => {
|
|
204
|
-
!defaultConfig.reject.includes(key) && (allPackages[key] = value as string)
|
|
205
|
-
})
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* 进度条
|
|
210
|
-
*/
|
|
211
|
-
const versionLogs = await taskProgress(allPackages, keys, newPackages)
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* 更新包内容
|
|
215
|
-
*/
|
|
216
|
-
if (newUpdate) {
|
|
217
|
-
writeFileSync(packagePath, JSON.stringify(newPackages, null, 2))
|
|
218
|
-
success('文件 package.json 已更新')
|
|
219
|
-
info()
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* 输出包信息
|
|
224
|
-
*/
|
|
225
|
-
outVersionLog(versionLogs)
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
program
|
|
229
|
-
.command('check')
|
|
230
|
-
.option('-u, --update', `更新 package.json 依赖内容 或者配置 ${checkConfigName} 文件`, false)
|
|
231
|
-
.option('-i, --init', `仅初始化 ${checkConfigName} 文件,不检查依赖版本`, false)
|
|
232
|
-
.description('升级 package.json 依赖版本')
|
|
233
|
-
.action(simplifyUpgrade)
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { program } from 'commander'
|
|
2
|
-
import { readdirSync, writeFileSync, readFileSync, existsSync } from 'fs'
|
|
3
|
-
import { join } from 'path'
|
|
4
|
-
import type { MkdirTree } from '@/types'
|
|
5
|
-
|
|
6
|
-
const topIgnore = ['dist', 'node_modules', '.git', 'miniprogram_npm']
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 最大值
|
|
10
|
-
*/
|
|
11
|
-
let maxLength = 0
|
|
12
|
-
/**
|
|
13
|
-
* 是否计算了最大值
|
|
14
|
-
*/
|
|
15
|
-
let isMax = false
|
|
16
|
-
/**
|
|
17
|
-
* 是否有横线
|
|
18
|
-
*/
|
|
19
|
-
let hasLine = false
|
|
20
|
-
/**
|
|
21
|
-
* 初始化横线数量
|
|
22
|
-
*/
|
|
23
|
-
let initLine = 20
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 获取 suffix
|
|
27
|
-
*/
|
|
28
|
-
const getItemText = ({ prev, i, index, arr, curText }: Record<string, any>) => {
|
|
29
|
-
const prefix = Array.from({ length: i }).reduce(prev => prev + `${i === 1 && index === arr.length - 1 ? '└ ' : '│ '} `, '') as string
|
|
30
|
-
const newPrev = prev + prefix
|
|
31
|
-
const curLen = (prefix + curText).length
|
|
32
|
-
const suffix = Array.from({ length: initLine + maxLength - curLen }).reduce(prev => `${prev}-`, ' ')
|
|
33
|
-
!isMax && (maxLength = Math.max(maxLength, curLen))
|
|
34
|
-
return `${newPrev}${curText}${hasLine ? suffix : ''}\n`
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* 获取文本
|
|
38
|
-
*/
|
|
39
|
-
const getText = (tree: MkdirTree[], i = 0): string =>
|
|
40
|
-
tree.reduce((prev, item, index, arr) => {
|
|
41
|
-
let curText
|
|
42
|
-
if (item.children) {
|
|
43
|
-
curText = `├── ${item.name}`
|
|
44
|
-
return getItemText({ prev, i, index, arr, curText }) + getText(item.children, i + 1)
|
|
45
|
-
} else {
|
|
46
|
-
curText = `${index === arr.length - 1 ? '└── ' : '├── '}${item.name}`
|
|
47
|
-
return getItemText({ prev, i, index, arr, curText })
|
|
48
|
-
}
|
|
49
|
-
}, '')
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 排序,文件夹在文件的前面
|
|
53
|
-
*/
|
|
54
|
-
const sort = (path: string) => readdirSync(path, { withFileTypes: true }).sort((a, b) => +b.isDirectory() - +a.isDirectory())
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 简化 mkdir 操作
|
|
58
|
-
*/
|
|
59
|
-
export const simplifyMkdir = ({ line, name }: Record<string, string | boolean>) => {
|
|
60
|
-
hasLine = !!line
|
|
61
|
-
typeof line === 'string' && (initLine = +line)
|
|
62
|
-
|
|
63
|
-
const rootDir = process.cwd()
|
|
64
|
-
|
|
65
|
-
const gitignorePath = join(rootDir, '.gitignore')
|
|
66
|
-
if (existsSync(gitignorePath)) {
|
|
67
|
-
const ignoreFile = readFileSync(gitignorePath, { encoding: 'utf-8' }).split('\r\n')
|
|
68
|
-
topIgnore.push(...ignoreFile)
|
|
69
|
-
}
|
|
70
|
-
const rootName = rootDir.split('\\').at(-1)!
|
|
71
|
-
const dirs = sort(rootDir)
|
|
72
|
-
const children = dirs.map(dir => {
|
|
73
|
-
const { name } = dir
|
|
74
|
-
const item: MkdirTree = { name }
|
|
75
|
-
!topIgnore.includes(name) && dir.isDirectory() && (item.children = sort(join(dir.path, name)).map(({ name }) => ({ name })))
|
|
76
|
-
return item
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
const tree: MkdirTree[] = [{ name: rootName, children }]
|
|
80
|
-
|
|
81
|
-
if (hasLine) {
|
|
82
|
-
getText(tree)
|
|
83
|
-
isMax = true
|
|
84
|
-
}
|
|
85
|
-
writeFileSync(join(rootDir, `${(typeof name === 'string' && name) || 'directory'}.md`), getText(tree))
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
program
|
|
89
|
-
.command('mkdir')
|
|
90
|
-
.option('-l, --line [数量]', '数量', false)
|
|
91
|
-
.option('-n, --name [文件名称]', '文件名称', false)
|
|
92
|
-
.option('-d, --depth [深度值]', '深度值', '3')
|
|
93
|
-
.description('生成目录结构文件')
|
|
94
|
-
.action(simplifyMkdir)
|
package/src/commander/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { program } from 'commander'
|
|
2
|
-
import { version } from '~/package.json'
|
|
3
|
-
import { simplifyGit, handleArguments } from './actions'
|
|
4
|
-
import './commands'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 重置版本
|
|
8
|
-
*/
|
|
9
|
-
program.usage('[commands] [options]').version(version, '-v, --version', '输出版本号').helpOption('-h, --help', '输出所有命令')
|
|
10
|
-
program.command('git [描述]').description('简化 Git 提交命令').action(simplifyGit)
|
|
11
|
-
program.command('build[:环境] [描述]').description('简化打包提交命令')
|
|
12
|
-
program.command('version<[++]|[@<版本号>]>').description('例如:version++ 或者 version@1.0.0;自动更新 package.json 版本号,自动更新 `README.md` 中的 `version-v<version>-blue` 图标版本')
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 定义顶级命令的参数语法
|
|
16
|
-
*/
|
|
17
|
-
program.arguments('<cmd> [env]').action((cmd: any, env: any) => {
|
|
18
|
-
handleArguments(cmd, env)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 处理参数
|
|
23
|
-
*/
|
|
24
|
-
process.argv.length < 3 ? program.help() : program.parse(process.argv)
|
package/src/commander/types.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* defaultConfig
|
|
3
|
-
*/
|
|
4
|
-
export interface DefaultConfig {
|
|
5
|
-
prefix: string
|
|
6
|
-
registry: string
|
|
7
|
-
check: boolean
|
|
8
|
-
reject: string[]
|
|
9
|
-
resolve: string[]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* versionLogs
|
|
14
|
-
*/
|
|
15
|
-
export interface VersionLog {
|
|
16
|
-
name: string
|
|
17
|
-
value: string
|
|
18
|
-
newVersion: string
|
|
19
|
-
tag: string
|
|
20
|
-
}
|
package/src/config/config.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 默认的模板地址,也可以配置其它模板地址
|
|
3
|
-
*/
|
|
4
|
-
const defaultTemplateUrl = 'https://gitee.com/biaovorg/project-template.git'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 模板下载地址
|
|
8
|
-
*/
|
|
9
|
-
export const templateUrls = {
|
|
10
|
-
vue: defaultTemplateUrl,
|
|
11
|
-
react: defaultTemplateUrl,
|
|
12
|
-
'uni-app': defaultTemplateUrl,
|
|
13
|
-
electron: defaultTemplateUrl,
|
|
14
|
-
node: defaultTemplateUrl,
|
|
15
|
-
'node-simple': defaultTemplateUrl
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 工具对应命令
|
|
20
|
-
*/
|
|
21
|
-
export const toolCommands = {
|
|
22
|
-
npm: {
|
|
23
|
-
install: 'npm i',
|
|
24
|
-
start: 'npm start'
|
|
25
|
-
},
|
|
26
|
-
cnpm: {
|
|
27
|
-
install: 'cnpm i',
|
|
28
|
-
start: 'cnpm start'
|
|
29
|
-
},
|
|
30
|
-
pnpm: {
|
|
31
|
-
install: 'pnpm i',
|
|
32
|
-
start: 'pnpm start'
|
|
33
|
-
},
|
|
34
|
-
yarn: {
|
|
35
|
-
install: 'yarn',
|
|
36
|
-
start: 'yarn start'
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/config/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { InstallToolKey, TemplateUrlKey } from '@/types'
|
|
2
|
-
import { templateUrls, toolCommands } from './config'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 模板名称
|
|
6
|
-
*/
|
|
7
|
-
export const templateNames = Object.keys(templateUrls) as TemplateUrlKey[]
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 模板名称拼接
|
|
11
|
-
*/
|
|
12
|
-
export const templateNameString = templateNames.reduce((prev, item, i) => prev + (i ? ', ' : '') + item, '')
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 工具名称
|
|
16
|
-
*/
|
|
17
|
-
export const installTools = Object.keys(toolCommands) as InstallToolKey[]
|
|
18
|
-
|
|
19
|
-
export { templateUrls, toolCommands }
|
package/src/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// <reference path="./module.d.ts" />
|
|
2
|
-
|
|
3
|
-
import updateNotifier from 'update-notifier'
|
|
4
|
-
import chalk from 'chalk'
|
|
5
|
-
import pkg from '../package.json'
|
|
6
|
-
import './commander' // 命令
|
|
7
|
-
|
|
8
|
-
const notifier = updateNotifier({ pkg })
|
|
9
|
-
|
|
10
|
-
if (notifier.update && notifier.update.latest !== pkg.version) {
|
|
11
|
-
let msg = ''
|
|
12
|
-
switch (notifier.update.type) {
|
|
13
|
-
case 'major':
|
|
14
|
-
msg = chalk.red('{latestVersion}')
|
|
15
|
-
break
|
|
16
|
-
case 'minor':
|
|
17
|
-
msg = chalk.yellow('{latestVersion}')
|
|
18
|
-
break
|
|
19
|
-
default:
|
|
20
|
-
msg = chalk.green('{latestVersion}')
|
|
21
|
-
break
|
|
22
|
-
}
|
|
23
|
-
const compareUrl = `https://github.com/biaov/${pkg.name}/compare/v${pkg.version}...v{latestVersion}`
|
|
24
|
-
notifier.notify({
|
|
25
|
-
defer: false,
|
|
26
|
-
isGlobal: true,
|
|
27
|
-
message: `有更新 ${chalk.dim('{currentVersion}')}${chalk.reset(' → ')}${msg}\n运行 ${chalk.cyan('{updateCommand}')} 命令更新\n${chalk.dim.underline(compareUrl)}`
|
|
28
|
-
})
|
|
29
|
-
}
|
package/src/module.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module 'inquirer'
|
package/src/types.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { templateUrls, toolCommands } from './config/config'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 安装工具 key
|
|
5
|
-
*/
|
|
6
|
-
export type InstallToolKey = keyof typeof toolCommands
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 模板 key
|
|
10
|
-
*/
|
|
11
|
-
export type TemplateUrlKey = keyof typeof templateUrls
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* mkdir tree
|
|
15
|
-
*/
|
|
16
|
-
export interface MkdirTree {
|
|
17
|
-
name: string
|
|
18
|
-
children?: MkdirTree[]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* `https://registry.npmjs.org/包名/` 返回信息
|
|
23
|
-
*/
|
|
24
|
-
export interface NPMResponse {
|
|
25
|
-
'dist-tags': Record<string, string>
|
|
26
|
-
}
|
package/src/utils/functions.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { writeFile, readFileSync } from 'fs'
|
|
2
|
-
import { resolve, dirname } from 'path'
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import { fileURLToPath } from 'url'
|
|
5
|
-
import { PresetInfo } from './types'
|
|
6
|
-
|
|
7
|
-
export const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
8
|
-
/**
|
|
9
|
-
* 预设数据路径
|
|
10
|
-
*/
|
|
11
|
-
const presetPath = resolve(__dirname, './presetData.json')
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 保存本地预设信息
|
|
15
|
-
* @param { string } name - 对象名称
|
|
16
|
-
* @param { PresetInfo } data - 对象值
|
|
17
|
-
* @returns { void }
|
|
18
|
-
*/
|
|
19
|
-
export const SavePresetInfo = (name: string, data: PresetInfo) => {
|
|
20
|
-
/**
|
|
21
|
-
* 保存对象键值对
|
|
22
|
-
*/
|
|
23
|
-
const saveData = GetPresetInfo()
|
|
24
|
-
saveData[name] = data
|
|
25
|
-
writeFile(presetPath, JSON.stringify(saveData), err => {
|
|
26
|
-
err && console.log('保存预设失败')
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 读取本地预设信息
|
|
32
|
-
* @param { void }
|
|
33
|
-
* @returns { Partial<PresetInfo> }
|
|
34
|
-
*/
|
|
35
|
-
export const GetPresetInfo = (): Partial<PresetInfo> => {
|
|
36
|
-
let info: Buffer
|
|
37
|
-
try {
|
|
38
|
-
info = readFileSync(presetPath) // 读取文件
|
|
39
|
-
} catch {
|
|
40
|
-
return {} // 返回空对象
|
|
41
|
-
}
|
|
42
|
-
return JSON.parse(`${info}`)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 格式化预设值
|
|
47
|
-
* @param { Partial<PresetInfo> }
|
|
48
|
-
* @returns { string[] }
|
|
49
|
-
*/
|
|
50
|
-
export const FormatePreset = (presetInfo: Partial<PresetInfo>): string[] =>
|
|
51
|
-
Object.entries(presetInfo).map(
|
|
52
|
-
([key, value]) =>
|
|
53
|
-
`${key}(${Object.values(value)
|
|
54
|
-
.map(item => `${chalk.yellow(item)}`)
|
|
55
|
-
.join(', ')})`
|
|
56
|
-
)
|
package/src/utils/log.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import logSymbols from 'log-symbols'
|
|
3
|
-
import { name } from '~/package.json'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 成功日志
|
|
7
|
-
*/
|
|
8
|
-
export const success = (text?: string | number) => {
|
|
9
|
-
console.log(`${logSymbols.success} ${chalk.green('SUCCESS')} ${text}`)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 失败日志
|
|
14
|
-
*/
|
|
15
|
-
export const error = (text?: string | number) => {
|
|
16
|
-
console.log(`${name} ${logSymbols.error} ${chalk.red('ERROR')} ${text}`)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 信息日志
|
|
21
|
-
*/
|
|
22
|
-
export const info = (text?: string | number) => {
|
|
23
|
-
console.log(text ?? '')
|
|
24
|
-
}
|
package/src/utils/types.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"incremental": false,
|
|
4
|
-
"composite": false,
|
|
5
|
-
"target": "esnext",
|
|
6
|
-
"useDefineForClassFields": true,
|
|
7
|
-
"module": "ESNext",
|
|
8
|
-
"moduleResolution": "node",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"jsx": "preserve",
|
|
11
|
-
"sourceMap": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"esModuleInterop": true,
|
|
15
|
-
"lib": ["esnext"],
|
|
16
|
-
"types": ["node"],
|
|
17
|
-
"skipLibCheck": true,
|
|
18
|
-
"baseUrl": "./",
|
|
19
|
-
"paths": {
|
|
20
|
-
"@/*": ["./src/*"],
|
|
21
|
-
"~/*": ["./*"]
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"include": ["src/**/*.ts"],
|
|
25
|
-
"exclude": ["node_modules", "dist", ".git"]
|
|
26
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite'
|
|
2
|
-
import { resolve } from 'path'
|
|
3
|
-
import rollupPluginCopy from './scripts/rollup-plugin-copy'
|
|
4
|
-
|
|
5
|
-
const { dirname } = import.meta
|
|
6
|
-
|
|
7
|
-
const outDir = resolve(dirname, './dist/dist')
|
|
8
|
-
|
|
9
|
-
export default defineConfig({
|
|
10
|
-
root: dirname,
|
|
11
|
-
resolve: {
|
|
12
|
-
alias: {
|
|
13
|
-
'@': resolve(dirname, './src'),
|
|
14
|
-
'~': resolve(dirname, './')
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
build: {
|
|
18
|
-
target: 'node20',
|
|
19
|
-
outDir,
|
|
20
|
-
lib: {
|
|
21
|
-
entry: resolve(dirname, './src/index.ts'),
|
|
22
|
-
formats: ['es']
|
|
23
|
-
},
|
|
24
|
-
rollupOptions: {
|
|
25
|
-
external: ['update-notifier', 'url', 'path', 'child_process', 'fs', 'chalk', 'commander', 'log-symbols', 'ora', 'pacote', 'strip-json-comments'],
|
|
26
|
-
output: {
|
|
27
|
-
entryFileNames: '[name].js'
|
|
28
|
-
},
|
|
29
|
-
plugins: [rollupPluginCopy()]
|
|
30
|
-
},
|
|
31
|
-
ssr: false,
|
|
32
|
-
ssrManifest: false,
|
|
33
|
-
emptyOutDir: true
|
|
34
|
-
}
|
|
35
|
-
})
|
|
File without changes
|