mine-auto-cli 2.0.3 → 2.1.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 +13 -4
- package/dist/index.js +121 -90
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
一个将多个命令简化成一个命令的项目 😆
|
|
4
4
|
|
|
5
5
|
<h2 align="center">
|
|
6
|
-
<a href="https://www.npmjs.com/package/mine-auto-cli"><img src="https://img.shields.io/npm/v/mine-auto-cli.svg?logo=npm" /></a>
|
|
7
|
-
<a href="https://www.npmjs.com/package/mine-auto-cli"><img src="https://img.shields.io/npm/dt/mine-auto-cli?logo=Markdown" /></a>
|
|
8
|
-
<a href="https://www.npmjs.com/package/mine-auto-cli"><img src="https://packagephobia.com/badge?p=mine-auto-cli" /></a>
|
|
9
|
-
<a href="https://github.com/biaov/mine-auto-cli/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green?logo=Unlicense" /></a>
|
|
6
|
+
<a href="https://www.npmjs.com/package/mine-auto-cli"><img src="https://img.shields.io/npm/v/mine-auto-cli.svg?logo=npm" alt="版本" /></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/mine-auto-cli"><img src="https://img.shields.io/npm/dt/mine-auto-cli?logo=Markdown" alt="下载量" /></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/mine-auto-cli"><img src="https://packagephobia.com/badge?p=mine-auto-cli" alt="安装大小" /></a>
|
|
9
|
+
<a href="https://github.com/biaov/mine-auto-cli/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green?logo=Unlicense" alt="版权" /></a>
|
|
10
10
|
</h2>
|
|
11
11
|
|
|
12
12
|
## 全局安装
|
|
@@ -50,6 +50,15 @@ git commit -m [描述]
|
|
|
50
50
|
git push
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
### 简化手动更改版本号命令
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
# 版本号自增
|
|
57
|
+
auto version++
|
|
58
|
+
# 或者指定具体的版本号
|
|
59
|
+
auto version@1.0.0
|
|
60
|
+
```
|
|
61
|
+
|
|
53
62
|
### 技术栈
|
|
54
63
|
|
|
55
64
|
- `Vite` + `TypeScript` + `Node`
|
package/dist/index.js
CHANGED
|
@@ -1,144 +1,175 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { program as
|
|
4
|
-
import
|
|
5
|
-
import { execSync as
|
|
6
|
-
import
|
|
7
|
-
|
|
1
|
+
import C from "update-notifier";
|
|
2
|
+
import s from "chalk";
|
|
3
|
+
import { program as r } from "commander";
|
|
4
|
+
import E from "ora";
|
|
5
|
+
import { execSync as J } from "child_process";
|
|
6
|
+
import { readFileSync as y, writeFileSync as v } from "fs";
|
|
7
|
+
import { join as $ } from "path";
|
|
8
|
+
import w from "log-symbols";
|
|
9
|
+
const k = "mine-auto-cli", j = "2.1.0", A = "./dist/index.js", q = "./dist/index.js", D = "module", N = {
|
|
8
10
|
auto: "bin/mine-auto-cli.js"
|
|
9
|
-
},
|
|
11
|
+
}, O = {
|
|
10
12
|
name: "biaov",
|
|
11
13
|
email: "biaov@qq.com",
|
|
12
14
|
url: "https://biaov.cn"
|
|
13
|
-
},
|
|
15
|
+
}, F = "一个将多个命令简化成一个命令的项目 😆", G = {
|
|
14
16
|
start: "npm run dev",
|
|
15
17
|
dev: "npm run build -- --watch",
|
|
16
18
|
build: "node scripts/build && vite build",
|
|
17
19
|
prettier: "prettier --write '**/*.{js,ts,md,json}'",
|
|
18
20
|
ncu: "ncu --configFileName .ncurc.json && npm i"
|
|
19
|
-
},
|
|
21
|
+
}, I = {
|
|
20
22
|
registry: "https://registry.npmjs.org/"
|
|
21
|
-
},
|
|
22
|
-
node: ">=
|
|
23
|
-
},
|
|
23
|
+
}, T = {
|
|
24
|
+
node: ">=20"
|
|
25
|
+
}, B = [
|
|
24
26
|
"auto",
|
|
25
27
|
"cli",
|
|
26
28
|
"vite",
|
|
27
29
|
"typescript"
|
|
28
|
-
],
|
|
30
|
+
], M = {
|
|
29
31
|
type: "git",
|
|
30
|
-
url: "https://github.com/biaov/mine-auto-cli.git"
|
|
31
|
-
},
|
|
32
|
+
url: "git+https://github.com/biaov/mine-auto-cli.git"
|
|
33
|
+
}, R = "https://github.com/biaov/mine-auto-cli.git", U = {
|
|
32
34
|
url: "https://github.com/biaov/mine-auto-cli/issues"
|
|
33
|
-
},
|
|
35
|
+
}, L = "ISC", P = [
|
|
34
36
|
{
|
|
35
37
|
name: "biaov",
|
|
36
38
|
email: "biaov@qq.com"
|
|
37
39
|
}
|
|
38
|
-
],
|
|
40
|
+
], z = {
|
|
39
41
|
chalk: "^5.3.0",
|
|
40
|
-
commander: "^11.
|
|
41
|
-
"log-symbols": "^
|
|
42
|
-
ora: "^
|
|
43
|
-
"update-notifier": "^
|
|
44
|
-
},
|
|
45
|
-
"@types/node": "^20.
|
|
46
|
-
"@types/update-notifier": "^6.0.
|
|
47
|
-
prettier: "^3.
|
|
48
|
-
typescript: "^5.
|
|
49
|
-
vite: "^
|
|
50
|
-
},
|
|
51
|
-
name:
|
|
42
|
+
commander: "^11.1.0",
|
|
43
|
+
"log-symbols": "^6.0.0",
|
|
44
|
+
ora: "^8.0.1",
|
|
45
|
+
"update-notifier": "^7.0.0"
|
|
46
|
+
}, H = {
|
|
47
|
+
"@types/node": "^20.11.13",
|
|
48
|
+
"@types/update-notifier": "^6.0.8",
|
|
49
|
+
prettier: "^3.2.4",
|
|
50
|
+
typescript: "^5.3.3",
|
|
51
|
+
vite: "^5.0.12"
|
|
52
|
+
}, u = {
|
|
53
|
+
name: k,
|
|
52
54
|
private: !1,
|
|
53
|
-
version:
|
|
54
|
-
exports:
|
|
55
|
-
main:
|
|
56
|
-
type:
|
|
57
|
-
bin:
|
|
58
|
-
author:
|
|
59
|
-
description:
|
|
60
|
-
scripts:
|
|
61
|
-
publishConfig:
|
|
62
|
-
engines:
|
|
63
|
-
keywords:
|
|
64
|
-
repository:
|
|
65
|
-
homepage:
|
|
66
|
-
bugs:
|
|
67
|
-
license:
|
|
68
|
-
contributors:
|
|
69
|
-
dependencies:
|
|
70
|
-
devDependencies:
|
|
71
|
-
},
|
|
55
|
+
version: j,
|
|
56
|
+
exports: A,
|
|
57
|
+
main: q,
|
|
58
|
+
type: D,
|
|
59
|
+
bin: N,
|
|
60
|
+
author: O,
|
|
61
|
+
description: F,
|
|
62
|
+
scripts: G,
|
|
63
|
+
publishConfig: I,
|
|
64
|
+
engines: T,
|
|
65
|
+
keywords: B,
|
|
66
|
+
repository: M,
|
|
67
|
+
homepage: R,
|
|
68
|
+
bugs: U,
|
|
69
|
+
license: L,
|
|
70
|
+
contributors: P,
|
|
71
|
+
dependencies: z,
|
|
72
|
+
devDependencies: H
|
|
73
|
+
}, g = {}, K = [
|
|
72
74
|
{
|
|
73
75
|
name: "success",
|
|
74
|
-
color:
|
|
76
|
+
color: s.green
|
|
75
77
|
},
|
|
76
78
|
{
|
|
77
79
|
name: "error",
|
|
78
|
-
color:
|
|
79
|
-
prefix:
|
|
80
|
+
color: s.red,
|
|
81
|
+
prefix: k
|
|
80
82
|
},
|
|
81
83
|
{
|
|
82
84
|
name: "warning",
|
|
83
|
-
color:
|
|
85
|
+
color: s.red
|
|
84
86
|
},
|
|
85
87
|
{
|
|
86
88
|
name: "info"
|
|
87
89
|
}
|
|
88
90
|
];
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (typeof
|
|
92
|
-
const { text:
|
|
93
|
-
|
|
91
|
+
K.forEach(({ name: e, color: o, prefix: c = "" }) => {
|
|
92
|
+
g[e] = (t = "") => {
|
|
93
|
+
if (typeof t == "object") {
|
|
94
|
+
const { text: i = "", prefix: a = "" } = t;
|
|
95
|
+
i && console.log(`${a + " "}${t}`);
|
|
94
96
|
} else
|
|
95
|
-
console.log(o ? `${
|
|
97
|
+
console.log(o ? `${c + " "}${o(e.toUpperCase())} ${t}` : t);
|
|
96
98
|
};
|
|
97
99
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const o =
|
|
100
|
+
g.iconError = w.error;
|
|
101
|
+
g.iconSuccess = w.success;
|
|
102
|
+
const Q = (e) => ["git add -A", `git commit -m ${e}`, "git push"], W = (e, o) => [`npm run ${e}`, "git add -A", `git commit -m ${o}`, "git push"], { success: d, info: n, error: S } = g, x = (e) => {
|
|
103
|
+
n(`开始执行 ${s.cyanBright(e)} 命令`);
|
|
104
|
+
const o = E({ text: "正在执行命令中...", color: "yellow" });
|
|
103
105
|
o.start();
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
},
|
|
106
|
+
const c = J(e, { cwd: process.cwd() });
|
|
107
|
+
n(c.toString()), o.succeed(`${s.green(e)} 命令执行成功`), n();
|
|
108
|
+
}, X = async (e = "更新代码") => {
|
|
109
|
+
n(), n(`${s.yellow(">>")} 开始依次执行命令...`), n(), Q(e).forEach(x), d("全部命令执行完成"), n();
|
|
110
|
+
}, Y = async (e, o = "打包") => {
|
|
111
|
+
n(), n(`${s.yellow(">>")} 开始依次执行命令...`), n(), W(e, o).map(x), d("全部命令执行完成"), n();
|
|
112
|
+
}, h = (e) => {
|
|
113
|
+
n(), S(`\`${e}\` 命令错误,请检查你的命令`), n(), r.help();
|
|
114
|
+
}, b = (e) => {
|
|
115
|
+
const o = ["package.json", "README.md"].map((a) => {
|
|
116
|
+
const p = $(process.cwd(), a), l = y(p).toString();
|
|
117
|
+
return { path: p, content: l };
|
|
118
|
+
}), [c, t] = o, i = JSON.parse(c.content);
|
|
119
|
+
if (e)
|
|
120
|
+
i.version = e;
|
|
121
|
+
else {
|
|
122
|
+
const a = i.version.split(".").reduce((p, l, f, V) => p + (f === V.length - 1 ? +l + 1 : `${l}.`), "");
|
|
123
|
+
i.version = a;
|
|
124
|
+
}
|
|
125
|
+
v(c.path, JSON.stringify(i, null, 2)), t.content = t.content.replace(/version\-v.+\-blue/, () => `version-v${i.version}-blue`), v(t.path, t.content);
|
|
126
|
+
}, Z = async (e) => {
|
|
127
|
+
const o = e.split("version")[1];
|
|
128
|
+
if (!o)
|
|
129
|
+
return h(e);
|
|
130
|
+
const c = JSON.parse(y($(process.cwd(), "package.json"), "utf-8"));
|
|
131
|
+
if (o === "++") {
|
|
132
|
+
const i = c.version.split(".").reduce((a, p, l, f) => a + (l === f.length - 1 ? +p + 1 : `${p}.`), "");
|
|
133
|
+
b(i), n(), d("命令执行完成");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const t = o.split("@")[1];
|
|
137
|
+
t ? (b(t), n(), d("命令执行完成")) : h(e);
|
|
138
|
+
}, _ = (e, o) => {
|
|
111
139
|
if (e.includes("build"))
|
|
112
|
-
return
|
|
113
|
-
|
|
140
|
+
return Y(e, o);
|
|
141
|
+
if (e.includes("version"))
|
|
142
|
+
return Z(e);
|
|
143
|
+
S(s.hex("#f56c6c")(`\`auto ${e}${o ? ` ${o}` : ""}\` 命令不存在`)), r.help();
|
|
114
144
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
145
|
+
r.usage("[commands] [options]").version(j, "-v, --version", "输出版本号").helpOption("-h, --help", "输出所有命令");
|
|
146
|
+
r.command("git [描述]").description("简化 Git 提交命令").action(X);
|
|
147
|
+
r.command("build[:环境] [描述]").description("简化打包提交命令");
|
|
148
|
+
r.command("version<[++]|[@<版本号>]>").description("例如:version++ 或者 version@1.0.0;自动更新 package.json 版本号,自动更新 `README.md` 中的 `version-v<version>-blue` 图标版本");
|
|
149
|
+
r.arguments("<cmd> [env]").action((e, o) => {
|
|
150
|
+
_(e, o);
|
|
120
151
|
});
|
|
121
|
-
process.argv.length < 3 ?
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
152
|
+
process.argv.length < 3 ? r.help() : r.parse(process.argv);
|
|
153
|
+
const m = C({ pkg: u });
|
|
154
|
+
if (m.update && m.update.latest !== u.version) {
|
|
124
155
|
let e = "";
|
|
125
|
-
switch (
|
|
156
|
+
switch (m.update.type) {
|
|
126
157
|
case "major":
|
|
127
|
-
e =
|
|
158
|
+
e = s.red("{latestVersion}");
|
|
128
159
|
break;
|
|
129
160
|
case "minor":
|
|
130
|
-
e =
|
|
161
|
+
e = s.yellow("{latestVersion}");
|
|
131
162
|
break;
|
|
132
163
|
default:
|
|
133
|
-
e =
|
|
164
|
+
e = s.green("{latestVersion}");
|
|
134
165
|
break;
|
|
135
166
|
}
|
|
136
|
-
const o = `https://github.com/biaov/${
|
|
137
|
-
|
|
167
|
+
const o = `https://github.com/biaov/${u.name}/compare/v${u.version}...v{latestVersion}`;
|
|
168
|
+
m.notify({
|
|
138
169
|
defer: !1,
|
|
139
170
|
isGlobal: !0,
|
|
140
|
-
message: `有更新 ${
|
|
141
|
-
运行 ${
|
|
142
|
-
${
|
|
171
|
+
message: `有更新 ${s.dim("{currentVersion}")}${s.reset(" → ")}${e}
|
|
172
|
+
运行 ${s.cyan("{updateCommand}")} 命令更新
|
|
173
|
+
${s.dim.underline(o)}`
|
|
143
174
|
});
|
|
144
175
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mine-auto-cli",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"registry": "https://registry.npmjs.org/"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": ">=
|
|
22
|
+
"node": ">=20"
|
|
23
23
|
},
|
|
24
24
|
"keywords": [
|
|
25
25
|
"auto",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
32
|
-
"url": "https://github.com/biaov/mine-auto-cli.git"
|
|
32
|
+
"url": "git+https://github.com/biaov/mine-auto-cli.git"
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/biaov/mine-auto-cli.git",
|
|
35
35
|
"bugs": {
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"chalk": "^5.3.0",
|
|
47
|
-
"commander": "^11.
|
|
48
|
-
"log-symbols": "^
|
|
49
|
-
"ora": "^
|
|
50
|
-
"update-notifier": "^
|
|
47
|
+
"commander": "^11.1.0",
|
|
48
|
+
"log-symbols": "^6.0.0",
|
|
49
|
+
"ora": "^8.0.1",
|
|
50
|
+
"update-notifier": "^7.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {}
|
|
53
53
|
}
|