mine-auto-cli 2.1.0 → 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.
Files changed (3) hide show
  1. package/README.md +45 -0
  2. package/dist/index.js +134 -111
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -9,6 +9,13 @@
9
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
@@ -59,17 +66,55 @@ auto version++
59
66
  auto version@1.0.0
60
67
  ```
61
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
+
62
102
  ### 技术栈
63
103
 
64
104
  - `Vite` + `TypeScript` + `Node`
65
105
 
66
106
  ### 依赖特性
67
107
 
108
+ #### dependencies
109
+
68
110
  - `chalk`: 字体颜色
69
111
  - `commander`: 命令
70
112
  - `log-symbols`: 图标
71
113
  - `ora`: 动画效果
72
114
  - `update-notifier`: 检查更新
115
+
116
+ #### devDependencies
117
+
73
118
  - `@types/node`: `node` 类型
74
119
  - `@types/update-notifier`: `update-notifier` 类型
75
120
  - `prettier`: 格式化工具
package/dist/index.js CHANGED
@@ -1,175 +1,198 @@
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 = {
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", _ = {
10
10
  auto: "bin/mine-auto-cli.js"
11
- }, O = {
11
+ }, z = {
12
12
  name: "biaov",
13
13
  email: "biaov@qq.com",
14
14
  url: "https://biaov.cn"
15
- }, F = "一个将多个命令简化成一个命令的项目 😆", G = {
15
+ }, H = "一个将多个命令简化成一个命令的项目 😆", K = {
16
16
  start: "npm run dev",
17
17
  dev: "npm run build -- --watch",
18
18
  build: "node scripts/build && vite build",
19
19
  prettier: "prettier --write '**/*.{js,ts,md,json}'",
20
20
  ncu: "ncu --configFileName .ncurc.json && npm i"
21
- }, I = {
21
+ }, Q = {
22
22
  registry: "https://registry.npmjs.org/"
23
- }, T = {
23
+ }, W = {
24
24
  node: ">=20"
25
- }, B = [
25
+ }, X = [
26
26
  "auto",
27
27
  "cli",
28
28
  "vite",
29
29
  "typescript"
30
- ], M = {
30
+ ], Y = {
31
31
  type: "git",
32
32
  url: "git+https://github.com/biaov/mine-auto-cli.git"
33
- }, R = "https://github.com/biaov/mine-auto-cli.git", U = {
33
+ }, Z = "https://github.com/biaov/mine-auto-cli.git", ee = {
34
34
  url: "https://github.com/biaov/mine-auto-cli/issues"
35
- }, L = "ISC", P = [
35
+ }, te = "ISC", oe = [
36
36
  {
37
37
  name: "biaov",
38
38
  email: "biaov@qq.com"
39
39
  }
40
- ], z = {
40
+ ], ne = {
41
41
  chalk: "^5.3.0",
42
- commander: "^11.1.0",
42
+ commander: "^12.0.0",
43
43
  "log-symbols": "^6.0.0",
44
44
  ora: "^8.0.1",
45
45
  "update-notifier": "^7.0.0"
46
- }, H = {
47
- "@types/node": "^20.11.13",
46
+ }, se = {
47
+ "@types/node": "^20.11.30",
48
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,
49
+ prettier: "^3.2.5",
50
+ typescript: "^5.4.3",
51
+ vite: "^5.2.6"
52
+ }, f = {
53
+ name: E,
54
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 = [
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 = [
74
74
  {
75
75
  name: "success",
76
- color: s.green
76
+ color: c.green
77
77
  },
78
78
  {
79
79
  name: "error",
80
- color: s.red,
81
- prefix: k
80
+ color: c.red,
81
+ prefix: E
82
82
  },
83
83
  {
84
84
  name: "warning",
85
- color: s.red
85
+ color: c.red
86
86
  },
87
87
  {
88
88
  name: "info"
89
89
  }
90
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}`);
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}`);
96
96
  } else
97
- console.log(o ? `${c + " "}${o(e.toUpperCase())} ${t}` : t);
97
+ console.log(t ? `${n + " "}${t(e.toUpperCase())} ${o}` : o);
98
98
  };
99
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);
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
119
  if (e)
120
- i.version = e;
120
+ s.version = e;
121
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;
122
+ const r = s.version.split(".").reduce((i, p, l, d) => i + (l === d.length - 1 ? +p + 1 : `${p}.`), "");
123
+ s.version = r;
124
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("命令执行完成");
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
134
  return;
135
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);
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
141
  if (e.includes("version"))
142
- return Z(e);
143
- S(s.hex("#f56c6c")(`\`auto ${e}${o ? ` ${o}` : ""}\` 命令不存在`)), r.help();
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));
144
166
  };
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);
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);
151
174
  });
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) {
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) {
155
178
  let e = "";
156
- switch (m.update.type) {
179
+ switch (g.update.type) {
157
180
  case "major":
158
- e = s.red("{latestVersion}");
181
+ e = c.red("{latestVersion}");
159
182
  break;
160
183
  case "minor":
161
- e = s.yellow("{latestVersion}");
184
+ e = c.yellow("{latestVersion}");
162
185
  break;
163
186
  default:
164
- e = s.green("{latestVersion}");
187
+ e = c.green("{latestVersion}");
165
188
  break;
166
189
  }
167
- const o = `https://github.com/biaov/${u.name}/compare/v${u.version}...v{latestVersion}`;
168
- m.notify({
190
+ const t = `https://github.com/biaov/${f.name}/compare/v${f.version}...v{latestVersion}`;
191
+ g.notify({
169
192
  defer: !1,
170
193
  isGlobal: !0,
171
- message: `有更新 ${s.dim("{currentVersion}")}${s.reset(" → ")}${e}
172
- 运行 ${s.cyan("{updateCommand}")} 命令更新
173
- ${s.dim.underline(o)}`
194
+ message: `有更新 ${c.dim("{currentVersion}")}${c.reset(" → ")}${e}
195
+ 运行 ${c.cyan("{updateCommand}")} 命令更新
196
+ ${c.dim.underline(t)}`
174
197
  });
175
198
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mine-auto-cli",
3
3
  "private": false,
4
- "version": "2.1.0",
4
+ "version": "2.2.0",
5
5
  "exports": "./dist/index.js",
6
6
  "main": "./dist/index.js",
7
7
  "type": "module",
@@ -44,7 +44,7 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "chalk": "^5.3.0",
47
- "commander": "^11.1.0",
47
+ "commander": "^12.0.0",
48
48
  "log-symbols": "^6.0.0",
49
49
  "ora": "^8.0.1",
50
50
  "update-notifier": "^7.0.0"