@done-coding/cli-publish 0.3.6 → 0.4.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/es/handler.mjs CHANGED
@@ -1,107 +1,194 @@
1
1
  #!/usr/bin/env node
2
- import { PublishModeEnum as h } from "./utils/types.mjs";
3
- import { inc as p, prerelease as S } from "semver";
4
- import { join as u } from "node:path";
2
+ import { PublishModeEnum as v } from "./utils/types.mjs";
3
+ import { PublishVersionTypeEnum as e, PublishTagEnum as P } from "./utils/enums.mjs";
4
+ import { inc as f, prerelease as N } from "semver";
5
+ import { join as h } from "node:path";
5
6
  import { execSync as o } from "node:child_process";
6
- import f from "pinyin";
7
- import { readFileSync as y, existsSync as d } from "node:fs";
8
- import c from "chalk";
9
- const w = "/.dc/publish.json", $ = "/package.json", b = ({ gitOriginName: r = "origin" }) => {
7
+ import u from "pinyin";
8
+ import { readFileSync as A, existsSync as S } from "node:fs";
9
+ import p from "chalk";
10
+ import $ from "prompts";
11
+ const d = "/.dc/publish.json", O = "/package.json", w = ({ gitOriginName: i = "origin" }) => {
10
12
  try {
11
- const i = o("git rev-parse HEAD").toString().trim(), s = o('git log -1 --pretty=format:"%an"').toString().trim(), a = o('git log -1 --pretty=format:"%ae"').toString().trim(), t = o('git log -1 --pretty=format:"%s"').toString().trim(), n = o("git config user.name").toString().trim(), e = o("git config user.email").toString().trim(), g = o("git rev-parse --abbrev-ref HEAD").toString().trim();
12
- let l = "";
13
+ const n = o("git rev-parse HEAD").toString().trim(), m = o('git log -1 --pretty=format:"%an"').toString().trim(), a = o('git log -1 --pretty=format:"%ae"').toString().trim(), s = o('git log -1 --pretty=format:"%s"').toString().trim(), r = o("git config user.name").toString().trim(), c = o("git config user.email").toString().trim(), g = o("git rev-parse --abbrev-ref HEAD").toString().trim();
14
+ let R = "";
13
15
  try {
14
- l = o(`git config --get remote.${r}.url`).toString().trim();
16
+ R = o(`git config --get remote.${i}.url`).toString().trim();
15
17
  } catch {
16
- throw new Error(`git remote ${r} 不存在`);
18
+ throw new Error(`git remote ${i} 不存在`);
17
19
  }
18
20
  return {
19
- lastHash: i,
20
- lastCommitter: s,
21
- lastCommitterPinYin: f(s, {
22
- style: f.STYLE_NORMAL,
21
+ lastHash: n,
22
+ lastCommitter: m,
23
+ lastCommitterPinYin: u(m, {
24
+ style: u.STYLE_NORMAL,
23
25
  heteronym: !1
24
26
  }).join(""),
25
27
  lastCommitEmail: a,
26
- lastCommitMsg: t,
27
- userName: n,
28
- userNamePinYin: f(n, {
29
- style: f.STYLE_NORMAL,
28
+ lastCommitMsg: s,
29
+ userName: r,
30
+ userNamePinYin: u(r, {
31
+ style: u.STYLE_NORMAL,
30
32
  heteronym: !1
31
33
  }).join(""),
32
- userEmail: e,
34
+ userEmail: c,
33
35
  branchName: g,
34
- remoteUrl: l
36
+ remoteUrl: R
35
37
  };
36
- } catch (i) {
37
- throw console.error("Error fetching git information:", i), i;
38
+ } catch (n) {
39
+ throw console.error("Error fetching git information:", n), n;
38
40
  }
39
- }, v = async (r) => {
40
- const i = y(u(process.cwd(), $), "utf-8"), s = JSON.parse(i);
41
- let a = s.name, t = "", n;
42
- const { version: e } = s;
43
- if (["major", "minor", "patch"].includes(r))
44
- t = p(e, r), n = "latest";
45
- else if (["premajor", "preminor", "prepatch"].includes(r)) {
46
- const g = S(e);
47
- g ? (console.log(
48
- c.yellow("当前版本已经是预发布版本,将会在当前版本基础上进行发布")
49
- ), g.length === 1 && typeof g[0] == "number" ? t = p(e, "prerelease") : t = e.split("-")[0] + "-0") : t = p(e, r), n = "next";
41
+ }, E = (i, n = JSON.parse(A(h(process.cwd(), O), "utf-8"))) => {
42
+ let m = n.name, a = "", s;
43
+ const { version: r } = n;
44
+ if ([
45
+ e.MAJOR,
46
+ e.MINOR,
47
+ e.PATCH
48
+ ].includes(i))
49
+ a = f(r, i), s = P.LATEST;
50
+ else if ([
51
+ e.PREMAJOR,
52
+ e.PREMINOR,
53
+ e.PREPATCH
54
+ ].includes(i)) {
55
+ const c = N(r);
56
+ c ? (console.log(
57
+ p.yellow("当前版本已经是预发布版本,将会在当前版本基础上进行发布")
58
+ ), c.length === 1 && typeof c[0] == "number" ? a = f(
59
+ r,
60
+ e.PRERELEASE
61
+ ) : a = r.split("-")[0] + "-0") : a = f(r, i), s = P.NEXT;
50
62
  } else
51
- n = "alpha", t = p(e, "prerelease", n);
52
- if (!t)
63
+ s = P.ALPHA, a = f(
64
+ r,
65
+ e.PRERELEASE,
66
+ s
67
+ );
68
+ if (!a)
53
69
  throw new Error("version is empty");
54
70
  return {
55
- name: a,
56
- version: t,
57
- tag: n
71
+ name: m,
72
+ version: a,
73
+ tag: s
58
74
  };
59
- }, N = () => {
60
- let r;
61
- const i = u(process.cwd(), w);
62
- if (d(i)) {
63
- const s = y(i, "utf-8");
64
- r = JSON.parse(s);
75
+ }, I = () => {
76
+ let i;
77
+ const n = h(process.cwd(), d);
78
+ if (S(n)) {
79
+ const m = A(n, "utf-8");
80
+ i = JSON.parse(m);
65
81
  } else
66
82
  console.log(
67
- c.yellow(`未找到配置文件,将使用默认配置
83
+ p.yellow(`未找到配置文件,将使用默认配置
68
84
  { gitOriginName: "origin" }
69
85
  `)
70
86
  );
71
87
  return {
72
88
  gitOriginName: "origin",
73
- ...r || {}
89
+ ...i || {}
74
90
  };
75
- }, C = async (r) => {
76
- console.log(r);
77
- const { mode: i, type: s, push: a } = r, t = N(), n = b(t);
78
- console.log("type:", s), console.log("gitInfo:", n);
79
- const e = await v(s), { version: g } = e;
80
- console.log("npmInfo:", e), o(`npm version ${g} 1>&2`);
91
+ }, k = async (i) => {
92
+ console.log(i);
93
+ const { mode: n, type: m, push: a } = i, s = I(), r = w(s);
94
+ console.log("gitInfo:", r);
95
+ let c = m, g;
96
+ if (c)
97
+ console.log("type:", c), g = await E(c);
98
+ else {
99
+ const t = JSON.parse(A(h(process.cwd(), O), "utf-8")), l = {
100
+ [e.MAJOR]: E(
101
+ e.MAJOR,
102
+ t
103
+ ),
104
+ [e.MINOR]: E(
105
+ e.MINOR,
106
+ t
107
+ ),
108
+ [e.PATCH]: E(
109
+ e.PATCH,
110
+ t
111
+ ),
112
+ [e.PREMAJOR]: E(
113
+ e.PREMAJOR,
114
+ t
115
+ ),
116
+ [e.PREMINOR]: E(
117
+ e.PREMINOR,
118
+ t
119
+ ),
120
+ [e.PREPATCH]: E(
121
+ e.PREPATCH,
122
+ t
123
+ ),
124
+ [e.PRERELEASE]: E(
125
+ e.PRERELEASE,
126
+ t
127
+ )
128
+ }, y = [
129
+ {
130
+ title: `主版本(${l[e.MAJOR].version})`,
131
+ value: e.MAJOR
132
+ },
133
+ {
134
+ title: `次版本(${l[e.MINOR].version})`,
135
+ value: e.MINOR
136
+ },
137
+ {
138
+ title: `修订版本(${l[e.PATCH].version})`,
139
+ value: e.PATCH
140
+ },
141
+ {
142
+ title: `预发布主版本(${l[e.PREMAJOR].version})`,
143
+ value: e.PREMAJOR
144
+ },
145
+ {
146
+ title: `预发布次版本(${l[e.PREMINOR].version})`,
147
+ value: e.PREMINOR
148
+ },
149
+ {
150
+ title: `预发布修订版本(${l[e.PREPATCH].version})`,
151
+ value: e.PREPATCH
152
+ },
153
+ {
154
+ title: `alpha版本(${l[e.PRERELEASE].version})`,
155
+ value: e.PRERELEASE
156
+ }
157
+ ];
158
+ c = (await $({
159
+ type: "select",
160
+ name: "type",
161
+ message: `请选择发布类型,当前版本:${t.version}`,
162
+ choices: y,
163
+ validate: (M) => M ? !0 : "请选择发布类型"
164
+ })).type, g = l[c];
165
+ }
166
+ const { version: R } = g;
167
+ console.log("npmInfo:", g), o(`npm version ${R} 1>&2`);
81
168
  try {
82
- if (i === h.NPM) {
83
- const { tag: l } = e;
84
- o(`npm publish --tag ${l} 1>&2`);
85
- } else if (i === h.WEB) {
86
- const { webBuild: l } = t;
87
- l ? o(`${l} 1>&2`) : console.log(c.yellow("webBuild为空,不执行web构建"));
169
+ if (n === v.NPM) {
170
+ const { tag: t } = g;
171
+ o(`npm publish --tag ${t} 1>&2`);
172
+ } else if (n === v.WEB) {
173
+ const { webBuild: t } = s;
174
+ t ? o(`${t} 1>&2`) : console.log(p.yellow("webBuild为空,不执行web构建"));
88
175
  } else
89
176
  throw new Error("未知命令");
90
- } catch (l) {
91
- console.log(c.red(`发布失败, error: ${l.message}`));
177
+ } catch (t) {
178
+ console.log(p.red(`发布失败, error: ${t.message}`));
92
179
  try {
93
180
  console.log(
94
- c.blue(`回滚本地版本到发布前的版本:${n.lastHash}`)
181
+ p.blue(`回滚本地版本到发布前的版本:${r.lastHash}`)
95
182
  );
96
- const { lastHash: m } = n;
97
- o(`git reset --hard ${m} 1>&2`), console.log(c.blue(`删除本次发布时生成的tag:v${e.version}`)), o(`git tag -d v${e.version} 1>&2`);
98
- } catch (m) {
99
- console.log(c.red(`回滚失败, error: ${m.message}`));
183
+ const { lastHash: l } = r;
184
+ o(`git reset --hard ${l} 1>&2`), console.log(p.blue(`删除本次发布时生成的tag:v${g.version}`)), o(`git tag -d v${g.version} 1>&2`);
185
+ } catch (l) {
186
+ console.log(p.red(`回滚失败, error: ${l.message}`));
100
187
  }
101
188
  return process.exit(1);
102
189
  }
103
- a && (o(`git push ${t.gitOriginName} v${e.version} 1>&2`), o(`git push ${t.gitOriginName} ${n.branchName} 1>&2`)), console.log(c.green("发布成功"));
190
+ a && (o(`git push ${s.gitOriginName} v${g.version} 1>&2`), o(`git push ${s.gitOriginName} ${r.branchName} 1>&2`)), console.log(p.green("发布成功"));
104
191
  };
105
192
  export {
106
- C as handler
193
+ k as handler
107
194
  };
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  const n = {
3
- version: "0.3.6",
3
+ version: "0.4.0",
4
4
  name: "@done-coding/cli-publish",
5
5
  description: "项目发布命令行工具",
6
6
  cliConfig: {
package/es/main.mjs CHANGED
@@ -1,22 +1,30 @@
1
1
  #!/usr/bin/env node
2
- import m from "yargs";
3
- import { hideBin as l } from "yargs/helpers";
4
- import { PublishModeEnum as s } from "./utils/types.mjs";
2
+ import l from "yargs";
3
+ import { hideBin as p } from "yargs/helpers";
4
+ import { PublishModeEnum as i } from "./utils/types.mjs";
5
+ import { PublishVersionTypeEnum as e } from "./utils/enums.mjs";
5
6
  import { handler as t } from "./handler.mjs";
6
- import n from "chalk";
7
- import i from "./injectInfo.json.mjs";
7
+ import r from "chalk";
8
+ import n from "./injectInfo.json.mjs";
8
9
  const d = () => ({
9
10
  mode: {
10
11
  alias: "m",
11
12
  describe: "发布模式",
12
- choices: [s.NPM, s.WEB],
13
- default: s.NPM
13
+ choices: [i.NPM, i.WEB],
14
+ default: i.NPM
14
15
  },
15
16
  type: {
16
17
  alias: "t",
17
18
  describe: "发布类型",
18
- choices: ["major", "minor", "patch"],
19
- default: "patch"
19
+ choices: [
20
+ e.MAJOR,
21
+ e.MINOR,
22
+ e.PATCH,
23
+ e.PREMAJOR,
24
+ e.PREMINOR,
25
+ e.PREPATCH,
26
+ e.PRERELEASE
27
+ ]
20
28
  },
21
29
  push: {
22
30
  alias: "p",
@@ -24,21 +32,21 @@ const d = () => ({
24
32
  type: "boolean",
25
33
  default: !0
26
34
  }
27
- }), r = i.cliConfig.moduleName, p = (o, e) => {
28
- console.log(o ? n.red(o) : n.red(e.message)), process.exit(1);
29
- }, u = i.description, f = `Usage: $0 ${r} [options]`, g = "Usage: $0 [options]", a = (o, e) => {
30
- const c = d();
31
- return o.strict().usage(e).help("help").version(i.version).alias("v", "version").alias("h", "help").options(c).fail(p).argv;
32
- }, h = (o) => a(o, f), M = {
33
- command: r,
34
- describe: u,
35
- builder: h,
35
+ }), a = n.cliConfig.moduleName, u = (o, s) => {
36
+ console.log(o ? r.red(o) : r.red(s.message)), process.exit(1);
37
+ }, f = n.description, g = `Usage: $0 ${a} [options]`, h = "Usage: $0 [options]", c = (o, s) => {
38
+ const m = d();
39
+ return o.strict().usage(s).help("help").version(n.version).alias("v", "version").alias("h", "help").options(m).fail(u).argv;
40
+ }, E = (o) => c(o, g), y = {
41
+ command: a,
42
+ describe: f,
43
+ builder: E,
36
44
  handler: t
37
- }, P = async () => {
38
- const o = m(l(process.argv)), e = await a(o, g);
39
- return t(e);
45
+ }, A = async () => {
46
+ const o = l(p(process.argv)), s = await c(o, h);
47
+ return t(s);
40
48
  };
41
49
  export {
42
- M as command,
43
- P as createCli
50
+ y as command,
51
+ A as createCli
44
52
  };
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ var R = /* @__PURE__ */ ((r) => (r.MAJOR = "major", r.MINOR = "minor", r.PATCH = "patch", r.PREMAJOR = "premajor", r.PREMINOR = "preminor", r.PREPATCH = "prepatch", r.PRERELEASE = "prerelease", r))(R || {}), a = /* @__PURE__ */ ((r) => (r.LATEST = "latest", r.NEXT = "next", r.ALPHA = "alpha", r))(a || {});
3
+ export {
4
+ a as PublishTagEnum,
5
+ R as PublishVersionTypeEnum
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-publish",
3
- "version": "0.3.6",
3
+ "version": "0.4.0",
4
4
  "description": "项目发布命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -41,7 +41,7 @@
41
41
  "license": "MIT",
42
42
  "sideEffects": false,
43
43
  "devDependencies": {
44
- "@done-coding/cli-inject": "^0.4.1",
44
+ "@done-coding/cli-inject": "^0.4.2",
45
45
  "@types/node": "^18.0.0",
46
46
  "@types/pinyin": "^2.10.0",
47
47
  "@types/prompts": "^2.4.6",
@@ -62,5 +62,5 @@
62
62
  "semver": "^7.5.4",
63
63
  "yargs": "^17.7.2"
64
64
  },
65
- "gitHead": "1778df27cf625b5588b1de38d260cfed75e123f2"
65
+ "gitHead": "eb3732e50f528b2c838af6303d774d6d04cf5f37"
66
66
  }
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- "version": "0.3.6",
2
+ "version": "0.4.0",
3
3
  "name": "@done-coding/cli-publish",
4
4
  "description": "项目发布命令行工具",
5
5
  "cliConfig": {
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 发布版本类型
3
+ */
4
+ export declare enum PublishVersionTypeEnum {
5
+ /**
6
+ * 主版本号
7
+ */
8
+ MAJOR = "major",
9
+ /**
10
+ * 次版本号
11
+ */
12
+ MINOR = "minor",
13
+ /**
14
+ * 修订版本号
15
+ */
16
+ PATCH = "patch",
17
+ /**
18
+ * 预发布版本号
19
+ */
20
+ PREMAJOR = "premajor",
21
+ /**
22
+ * 预发布次版本号
23
+ */
24
+ PREMINOR = "preminor",
25
+ /**
26
+ * 预发布修订版本号
27
+ */
28
+ PREPATCH = "prepatch",
29
+ /**
30
+ * 预发布版本号
31
+ */
32
+ PRERELEASE = "prerelease"
33
+ }
34
+ /**
35
+ * 发布标签类型
36
+ */
37
+ export declare enum PublishTagEnum {
38
+ /**
39
+ * 最新版本
40
+ */
41
+ LATEST = "latest",
42
+ /**
43
+ * next版本
44
+ */
45
+ NEXT = "next",
46
+ /**
47
+ * alpha版本
48
+ */
49
+ ALPHA = "alpha"
50
+ }
@@ -1 +1,2 @@
1
1
  export * from "./types";
2
+ export * from "./enums";
@@ -1,4 +1,4 @@
1
- import type { ReleaseType } from "semver";
1
+ import type { PublishTagEnum, PublishVersionTypeEnum } from "./enums";
2
2
  /**
3
3
  * git仓库信息
4
4
  */
@@ -59,7 +59,7 @@ export interface NpmInfo {
59
59
  /**
60
60
  * 标签
61
61
  */
62
- tag: "latest" | "next" | "alpha";
62
+ tag: PublishTagEnum;
63
63
  }
64
64
  /**
65
65
  * 配置信息
@@ -87,7 +87,7 @@ export interface Options {
87
87
  /**
88
88
  * 发布类型
89
89
  */
90
- type: ReleaseType;
90
+ type?: PublishVersionTypeEnum;
91
91
  /** (发布成功后)是否推送至远程仓库 */
92
92
  push: boolean;
93
93
  }