mine-auto-cli 2.0.2 → 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/bin/mine-auto-cli.js +1 -1
- package/dist/index.js +175 -0
- package/package.json +9 -9
- package/index.js +0 -145
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/bin/mine-auto-cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import '../index.js'
|
|
2
|
+
import '../dist/index.js'
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
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 = {
|
|
10
|
+
auto: "bin/mine-auto-cli.js"
|
|
11
|
+
}, O = {
|
|
12
|
+
name: "biaov",
|
|
13
|
+
email: "biaov@qq.com",
|
|
14
|
+
url: "https://biaov.cn"
|
|
15
|
+
}, F = "一个将多个命令简化成一个命令的项目 😆", G = {
|
|
16
|
+
start: "npm run dev",
|
|
17
|
+
dev: "npm run build -- --watch",
|
|
18
|
+
build: "node scripts/build && vite build",
|
|
19
|
+
prettier: "prettier --write '**/*.{js,ts,md,json}'",
|
|
20
|
+
ncu: "ncu --configFileName .ncurc.json && npm i"
|
|
21
|
+
}, I = {
|
|
22
|
+
registry: "https://registry.npmjs.org/"
|
|
23
|
+
}, T = {
|
|
24
|
+
node: ">=20"
|
|
25
|
+
}, B = [
|
|
26
|
+
"auto",
|
|
27
|
+
"cli",
|
|
28
|
+
"vite",
|
|
29
|
+
"typescript"
|
|
30
|
+
], M = {
|
|
31
|
+
type: "git",
|
|
32
|
+
url: "git+https://github.com/biaov/mine-auto-cli.git"
|
|
33
|
+
}, R = "https://github.com/biaov/mine-auto-cli.git", U = {
|
|
34
|
+
url: "https://github.com/biaov/mine-auto-cli/issues"
|
|
35
|
+
}, L = "ISC", P = [
|
|
36
|
+
{
|
|
37
|
+
name: "biaov",
|
|
38
|
+
email: "biaov@qq.com"
|
|
39
|
+
}
|
|
40
|
+
], z = {
|
|
41
|
+
chalk: "^5.3.0",
|
|
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,
|
|
54
|
+
private: !1,
|
|
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 = [
|
|
74
|
+
{
|
|
75
|
+
name: "success",
|
|
76
|
+
color: s.green
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "error",
|
|
80
|
+
color: s.red,
|
|
81
|
+
prefix: k
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "warning",
|
|
85
|
+
color: s.red
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "info"
|
|
89
|
+
}
|
|
90
|
+
];
|
|
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}`);
|
|
96
|
+
} else
|
|
97
|
+
console.log(o ? `${c + " "}${o(e.toUpperCase())} ${t}` : t);
|
|
98
|
+
};
|
|
99
|
+
});
|
|
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" });
|
|
105
|
+
o.start();
|
|
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) => {
|
|
139
|
+
if (e.includes("build"))
|
|
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();
|
|
144
|
+
};
|
|
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);
|
|
151
|
+
});
|
|
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) {
|
|
155
|
+
let e = "";
|
|
156
|
+
switch (m.update.type) {
|
|
157
|
+
case "major":
|
|
158
|
+
e = s.red("{latestVersion}");
|
|
159
|
+
break;
|
|
160
|
+
case "minor":
|
|
161
|
+
e = s.yellow("{latestVersion}");
|
|
162
|
+
break;
|
|
163
|
+
default:
|
|
164
|
+
e = s.green("{latestVersion}");
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
const o = `https://github.com/biaov/${u.name}/compare/v${u.version}...v{latestVersion}`;
|
|
168
|
+
m.notify({
|
|
169
|
+
defer: !1,
|
|
170
|
+
isGlobal: !0,
|
|
171
|
+
message: `有更新 ${s.dim("{currentVersion}")}${s.reset(" → ")}${e}
|
|
172
|
+
运行 ${s.cyan("{updateCommand}")} 命令更新
|
|
173
|
+
${s.dim.underline(o)}`
|
|
174
|
+
});
|
|
175
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mine-auto-cli",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.0
|
|
5
|
-
"exports": "./index.js",
|
|
6
|
-
"main": "./index.js",
|
|
4
|
+
"version": "2.1.0",
|
|
5
|
+
"exports": "./dist/index.js",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": {
|
|
9
9
|
"auto": "bin/mine-auto-cli.js"
|
|
@@ -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
|
}
|
package/index.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import f from "update-notifier";
|
|
2
|
-
import t from "chalk";
|
|
3
|
-
import { program as i } from "commander";
|
|
4
|
-
import y from "ora";
|
|
5
|
-
import { execSync as v } from "child_process";
|
|
6
|
-
import m from "log-symbols";
|
|
7
|
-
const l = "mine-auto-cli", d = "2.0.2", $ = "./index.js", w = "./index.js", j = "module", k = {
|
|
8
|
-
auto: "bin/mine-auto-cli.js"
|
|
9
|
-
}, x = {
|
|
10
|
-
name: "biaov",
|
|
11
|
-
email: "biaov@qq.com",
|
|
12
|
-
url: "https://biaov.cn"
|
|
13
|
-
}, C = "一个将多个命令简化成一个命令的项目 😆", S = {
|
|
14
|
-
start: "npm run dev",
|
|
15
|
-
dev: "vite build --watch && node scripts/build",
|
|
16
|
-
build: "vite build && node scripts/build",
|
|
17
|
-
prettier: "prettier --write '**/*.{js,ts,md,json}'",
|
|
18
|
-
ncu: "ncu --configFileName .ncurc.json && npm i",
|
|
19
|
-
"pre-publish": "start cmd /k cd ./dist"
|
|
20
|
-
}, V = {
|
|
21
|
-
registry: "https://registry.npmjs.org/"
|
|
22
|
-
}, q = {
|
|
23
|
-
node: ">=16"
|
|
24
|
-
}, A = [
|
|
25
|
-
"auto",
|
|
26
|
-
"cli",
|
|
27
|
-
"vite",
|
|
28
|
-
"typescript"
|
|
29
|
-
], E = {
|
|
30
|
-
type: "git",
|
|
31
|
-
url: "https://github.com/biaov/mine-auto-cli.git"
|
|
32
|
-
}, G = "https://github.com/biaov/mine-auto-cli.git", B = {
|
|
33
|
-
url: "https://github.com/biaov/mine-auto-cli/issues"
|
|
34
|
-
}, D = "ISC", T = [
|
|
35
|
-
{
|
|
36
|
-
name: "biaov",
|
|
37
|
-
email: "biaov@qq.com"
|
|
38
|
-
}
|
|
39
|
-
], U = {
|
|
40
|
-
chalk: "^5.3.0",
|
|
41
|
-
commander: "^11.0.0",
|
|
42
|
-
"log-symbols": "^5.1.0",
|
|
43
|
-
ora: "^7.0.1",
|
|
44
|
-
"update-notifier": "^6.0.2"
|
|
45
|
-
}, F = {
|
|
46
|
-
"@types/node": "^20.8.4",
|
|
47
|
-
"@types/update-notifier": "^6.0.5",
|
|
48
|
-
prettier: "^3.0.3",
|
|
49
|
-
typescript: "^5.2.2",
|
|
50
|
-
vite: "^4.4.11"
|
|
51
|
-
}, c = {
|
|
52
|
-
name: l,
|
|
53
|
-
private: !1,
|
|
54
|
-
version: d,
|
|
55
|
-
exports: $,
|
|
56
|
-
main: w,
|
|
57
|
-
type: j,
|
|
58
|
-
bin: k,
|
|
59
|
-
author: x,
|
|
60
|
-
description: C,
|
|
61
|
-
scripts: S,
|
|
62
|
-
publishConfig: V,
|
|
63
|
-
engines: q,
|
|
64
|
-
keywords: A,
|
|
65
|
-
repository: E,
|
|
66
|
-
homepage: G,
|
|
67
|
-
bugs: B,
|
|
68
|
-
license: D,
|
|
69
|
-
contributors: T,
|
|
70
|
-
dependencies: U,
|
|
71
|
-
devDependencies: F
|
|
72
|
-
}, a = {}, I = [
|
|
73
|
-
{
|
|
74
|
-
name: "success",
|
|
75
|
-
color: t.green
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: "error",
|
|
79
|
-
color: t.red,
|
|
80
|
-
prefix: l
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: "warning",
|
|
84
|
-
color: t.red
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: "info"
|
|
88
|
-
}
|
|
89
|
-
];
|
|
90
|
-
I.forEach(({ name: e, color: o, prefix: p = "" }) => {
|
|
91
|
-
a[e] = (n = "") => {
|
|
92
|
-
if (typeof n == "object") {
|
|
93
|
-
const { text: b = "", prefix: h = "" } = n;
|
|
94
|
-
b && console.log(`${h + " "}${n}`);
|
|
95
|
-
} else
|
|
96
|
-
console.log(o ? `${p + " "}${o(e.toUpperCase())} ${n}` : n);
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
a.iconError = m.error;
|
|
100
|
-
a.iconSuccess = m.success;
|
|
101
|
-
const N = (e) => ["git add -A", `git commit -m ${e}`, "git push"], O = (e, o) => [`npm run ${e}`, "git add -A", `git commit -m ${o}`, "git push"], { success: u, info: s, error: P } = a, g = (e) => {
|
|
102
|
-
s(`开始执行 ${t.cyanBright(e)} 命令`);
|
|
103
|
-
const o = y({ text: "正在执行命令中...", color: "yellow" });
|
|
104
|
-
o.start();
|
|
105
|
-
const p = v(e, { cwd: process.cwd() });
|
|
106
|
-
s(p.toString()), o.succeed(`${t.green(e)} 命令执行成功`), s();
|
|
107
|
-
}, z = async (e = "更新代码") => {
|
|
108
|
-
s(), s(`${t.yellow(">>")} 开始依次执行命令...`), s(), N(e).forEach(g), u("全部命令执行完成"), s();
|
|
109
|
-
}, H = async (e, o = "打包") => {
|
|
110
|
-
s(), s(`${t.yellow(">>")} 开始依次执行命令...`), s(), O(e, o).map(g), u("全部命令执行完成"), s();
|
|
111
|
-
}, J = (e, o) => {
|
|
112
|
-
if (e.includes("build"))
|
|
113
|
-
return H(e, o);
|
|
114
|
-
P(t.hex("#f56c6c")(`\`auto ${e}${o ? ` ${o}` : ""}\` 命令不存在`)), i.help();
|
|
115
|
-
};
|
|
116
|
-
i.usage("[commands] [options]").version(d, "-v, --version", "输出版本号").helpOption("-h, --help", "输出所有命令");
|
|
117
|
-
i.command("git [描述]").description("简化 Git 提交命令").action(z);
|
|
118
|
-
i.command("build[:环境] [描述]").description("简化打包提交命令");
|
|
119
|
-
i.arguments("<cmd> [env]").action((e, o) => {
|
|
120
|
-
J(e, o);
|
|
121
|
-
});
|
|
122
|
-
process.argv.length < 3 ? i.help() : i.parse(process.argv);
|
|
123
|
-
const r = f({ pkg: c });
|
|
124
|
-
if (r.update && r.update.latest !== c.version) {
|
|
125
|
-
let e = "";
|
|
126
|
-
switch (r.update.type) {
|
|
127
|
-
case "major":
|
|
128
|
-
e = t.red("{latestVersion}");
|
|
129
|
-
break;
|
|
130
|
-
case "minor":
|
|
131
|
-
e = t.yellow("{latestVersion}");
|
|
132
|
-
break;
|
|
133
|
-
default:
|
|
134
|
-
e = t.green("{latestVersion}");
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
const o = `https://github.com/biaov/${c.name}/compare/v${c.version}...v{latestVersion}`;
|
|
138
|
-
r.notify({
|
|
139
|
-
defer: !1,
|
|
140
|
-
isGlobal: !0,
|
|
141
|
-
message: `有更新 ${t.dim("{currentVersion}")}${t.reset(" → ")}${e}
|
|
142
|
-
运行 ${t.cyan("{updateCommand}")} 命令更新
|
|
143
|
-
${t.dim.underline(o)}`
|
|
144
|
-
});
|
|
145
|
-
}
|