@done-coding/cli-publish 0.3.7 → 0.4.1

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