@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 +155 -68
- package/es/injectInfo.json.mjs +1 -1
- package/es/main.mjs +31 -23
- package/es/utils/enums.mjs +6 -0
- package/package.json +3 -3
- package/types/injectInfo.json.d.ts +1 -1
- package/types/utils/enums.d.ts +50 -0
- package/types/utils/index.d.ts +1 -0
- package/types/utils/types.d.ts +3 -3
package/es/handler.mjs
CHANGED
|
@@ -1,107 +1,194 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { PublishModeEnum as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
|
7
|
-
import { readFileSync as
|
|
8
|
-
import
|
|
9
|
-
|
|
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
|
|
12
|
-
let
|
|
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
|
-
|
|
16
|
+
R = o(`git config --get remote.${i}.url`).toString().trim();
|
|
15
17
|
} catch {
|
|
16
|
-
throw new Error(`git remote ${
|
|
18
|
+
throw new Error(`git remote ${i} 不存在`);
|
|
17
19
|
}
|
|
18
20
|
return {
|
|
19
|
-
lastHash:
|
|
20
|
-
lastCommitter:
|
|
21
|
-
lastCommitterPinYin:
|
|
22
|
-
style:
|
|
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:
|
|
27
|
-
userName:
|
|
28
|
-
userNamePinYin:
|
|
29
|
-
style:
|
|
28
|
+
lastCommitMsg: s,
|
|
29
|
+
userName: r,
|
|
30
|
+
userNamePinYin: u(r, {
|
|
31
|
+
style: u.STYLE_NORMAL,
|
|
30
32
|
heteronym: !1
|
|
31
33
|
}).join(""),
|
|
32
|
-
userEmail:
|
|
34
|
+
userEmail: c,
|
|
33
35
|
branchName: g,
|
|
34
|
-
remoteUrl:
|
|
36
|
+
remoteUrl: R
|
|
35
37
|
};
|
|
36
|
-
} catch (
|
|
37
|
-
throw console.error("Error fetching git information:",
|
|
38
|
+
} catch (n) {
|
|
39
|
+
throw console.error("Error fetching git information:", n), n;
|
|
38
40
|
}
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
52
|
-
|
|
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:
|
|
56
|
-
version:
|
|
57
|
-
tag:
|
|
71
|
+
name: m,
|
|
72
|
+
version: a,
|
|
73
|
+
tag: s
|
|
58
74
|
};
|
|
59
|
-
},
|
|
60
|
-
let
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
const
|
|
64
|
-
|
|
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
|
-
|
|
83
|
+
p.yellow(`未找到配置文件,将使用默认配置
|
|
68
84
|
{ gitOriginName: "origin" }
|
|
69
85
|
`)
|
|
70
86
|
);
|
|
71
87
|
return {
|
|
72
88
|
gitOriginName: "origin",
|
|
73
|
-
...
|
|
89
|
+
...i || {}
|
|
74
90
|
};
|
|
75
|
-
},
|
|
76
|
-
console.log(
|
|
77
|
-
const { mode:
|
|
78
|
-
console.log("
|
|
79
|
-
|
|
80
|
-
|
|
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 (
|
|
83
|
-
const { tag:
|
|
84
|
-
o(`npm publish --tag ${
|
|
85
|
-
} else if (
|
|
86
|
-
const { webBuild:
|
|
87
|
-
|
|
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 (
|
|
91
|
-
console.log(
|
|
177
|
+
} catch (t) {
|
|
178
|
+
console.log(p.red(`发布失败, error: ${t.message}`));
|
|
92
179
|
try {
|
|
93
180
|
console.log(
|
|
94
|
-
|
|
181
|
+
p.blue(`回滚本地版本到发布前的版本:${r.lastHash}`)
|
|
95
182
|
);
|
|
96
|
-
const { lastHash:
|
|
97
|
-
o(`git reset --hard ${
|
|
98
|
-
} catch (
|
|
99
|
-
console.log(
|
|
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 ${
|
|
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
|
-
|
|
193
|
+
k as handler
|
|
107
194
|
};
|
package/es/injectInfo.json.mjs
CHANGED
package/es/main.mjs
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import { hideBin as
|
|
4
|
-
import { PublishModeEnum as
|
|
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
|
|
7
|
-
import
|
|
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: [
|
|
13
|
-
default:
|
|
13
|
+
choices: [i.NPM, i.WEB],
|
|
14
|
+
default: i.NPM
|
|
14
15
|
},
|
|
15
16
|
type: {
|
|
16
17
|
alias: "t",
|
|
17
18
|
describe: "发布类型",
|
|
18
|
-
choices: [
|
|
19
|
-
|
|
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
|
-
}),
|
|
28
|
-
console.log(o ?
|
|
29
|
-
},
|
|
30
|
-
const
|
|
31
|
-
return o.strict().usage(
|
|
32
|
-
},
|
|
33
|
-
command:
|
|
34
|
-
describe:
|
|
35
|
-
builder:
|
|
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
|
-
},
|
|
38
|
-
const o =
|
|
39
|
-
return t(
|
|
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
|
-
|
|
43
|
-
|
|
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
|
+
"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.
|
|
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": "
|
|
65
|
+
"gitHead": "eb3732e50f528b2c838af6303d774d6d04cf5f37"
|
|
66
66
|
}
|
|
@@ -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
|
+
}
|
package/types/utils/index.d.ts
CHANGED
package/types/utils/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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:
|
|
62
|
+
tag: PublishTagEnum;
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* 配置信息
|
|
@@ -87,7 +87,7 @@ export interface Options {
|
|
|
87
87
|
/**
|
|
88
88
|
* 发布类型
|
|
89
89
|
*/
|
|
90
|
-
type
|
|
90
|
+
type?: PublishVersionTypeEnum;
|
|
91
91
|
/** (发布成功后)是否推送至远程仓库 */
|
|
92
92
|
push: boolean;
|
|
93
93
|
}
|