@done-coding/cli-publish 0.4.0 → 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 +11 -2
- package/es/index-90fd06cf.js +245 -0
- package/es/index.mjs +13 -6
- package/package.json +3 -3
- package/types/injectInfo.json.d.ts +1 -1
- package/es/handler.mjs +0 -194
- package/es/injectInfo.json.mjs +0 -13
- package/es/main.mjs +0 -52
- package/es/utils/enums.mjs +0 -6
- package/es/utils/types.mjs +0 -5
package/es/cli.mjs
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
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 {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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.4.
|
|
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.
|
|
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": "
|
|
65
|
+
"gitHead": "516ef8bb086ae7be558c68bd7392501ef3ed6052"
|
|
66
66
|
}
|
package/es/handler.mjs
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
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";
|
|
6
|
-
import { execSync as o } from "node:child_process";
|
|
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" }) => {
|
|
12
|
-
try {
|
|
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 = "";
|
|
15
|
-
try {
|
|
16
|
-
R = o(`git config --get remote.${i}.url`).toString().trim();
|
|
17
|
-
} catch {
|
|
18
|
-
throw new Error(`git remote ${i} 不存在`);
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
lastHash: n,
|
|
22
|
-
lastCommitter: m,
|
|
23
|
-
lastCommitterPinYin: u(m, {
|
|
24
|
-
style: u.STYLE_NORMAL,
|
|
25
|
-
heteronym: !1
|
|
26
|
-
}).join(""),
|
|
27
|
-
lastCommitEmail: a,
|
|
28
|
-
lastCommitMsg: s,
|
|
29
|
-
userName: r,
|
|
30
|
-
userNamePinYin: u(r, {
|
|
31
|
-
style: u.STYLE_NORMAL,
|
|
32
|
-
heteronym: !1
|
|
33
|
-
}).join(""),
|
|
34
|
-
userEmail: c,
|
|
35
|
-
branchName: g,
|
|
36
|
-
remoteUrl: R
|
|
37
|
-
};
|
|
38
|
-
} catch (n) {
|
|
39
|
-
throw console.error("Error fetching git information:", n), n;
|
|
40
|
-
}
|
|
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;
|
|
62
|
-
} else
|
|
63
|
-
s = P.ALPHA, a = f(
|
|
64
|
-
r,
|
|
65
|
-
e.PRERELEASE,
|
|
66
|
-
s
|
|
67
|
-
);
|
|
68
|
-
if (!a)
|
|
69
|
-
throw new Error("version is empty");
|
|
70
|
-
return {
|
|
71
|
-
name: m,
|
|
72
|
-
version: a,
|
|
73
|
-
tag: s
|
|
74
|
-
};
|
|
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);
|
|
81
|
-
} else
|
|
82
|
-
console.log(
|
|
83
|
-
p.yellow(`未找到配置文件,将使用默认配置
|
|
84
|
-
{ gitOriginName: "origin" }
|
|
85
|
-
`)
|
|
86
|
-
);
|
|
87
|
-
return {
|
|
88
|
-
gitOriginName: "origin",
|
|
89
|
-
...i || {}
|
|
90
|
-
};
|
|
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`);
|
|
168
|
-
try {
|
|
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构建"));
|
|
175
|
-
} else
|
|
176
|
-
throw new Error("未知命令");
|
|
177
|
-
} catch (t) {
|
|
178
|
-
console.log(p.red(`发布失败, error: ${t.message}`));
|
|
179
|
-
try {
|
|
180
|
-
console.log(
|
|
181
|
-
p.blue(`回滚本地版本到发布前的版本:${r.lastHash}`)
|
|
182
|
-
);
|
|
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}`));
|
|
187
|
-
}
|
|
188
|
-
return process.exit(1);
|
|
189
|
-
}
|
|
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("发布成功"));
|
|
191
|
-
};
|
|
192
|
-
export {
|
|
193
|
-
k as handler
|
|
194
|
-
};
|
package/es/injectInfo.json.mjs
DELETED
package/es/main.mjs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
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";
|
|
6
|
-
import { handler as t } from "./handler.mjs";
|
|
7
|
-
import r from "chalk";
|
|
8
|
-
import n from "./injectInfo.json.mjs";
|
|
9
|
-
const d = () => ({
|
|
10
|
-
mode: {
|
|
11
|
-
alias: "m",
|
|
12
|
-
describe: "发布模式",
|
|
13
|
-
choices: [i.NPM, i.WEB],
|
|
14
|
-
default: i.NPM
|
|
15
|
-
},
|
|
16
|
-
type: {
|
|
17
|
-
alias: "t",
|
|
18
|
-
describe: "发布类型",
|
|
19
|
-
choices: [
|
|
20
|
-
e.MAJOR,
|
|
21
|
-
e.MINOR,
|
|
22
|
-
e.PATCH,
|
|
23
|
-
e.PREMAJOR,
|
|
24
|
-
e.PREMINOR,
|
|
25
|
-
e.PREPATCH,
|
|
26
|
-
e.PRERELEASE
|
|
27
|
-
]
|
|
28
|
-
},
|
|
29
|
-
push: {
|
|
30
|
-
alias: "p",
|
|
31
|
-
describe: "是否推送至远程仓库",
|
|
32
|
-
type: "boolean",
|
|
33
|
-
default: !0
|
|
34
|
-
}
|
|
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,
|
|
44
|
-
handler: t
|
|
45
|
-
}, A = async () => {
|
|
46
|
-
const o = l(p(process.argv)), s = await c(o, h);
|
|
47
|
-
return t(s);
|
|
48
|
-
};
|
|
49
|
-
export {
|
|
50
|
-
y as command,
|
|
51
|
-
A as createCli
|
|
52
|
-
};
|
package/es/utils/enums.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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
|
-
};
|