mine-auto-cli 2.0.3 → 2.2.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 +58 -4
- package/dist/index.js +146 -92
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -3,12 +3,19 @@
|
|
|
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
|
+
## 特性
|
|
13
|
+
|
|
14
|
+
- [x] [简化 `Git` 提交命令](#简化-git-提交命令)
|
|
15
|
+
- [x] [简化打包提交命令](#简化打包提交命令)
|
|
16
|
+
- [x] [简化手动更改版本号命令](#简化手动更改版本号命令)
|
|
17
|
+
- [x] [生成工作目录结构文件](#生成工作目录结构文件)
|
|
18
|
+
|
|
12
19
|
## 全局安装
|
|
13
20
|
|
|
14
21
|
```sh
|
|
@@ -50,17 +57,64 @@ git commit -m [描述]
|
|
|
50
57
|
git push
|
|
51
58
|
```
|
|
52
59
|
|
|
60
|
+
### 简化手动更改版本号命令
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
# 版本号自增
|
|
64
|
+
auto version++
|
|
65
|
+
# 或者指定具体的版本号
|
|
66
|
+
auto version@1.0.0
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 生成工作目录结构文件
|
|
70
|
+
|
|
71
|
+
- 可以在工作目录生成 `directory.md` 文件
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
auto mkdir
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- `directory.md`
|
|
78
|
+
|
|
79
|
+
```MD
|
|
80
|
+
├── mine-auto-cli
|
|
81
|
+
│ ├── src
|
|
82
|
+
│ │ └── commander
|
|
83
|
+
└ └── README.md
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- 通过 `-l, --line` 生成的结构文件带横线,默认数量为 `20`
|
|
87
|
+
- 通过 `-n, --name` 自定义生成的结构文件名称,默认名称为 `directory`
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
auto mkdir -l 10 -n demo
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- `demo.md`
|
|
94
|
+
|
|
95
|
+
```MD
|
|
96
|
+
├── mine-auto-cli ----------------------
|
|
97
|
+
│ ├── src ---------------------------
|
|
98
|
+
│ │ └── commander -----------------
|
|
99
|
+
└ └── README.md ----------------------
|
|
100
|
+
```
|
|
101
|
+
|
|
53
102
|
### 技术栈
|
|
54
103
|
|
|
55
104
|
- `Vite` + `TypeScript` + `Node`
|
|
56
105
|
|
|
57
106
|
### 依赖特性
|
|
58
107
|
|
|
108
|
+
#### dependencies
|
|
109
|
+
|
|
59
110
|
- `chalk`: 字体颜色
|
|
60
111
|
- `commander`: 命令
|
|
61
112
|
- `log-symbols`: 图标
|
|
62
113
|
- `ora`: 动画效果
|
|
63
114
|
- `update-notifier`: 检查更新
|
|
115
|
+
|
|
116
|
+
#### devDependencies
|
|
117
|
+
|
|
64
118
|
- `@types/node`: `node` 类型
|
|
65
119
|
- `@types/update-notifier`: `update-notifier` 类型
|
|
66
120
|
- `prettier`: 格式化工具
|
package/dist/index.js
CHANGED
|
@@ -1,144 +1,198 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { program as
|
|
4
|
-
import
|
|
5
|
-
import { execSync as
|
|
6
|
-
import
|
|
7
|
-
|
|
1
|
+
import N from "update-notifier";
|
|
2
|
+
import c from "chalk";
|
|
3
|
+
import { program as m } from "commander";
|
|
4
|
+
import q from "ora";
|
|
5
|
+
import { execSync as O } from "child_process";
|
|
6
|
+
import { readFileSync as k, writeFileSync as b, existsSync as G, readdirSync as P } from "fs";
|
|
7
|
+
import { join as u } from "path";
|
|
8
|
+
import A from "log-symbols";
|
|
9
|
+
const E = "mine-auto-cli", J = "2.2.0", B = "./dist/index.js", R = "./dist/index.js", U = "module", _ = {
|
|
8
10
|
auto: "bin/mine-auto-cli.js"
|
|
9
|
-
},
|
|
11
|
+
}, z = {
|
|
10
12
|
name: "biaov",
|
|
11
13
|
email: "biaov@qq.com",
|
|
12
14
|
url: "https://biaov.cn"
|
|
13
|
-
},
|
|
15
|
+
}, H = "一个将多个命令简化成一个命令的项目 😆", K = {
|
|
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
|
+
}, Q = {
|
|
20
22
|
registry: "https://registry.npmjs.org/"
|
|
21
|
-
},
|
|
22
|
-
node: ">=
|
|
23
|
-
},
|
|
23
|
+
}, W = {
|
|
24
|
+
node: ">=20"
|
|
25
|
+
}, X = [
|
|
24
26
|
"auto",
|
|
25
27
|
"cli",
|
|
26
28
|
"vite",
|
|
27
29
|
"typescript"
|
|
28
|
-
],
|
|
30
|
+
], Y = {
|
|
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
|
+
}, Z = "https://github.com/biaov/mine-auto-cli.git", ee = {
|
|
32
34
|
url: "https://github.com/biaov/mine-auto-cli/issues"
|
|
33
|
-
},
|
|
35
|
+
}, te = "ISC", oe = [
|
|
34
36
|
{
|
|
35
37
|
name: "biaov",
|
|
36
38
|
email: "biaov@qq.com"
|
|
37
39
|
}
|
|
38
|
-
],
|
|
40
|
+
], ne = {
|
|
39
41
|
chalk: "^5.3.0",
|
|
40
|
-
commander: "^
|
|
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: "^12.0.0",
|
|
43
|
+
"log-symbols": "^6.0.0",
|
|
44
|
+
ora: "^8.0.1",
|
|
45
|
+
"update-notifier": "^7.0.0"
|
|
46
|
+
}, se = {
|
|
47
|
+
"@types/node": "^20.11.30",
|
|
48
|
+
"@types/update-notifier": "^6.0.8",
|
|
49
|
+
prettier: "^3.2.5",
|
|
50
|
+
typescript: "^5.4.3",
|
|
51
|
+
vite: "^5.2.6"
|
|
52
|
+
}, f = {
|
|
53
|
+
name: E,
|
|
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: B,
|
|
57
|
+
main: R,
|
|
58
|
+
type: U,
|
|
59
|
+
bin: _,
|
|
60
|
+
author: z,
|
|
61
|
+
description: H,
|
|
62
|
+
scripts: K,
|
|
63
|
+
publishConfig: Q,
|
|
64
|
+
engines: W,
|
|
65
|
+
keywords: X,
|
|
66
|
+
repository: Y,
|
|
67
|
+
homepage: Z,
|
|
68
|
+
bugs: ee,
|
|
69
|
+
license: te,
|
|
70
|
+
contributors: oe,
|
|
71
|
+
dependencies: ne,
|
|
72
|
+
devDependencies: se
|
|
73
|
+
}, y = {}, ie = [
|
|
72
74
|
{
|
|
73
75
|
name: "success",
|
|
74
|
-
color:
|
|
76
|
+
color: c.green
|
|
75
77
|
},
|
|
76
78
|
{
|
|
77
79
|
name: "error",
|
|
78
|
-
color:
|
|
79
|
-
prefix:
|
|
80
|
+
color: c.red,
|
|
81
|
+
prefix: E
|
|
80
82
|
},
|
|
81
83
|
{
|
|
82
84
|
name: "warning",
|
|
83
|
-
color:
|
|
85
|
+
color: c.red
|
|
84
86
|
},
|
|
85
87
|
{
|
|
86
88
|
name: "info"
|
|
87
89
|
}
|
|
88
90
|
];
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (typeof
|
|
92
|
-
const { text:
|
|
93
|
-
|
|
91
|
+
ie.forEach(({ name: e, color: t, prefix: n = "" }) => {
|
|
92
|
+
y[e] = (o = "") => {
|
|
93
|
+
if (typeof o == "object") {
|
|
94
|
+
const { text: s = "", prefix: r = "" } = o;
|
|
95
|
+
s && console.log(`${r + " "}${o}`);
|
|
94
96
|
} else
|
|
95
|
-
console.log(
|
|
97
|
+
console.log(t ? `${n + " "}${t(e.toUpperCase())} ${o}` : o);
|
|
96
98
|
};
|
|
97
99
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
100
|
+
y.iconError = A.error;
|
|
101
|
+
y.iconSuccess = A.success;
|
|
102
|
+
const re = (e) => ["git add -A", `git commit -m ${e}`, "git push"], ce = (e, t) => [`npm run ${e}`, "git add -A", `git commit -m ${t}`, "git push"], { success: h, info: a, error: T } = y, F = (e) => {
|
|
103
|
+
a(`开始执行 ${c.cyanBright(e)} 命令`);
|
|
104
|
+
const t = q({ text: "正在执行命令中...", color: "yellow" });
|
|
105
|
+
t.start();
|
|
106
|
+
const n = O(e, { cwd: process.cwd() });
|
|
107
|
+
a(n.toString()), t.succeed(`${c.green(e)} 命令执行成功`), a();
|
|
108
|
+
}, ae = async (e = "更新代码") => {
|
|
109
|
+
a(), a(`${c.yellow(">>")} 开始依次执行命令...`), a(), re(e).forEach(F), h("全部命令执行完成"), a();
|
|
110
|
+
}, pe = async (e, t = "打包") => {
|
|
111
|
+
a(), a(`${c.yellow(">>")} 开始依次执行命令...`), a(), ce(e, t).map(F), h("全部命令执行完成"), a();
|
|
112
|
+
}, j = (e) => {
|
|
113
|
+
a(), T(`\`${e}\` 命令错误,请检查你的命令`), a(), m.help();
|
|
114
|
+
}, S = (e) => {
|
|
115
|
+
const t = ["package.json", "README.md"].map((r) => {
|
|
116
|
+
const i = u(process.cwd(), r), p = k(i).toString();
|
|
117
|
+
return { path: i, content: p };
|
|
118
|
+
}), [n, o] = t, s = JSON.parse(n.content);
|
|
119
|
+
if (e)
|
|
120
|
+
s.version = e;
|
|
121
|
+
else {
|
|
122
|
+
const r = s.version.split(".").reduce((i, p, l, d) => i + (l === d.length - 1 ? +p + 1 : `${p}.`), "");
|
|
123
|
+
s.version = r;
|
|
124
|
+
}
|
|
125
|
+
b(n.path, JSON.stringify(s, null, 2)), o.content = o.content.replace(/version\-v.+\-blue/, () => `version-v${s.version}-blue`), b(o.path, o.content);
|
|
126
|
+
}, le = async (e) => {
|
|
127
|
+
const t = e.split("version")[1];
|
|
128
|
+
if (!t)
|
|
129
|
+
return j(e);
|
|
130
|
+
const n = JSON.parse(k(u(process.cwd(), "package.json"), "utf-8"));
|
|
131
|
+
if (t === "++") {
|
|
132
|
+
const s = n.version.split(".").reduce((r, i, p, l) => r + (p === l.length - 1 ? +i + 1 : `${i}.`), "");
|
|
133
|
+
S(s), a(), h("命令执行完成");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const o = t.split("@")[1];
|
|
137
|
+
o ? (S(o), a(), h("命令执行完成")) : j(e);
|
|
138
|
+
}, me = (e, t) => {
|
|
139
|
+
if (console.log(e.includes("mkdir"), "--"), e.includes("build"))
|
|
140
|
+
return pe(e, t);
|
|
141
|
+
if (e.includes("version"))
|
|
142
|
+
return le(e);
|
|
143
|
+
T(c.hex("#f56c6c")(`\`auto ${e}${t ? ` ${t}` : ""}\` 命令不存在`)), m.help();
|
|
144
|
+
}, V = ["dist", "node_modules", ".git", "miniprogram_npm"];
|
|
145
|
+
let v = 0, I = !1, $ = !1, L = 20;
|
|
146
|
+
const C = ({ prev: e, i: t, index: n, arr: o, curText: s }) => {
|
|
147
|
+
const r = Array.from({ length: t }).reduce((d) => d + `${t === 1 && n === o.length - 1 ? "└ " : "│ "} `, ""), i = e + r, p = (r + s).length, l = Array.from({ length: L + v - p }).reduce((d) => `${d}-`, " ");
|
|
148
|
+
return !I && (v = Math.max(v, p)), `${i}${s}${$ ? l : ""}
|
|
149
|
+
`;
|
|
150
|
+
}, w = (e, t = 0) => e.reduce((n, o, s, r) => {
|
|
151
|
+
let i;
|
|
152
|
+
return o.children ? (i = `├── ${o.name}`, C({ prev: n, i: t, index: s, arr: r, curText: i }) + w(o.children, t + 1)) : (i = `${s === r.length - 1 ? "└── " : "├── "}${o.name}`, C({ prev: n, i: t, index: s, arr: r, curText: i }));
|
|
153
|
+
}, ""), D = (e) => P(e, { withFileTypes: !0 }).sort((t, n) => +n.isDirectory() - +t.isDirectory()), de = ({ line: e, name: t }) => {
|
|
154
|
+
$ = !!e, typeof e == "string" && (L = +e);
|
|
155
|
+
const n = process.cwd(), o = u(n, ".gitignore");
|
|
156
|
+
if (G(o)) {
|
|
157
|
+
const l = k(o, { encoding: "utf-8" }).split(`\r
|
|
158
|
+
`);
|
|
159
|
+
V.push(...l);
|
|
160
|
+
}
|
|
161
|
+
const s = n.split("\\").at(-1), i = D(n).map((l) => {
|
|
162
|
+
const { name: d } = l, x = { name: d };
|
|
163
|
+
return !V.includes(d) && l.isDirectory() && (x.children = D(u(l.path, d)).map(({ name: M }) => ({ name: M }))), x;
|
|
164
|
+
}), p = [{ name: s, children: i }];
|
|
165
|
+
$ && (w(p), I = !0), b(u(n, `${typeof t == "string" && t || "directory"}.md`), w(p));
|
|
114
166
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
167
|
+
m.usage("[commands] [options]").version(J, "-v, --version", "输出版本号").helpOption("-h, --help", "输出所有命令");
|
|
168
|
+
m.command("git [描述]").description("简化 Git 提交命令").action(ae);
|
|
169
|
+
m.command("build[:环境] [描述]").description("简化打包提交命令");
|
|
170
|
+
m.command("version<[++]|[@<版本号>]>").description("例如:version++ 或者 version@1.0.0;自动更新 package.json 版本号,自动更新 `README.md` 中的 `version-v<version>-blue` 图标版本");
|
|
171
|
+
m.command("mkdir").option("-l, --line [数量]", "数量", !1).option("-n, --name [文件名称]", "文件名称", !1).description("生成目录结构文件").action(de);
|
|
172
|
+
m.arguments("<cmd> [env]").action((e, t) => {
|
|
173
|
+
me(e, t);
|
|
120
174
|
});
|
|
121
|
-
process.argv.length < 3 ?
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
175
|
+
process.argv.length < 3 ? m.help() : m.parse(process.argv);
|
|
176
|
+
const g = N({ pkg: f });
|
|
177
|
+
if (g.update && g.update.latest !== f.version) {
|
|
124
178
|
let e = "";
|
|
125
|
-
switch (
|
|
179
|
+
switch (g.update.type) {
|
|
126
180
|
case "major":
|
|
127
|
-
e =
|
|
181
|
+
e = c.red("{latestVersion}");
|
|
128
182
|
break;
|
|
129
183
|
case "minor":
|
|
130
|
-
e =
|
|
184
|
+
e = c.yellow("{latestVersion}");
|
|
131
185
|
break;
|
|
132
186
|
default:
|
|
133
|
-
e =
|
|
187
|
+
e = c.green("{latestVersion}");
|
|
134
188
|
break;
|
|
135
189
|
}
|
|
136
|
-
const
|
|
137
|
-
|
|
190
|
+
const t = `https://github.com/biaov/${f.name}/compare/v${f.version}...v{latestVersion}`;
|
|
191
|
+
g.notify({
|
|
138
192
|
defer: !1,
|
|
139
193
|
isGlobal: !0,
|
|
140
|
-
message: `有更新 ${
|
|
141
|
-
运行 ${
|
|
142
|
-
${
|
|
194
|
+
message: `有更新 ${c.dim("{currentVersion}")}${c.reset(" → ")}${e}
|
|
195
|
+
运行 ${c.cyan("{updateCommand}")} 命令更新
|
|
196
|
+
${c.dim.underline(t)}`
|
|
143
197
|
});
|
|
144
198
|
}
|
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.2.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": "^
|
|
48
|
-
"log-symbols": "^
|
|
49
|
-
"ora": "^
|
|
50
|
-
"update-notifier": "^
|
|
47
|
+
"commander": "^12.0.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
|
}
|