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.
Files changed (3) hide show
  1. package/README.md +13 -4
  2. package/dist/index.js +121 -90
  3. 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 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.3", $ = "./dist/index.js", w = "./dist/index.js", j = "module", x = {
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
- }, k = {
11
+ }, O = {
10
12
  name: "biaov",
11
13
  email: "biaov@qq.com",
12
14
  url: "https://biaov.cn"
13
- }, C = "一个将多个命令简化成一个命令的项目 😆", S = {
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
- }, V = {
21
+ }, I = {
20
22
  registry: "https://registry.npmjs.org/"
21
- }, q = {
22
- node: ">=16"
23
- }, A = [
23
+ }, T = {
24
+ node: ">=20"
25
+ }, B = [
24
26
  "auto",
25
27
  "cli",
26
28
  "vite",
27
29
  "typescript"
28
- ], E = {
30
+ ], M = {
29
31
  type: "git",
30
- url: "https://github.com/biaov/mine-auto-cli.git"
31
- }, G = "https://github.com/biaov/mine-auto-cli.git", B = {
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
- }, D = "ISC", T = [
35
+ }, L = "ISC", P = [
34
36
  {
35
37
  name: "biaov",
36
38
  email: "biaov@qq.com"
37
39
  }
38
- ], U = {
40
+ ], z = {
39
41
  chalk: "^5.3.0",
40
- commander: "^11.0.0",
41
- "log-symbols": "^5.1.0",
42
- ora: "^7.0.1",
43
- "update-notifier": "^6.0.2"
44
- }, F = {
45
- "@types/node": "^20.8.4",
46
- "@types/update-notifier": "^6.0.5",
47
- prettier: "^3.0.3",
48
- typescript: "^5.2.2",
49
- vite: "^4.4.11"
50
- }, c = {
51
- name: l,
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: d,
54
- exports: $,
55
- main: w,
56
- type: j,
57
- bin: x,
58
- author: k,
59
- description: C,
60
- scripts: S,
61
- publishConfig: V,
62
- engines: q,
63
- keywords: A,
64
- repository: E,
65
- homepage: G,
66
- bugs: B,
67
- license: D,
68
- contributors: T,
69
- dependencies: U,
70
- devDependencies: F
71
- }, a = {}, I = [
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: t.green
76
+ color: s.green
75
77
  },
76
78
  {
77
79
  name: "error",
78
- color: t.red,
79
- prefix: l
80
+ color: s.red,
81
+ prefix: k
80
82
  },
81
83
  {
82
84
  name: "warning",
83
- color: t.red
85
+ color: s.red
84
86
  },
85
87
  {
86
88
  name: "info"
87
89
  }
88
90
  ];
89
- I.forEach(({ name: e, color: o, prefix: p = "" }) => {
90
- a[e] = (n = "") => {
91
- if (typeof n == "object") {
92
- const { text: b = "", prefix: h = "" } = n;
93
- b && console.log(`${h + " "}${n}`);
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 ? `${p + " "}${o(e.toUpperCase())} ${n}` : n);
97
+ console.log(o ? `${c + " "}${o(e.toUpperCase())} ${t}` : t);
96
98
  };
97
99
  });
98
- a.iconError = m.error;
99
- a.iconSuccess = m.success;
100
- 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) => {
101
- s(`开始执行 ${t.cyanBright(e)} 命令`);
102
- const o = y({ text: "正在执行命令中...", color: "yellow" });
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 p = v(e, { cwd: process.cwd() });
105
- s(p.toString()), o.succeed(`${t.green(e)} 命令执行成功`), s();
106
- }, z = async (e = "更新代码") => {
107
- s(), s(`${t.yellow(">>")} 开始依次执行命令...`), s(), N(e).forEach(g), u("全部命令执行完成"), s();
108
- }, H = async (e, o = "打包") => {
109
- s(), s(`${t.yellow(">>")} 开始依次执行命令...`), s(), O(e, o).map(g), u("全部命令执行完成"), s();
110
- }, J = (e, o) => {
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 H(e, o);
113
- P(t.hex("#f56c6c")(`\`auto ${e}${o ? ` ${o}` : ""}\` 命令不存在`)), i.help();
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
- i.usage("[commands] [options]").version(d, "-v, --version", "输出版本号").helpOption("-h, --help", "输出所有命令");
116
- i.command("git [描述]").description("简化 Git 提交命令").action(z);
117
- i.command("build[:环境] [描述]").description("简化打包提交命令");
118
- i.arguments("<cmd> [env]").action((e, o) => {
119
- J(e, o);
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 ? i.help() : i.parse(process.argv);
122
- const r = f({ pkg: c });
123
- if (r.update && r.update.latest !== c.version) {
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 (r.update.type) {
156
+ switch (m.update.type) {
126
157
  case "major":
127
- e = t.red("{latestVersion}");
158
+ e = s.red("{latestVersion}");
128
159
  break;
129
160
  case "minor":
130
- e = t.yellow("{latestVersion}");
161
+ e = s.yellow("{latestVersion}");
131
162
  break;
132
163
  default:
133
- e = t.green("{latestVersion}");
164
+ e = s.green("{latestVersion}");
134
165
  break;
135
166
  }
136
- const o = `https://github.com/biaov/${c.name}/compare/v${c.version}...v{latestVersion}`;
137
- r.notify({
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: `有更新 ${t.dim("{currentVersion}")}${t.reset(" → ")}${e}
141
- 运行 ${t.cyan("{updateCommand}")} 命令更新
142
- ${t.dim.underline(o)}`
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.3",
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": ">=16"
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.0.0",
48
- "log-symbols": "^5.1.0",
49
- "ora": "^7.0.1",
50
- "update-notifier": "^6.0.2"
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
  }