@done-coding/cli-publish 0.6.0-alpha.0 → 0.6.1-alpha.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/cli.mjs +2 -3
- package/es/index-12bd4947.js +239 -0
- package/es/index.mjs +4 -5
- package/package.json +4 -6
- package/types/config/index.d.ts +3 -2
- package/types/handlers/exec-npm.d.ts +0 -0
- package/types/handlers/exec-web.d.ts +0 -0
- package/types/handlers/exec.d.ts +1 -2
- package/types/injectInfo.json.d.ts +1 -1
- package/types/types/index.d.ts +20 -59
- package/es/index-69c14c7f.js +0 -252
package/es/cli.mjs
CHANGED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { getConfigFileCommonOptions as v, initHandlerCommon as L, log as l, readConfigFile as b, getGitLastCommitInfo as x, getPackageJson as y, pushGitPublishInfoToRemote as J, xPrompts as S, createSubcommand as N, createMainCommand as D } from "@done-coding/cli-utils";
|
|
3
|
+
import { execSync as E } from "node:child_process";
|
|
4
|
+
import { inc as f, prerelease as _ } from "semver";
|
|
5
|
+
var A = /* @__PURE__ */ ((e) => (e.INIT = "init", e.EXEC = "exec", e))(A || {}), t = /* @__PURE__ */ ((e) => (e.MAJOR = "major", e.MINOR = "minor", e.PATCH = "patch", e.PREMAJOR = "premajor", e.PREMINOR = "preminor", e.PREPATCH = "prepatch", e.PRERELEASE = "prerelease", e))(t || {}), p = /* @__PURE__ */ ((e) => (e.LATEST = "latest", e.NEXT = "next", e.ALPHA = "alpha", e))(p || {}), a = /* @__PURE__ */ ((e) => (e.NPM = "npm", e.WEB = "web", e))(a || {});
|
|
6
|
+
const I = {
|
|
7
|
+
name: "@done-coding/cli-publish",
|
|
8
|
+
version: "0.6.1-alpha.0",
|
|
9
|
+
description: "项目发布命令行工具",
|
|
10
|
+
cliConfig: {
|
|
11
|
+
namespaceDir: ".done-coding",
|
|
12
|
+
moduleName: "publish"
|
|
13
|
+
}
|
|
14
|
+
}, {
|
|
15
|
+
cliConfig: { namespaceDir: F, moduleName: j }
|
|
16
|
+
} = I, G = `./${F}/${j}`, g = `${G}.json`, U = {
|
|
17
|
+
[a.WEB]: {},
|
|
18
|
+
[a.NPM]: {}
|
|
19
|
+
}, B = () => v({
|
|
20
|
+
configPathDefault: g
|
|
21
|
+
}), M = async (e) => L(U, e, {
|
|
22
|
+
onFileGenerated: () => {
|
|
23
|
+
l.info("文件生成成功");
|
|
24
|
+
}
|
|
25
|
+
}), W = {
|
|
26
|
+
command: A.INIT,
|
|
27
|
+
describe: "初始化配置文件",
|
|
28
|
+
options: B(),
|
|
29
|
+
handler: M
|
|
30
|
+
}, X = () => ({
|
|
31
|
+
...v({
|
|
32
|
+
configPathDefault: g
|
|
33
|
+
}),
|
|
34
|
+
mode: {
|
|
35
|
+
alias: "m",
|
|
36
|
+
describe: "发布模式",
|
|
37
|
+
choices: [a.NPM, a.WEB],
|
|
38
|
+
default: a.NPM
|
|
39
|
+
},
|
|
40
|
+
type: {
|
|
41
|
+
alias: "t",
|
|
42
|
+
describe: "发布类型",
|
|
43
|
+
choices: [
|
|
44
|
+
t.MAJOR,
|
|
45
|
+
t.MINOR,
|
|
46
|
+
t.PATCH,
|
|
47
|
+
t.PREMAJOR,
|
|
48
|
+
t.PREMINOR,
|
|
49
|
+
t.PREPATCH,
|
|
50
|
+
t.PRERELEASE
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
push: {
|
|
54
|
+
alias: "p",
|
|
55
|
+
describe: "是否推送至远程仓库",
|
|
56
|
+
type: "boolean",
|
|
57
|
+
default: !0
|
|
58
|
+
}
|
|
59
|
+
}), C = ({
|
|
60
|
+
packageJson: e,
|
|
61
|
+
type: o
|
|
62
|
+
}) => {
|
|
63
|
+
let m = e.name, n = "", r;
|
|
64
|
+
const { version: i } = e;
|
|
65
|
+
if (!i)
|
|
66
|
+
throw new Error("当前版本号为空");
|
|
67
|
+
if ([
|
|
68
|
+
t.MAJOR,
|
|
69
|
+
t.MINOR,
|
|
70
|
+
t.PATCH
|
|
71
|
+
].includes(o))
|
|
72
|
+
n = f(i, o), r = p.LATEST;
|
|
73
|
+
else if ([
|
|
74
|
+
t.PREMAJOR,
|
|
75
|
+
t.PREMINOR,
|
|
76
|
+
t.PREPATCH
|
|
77
|
+
].includes(o)) {
|
|
78
|
+
const s = _(i);
|
|
79
|
+
s ? (l.warn("当前版本已经是预发布版本,将会在当前版本基础上进行发布"), s.length === 1 && typeof s[0] == "number" ? n = f(
|
|
80
|
+
i,
|
|
81
|
+
t.PRERELEASE
|
|
82
|
+
) : n = i.split("-")[0] + "-0") : n = f(i, o), r = p.NEXT;
|
|
83
|
+
} else
|
|
84
|
+
r = p.ALPHA, n = f(
|
|
85
|
+
i,
|
|
86
|
+
t.PRERELEASE,
|
|
87
|
+
r
|
|
88
|
+
);
|
|
89
|
+
if (!n)
|
|
90
|
+
throw new Error("version is empty");
|
|
91
|
+
return {
|
|
92
|
+
name: m,
|
|
93
|
+
version: n,
|
|
94
|
+
tag: r
|
|
95
|
+
};
|
|
96
|
+
}, k = async ({
|
|
97
|
+
type: e,
|
|
98
|
+
packageJson: o
|
|
99
|
+
}) => {
|
|
100
|
+
if (e)
|
|
101
|
+
return await C({
|
|
102
|
+
packageJson: o,
|
|
103
|
+
type: e
|
|
104
|
+
});
|
|
105
|
+
{
|
|
106
|
+
const n = Object.values(t).filter(
|
|
107
|
+
(s) => s.toUpperCase() !== s
|
|
108
|
+
).reduce(
|
|
109
|
+
(s, c) => (s[c] = C({
|
|
110
|
+
packageJson: o,
|
|
111
|
+
type: c
|
|
112
|
+
}), s),
|
|
113
|
+
{}
|
|
114
|
+
), r = [
|
|
115
|
+
{
|
|
116
|
+
title: `主版本(${n[t.MAJOR].version})`,
|
|
117
|
+
value: t.MAJOR
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
title: `次版本(${n[t.MINOR].version})`,
|
|
121
|
+
value: t.MINOR
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
title: `修订版本(${n[t.PATCH].version})`,
|
|
125
|
+
value: t.PATCH
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
title: `预发布主版本(${n[t.PREMAJOR].version})`,
|
|
129
|
+
value: t.PREMAJOR
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
title: `预发布次版本(${n[t.PREMINOR].version})`,
|
|
133
|
+
value: t.PREMINOR
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
title: `预发布修订版本(${n[t.PREPATCH].version})`,
|
|
137
|
+
value: t.PREPATCH
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
title: `alpha版本(${n[t.PRERELEASE].version})`,
|
|
141
|
+
value: t.PRERELEASE
|
|
142
|
+
}
|
|
143
|
+
], { type: i } = await S({
|
|
144
|
+
type: "select",
|
|
145
|
+
name: "type",
|
|
146
|
+
message: `请选择发布类型,当前版本:${o.version}`,
|
|
147
|
+
choices: r
|
|
148
|
+
});
|
|
149
|
+
return n[i];
|
|
150
|
+
}
|
|
151
|
+
}, O = async (e) => {
|
|
152
|
+
const { mode: o, type: m, push: n, rootDir: r } = e, s = (await b(e, () => ({})))[o], c = await x(s), H = y({ rootDir: r }), d = await k({
|
|
153
|
+
type: m,
|
|
154
|
+
packageJson: H
|
|
155
|
+
}), { version: P } = d;
|
|
156
|
+
E(`npm version ${P}`, {
|
|
157
|
+
cwd: r,
|
|
158
|
+
stdio: "inherit"
|
|
159
|
+
});
|
|
160
|
+
const { tag: T } = d;
|
|
161
|
+
try {
|
|
162
|
+
switch (o) {
|
|
163
|
+
case a.WEB: {
|
|
164
|
+
const { build: R } = s;
|
|
165
|
+
if (R)
|
|
166
|
+
E(`${R}`, {
|
|
167
|
+
stdio: "inherit",
|
|
168
|
+
cwd: r
|
|
169
|
+
});
|
|
170
|
+
else
|
|
171
|
+
throw new Error("未配置build命令");
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case a.NPM: {
|
|
175
|
+
E(`npm publish --tag ${T}`, {
|
|
176
|
+
cwd: r,
|
|
177
|
+
stdio: "inherit"
|
|
178
|
+
});
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
default:
|
|
182
|
+
throw new Error(`未知发布模式:${o}`);
|
|
183
|
+
}
|
|
184
|
+
} catch (R) {
|
|
185
|
+
l.error(`发布失败, error: ${R.message}`);
|
|
186
|
+
try {
|
|
187
|
+
l.info(`回滚本地版本到发布前的版本:${c.lastHash}`);
|
|
188
|
+
const { lastHash: u } = c;
|
|
189
|
+
E(`git reset --hard ${u}`, {
|
|
190
|
+
stdio: "inherit"
|
|
191
|
+
}), l.info(`删除本次发布时生成的tag:v${d.version}`), E(`git tag -d v${d.version}`, {
|
|
192
|
+
stdio: "inherit"
|
|
193
|
+
});
|
|
194
|
+
} catch (u) {
|
|
195
|
+
l.error(`回滚失败, error: ${u.message}`);
|
|
196
|
+
}
|
|
197
|
+
return process.exit(1);
|
|
198
|
+
}
|
|
199
|
+
n && J({
|
|
200
|
+
branchName: c.branchName,
|
|
201
|
+
version: d.version,
|
|
202
|
+
remoteInfo: c.remoteInfo
|
|
203
|
+
}), l.success(`发布成功,版本号:${P}`);
|
|
204
|
+
}, q = {
|
|
205
|
+
command: "$0",
|
|
206
|
+
describe: "执行发布命令",
|
|
207
|
+
options: X(),
|
|
208
|
+
handler: O
|
|
209
|
+
}, V = async (e, o) => {
|
|
210
|
+
switch (e) {
|
|
211
|
+
case A.INIT:
|
|
212
|
+
return M(o);
|
|
213
|
+
case A.EXEC:
|
|
214
|
+
return O(o);
|
|
215
|
+
default:
|
|
216
|
+
throw new Error(`不支持的命令 ${e}`);
|
|
217
|
+
}
|
|
218
|
+
}, { version: z, description: K } = I, $ = {
|
|
219
|
+
describe: K,
|
|
220
|
+
version: z,
|
|
221
|
+
subcommands: [W, q].map(N),
|
|
222
|
+
demandCommandCount: 1
|
|
223
|
+
}, {
|
|
224
|
+
cliConfig: { moduleName: h }
|
|
225
|
+
} = I, w = (e = !1) => {
|
|
226
|
+
const o = e ? h : void 0, m = `$0${e ? ` ${h}` : ""} [options]`;
|
|
227
|
+
return { command: o, usage: m };
|
|
228
|
+
}, ee = async () => D({
|
|
229
|
+
...$,
|
|
230
|
+
...w()
|
|
231
|
+
}), te = () => N({
|
|
232
|
+
...$,
|
|
233
|
+
...w(!0)
|
|
234
|
+
});
|
|
235
|
+
export {
|
|
236
|
+
te as a,
|
|
237
|
+
ee as c,
|
|
238
|
+
V as h
|
|
239
|
+
};
|
package/es/index.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as n, h as t } from "./index-12bd4947.js";
|
|
3
3
|
import "@done-coding/cli-utils";
|
|
4
|
-
import "semver";
|
|
5
4
|
import "node:child_process";
|
|
6
|
-
import "
|
|
5
|
+
import "semver";
|
|
7
6
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
n as crateAsSubcommand,
|
|
8
|
+
t as handler
|
|
10
9
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-publish",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1-alpha.0",
|
|
4
4
|
"description": "项目发布命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -40,9 +40,8 @@
|
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"sideEffects": false,
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@done-coding/cli-inject": "^0.5.
|
|
43
|
+
"@done-coding/cli-inject": "^0.5.7-alpha.0",
|
|
44
44
|
"@types/node": "^18.0.0",
|
|
45
|
-
"@types/pinyin": "^2.10.0",
|
|
46
45
|
"@types/semver": "^7.5.3",
|
|
47
46
|
"@types/yargs": "^17.0.28",
|
|
48
47
|
"rimraf": "^6.0.1",
|
|
@@ -54,9 +53,8 @@
|
|
|
54
53
|
"node": ">=18.0.0"
|
|
55
54
|
},
|
|
56
55
|
"dependencies": {
|
|
57
|
-
"@done-coding/cli-utils": "^0.
|
|
58
|
-
"pinyin": "^2.11.2",
|
|
56
|
+
"@done-coding/cli-utils": "^0.5.0-alpha.0",
|
|
59
57
|
"semver": "^7.5.4"
|
|
60
58
|
},
|
|
61
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "86cdd3eaf8cc8be3e48a812b93fd7c2110fcc879"
|
|
62
60
|
}
|
package/types/config/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { type ConfigInfo } from '../types';
|
|
2
|
+
declare const config: ConfigInfo;
|
|
3
|
+
export default config;
|
|
File without changes
|
|
File without changes
|
package/types/handlers/exec.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ExecOptions } from '../types';
|
|
2
2
|
import type { CliHandlerArgv, CliInfo, SubCliInfo } from "@done-coding/cli-utils";
|
|
3
3
|
export declare const getExecOptions: () => CliInfo["options"];
|
|
4
|
-
export type ChildCmd = "npm" | "web";
|
|
5
4
|
export declare const execHandler: (argv: CliHandlerArgv<ExecOptions>) => Promise<undefined>;
|
|
6
5
|
export declare const execCommandCliInfo: SubCliInfo;
|
package/types/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InitConfigFileOptions, ReadConfigFileOptions } from "@done-coding/cli-utils";
|
|
1
|
+
import type { GetGitLastCommitParams, InitConfigFileOptions, ReadConfigFileOptions } from "@done-coding/cli-utils";
|
|
2
2
|
/** 子命令枚举 */
|
|
3
3
|
export declare enum SubcommandEnum {
|
|
4
4
|
/** 初始化发布配置文件 */
|
|
@@ -57,51 +57,6 @@ export declare enum PublishTagEnum {
|
|
|
57
57
|
*/
|
|
58
58
|
ALPHA = "alpha"
|
|
59
59
|
}
|
|
60
|
-
/**
|
|
61
|
-
* git仓库信息
|
|
62
|
-
*/
|
|
63
|
-
export interface GitInfo {
|
|
64
|
-
/**
|
|
65
|
-
* 最后一次提交hash值
|
|
66
|
-
*/
|
|
67
|
-
lastHash: string;
|
|
68
|
-
/**
|
|
69
|
-
* 最后一次提交者
|
|
70
|
-
*/
|
|
71
|
-
lastCommitter: string;
|
|
72
|
-
/**
|
|
73
|
-
* 最后一次提交者拼音
|
|
74
|
-
*/
|
|
75
|
-
lastCommitterPinYin: string;
|
|
76
|
-
/**
|
|
77
|
-
* 最后一次提交者邮箱
|
|
78
|
-
*/
|
|
79
|
-
lastCommitEmail: string;
|
|
80
|
-
/**
|
|
81
|
-
* 最后一次提交信息
|
|
82
|
-
*/
|
|
83
|
-
lastCommitMsg: string;
|
|
84
|
-
/**
|
|
85
|
-
* 用户名
|
|
86
|
-
*/
|
|
87
|
-
userName: string;
|
|
88
|
-
/**
|
|
89
|
-
* 用户名拼音
|
|
90
|
-
*/
|
|
91
|
-
userNamePinYin: string;
|
|
92
|
-
/**
|
|
93
|
-
* 邮箱
|
|
94
|
-
*/
|
|
95
|
-
userEmail: string;
|
|
96
|
-
/**
|
|
97
|
-
* 分知名
|
|
98
|
-
*/
|
|
99
|
-
branchName: string;
|
|
100
|
-
/**
|
|
101
|
-
* 仓库地址
|
|
102
|
-
*/
|
|
103
|
-
remoteUrl: string;
|
|
104
|
-
}
|
|
105
60
|
/**
|
|
106
61
|
* npm信息
|
|
107
62
|
*/
|
|
@@ -119,19 +74,6 @@ export interface NpmInfo {
|
|
|
119
74
|
*/
|
|
120
75
|
tag: PublishTagEnum;
|
|
121
76
|
}
|
|
122
|
-
/**
|
|
123
|
-
* 配置信息
|
|
124
|
-
*/
|
|
125
|
-
export interface ConfigInfo {
|
|
126
|
-
/**
|
|
127
|
-
* web构建命令
|
|
128
|
-
*/
|
|
129
|
-
webBuild?: string;
|
|
130
|
-
/**
|
|
131
|
-
* git远程仓库名
|
|
132
|
-
*/
|
|
133
|
-
gitOriginName: string;
|
|
134
|
-
}
|
|
135
77
|
/** 发布模式 */
|
|
136
78
|
export declare enum PublishModeEnum {
|
|
137
79
|
/** npm发布模式 */
|
|
@@ -139,6 +81,25 @@ export declare enum PublishModeEnum {
|
|
|
139
81
|
/** web发布模式 */
|
|
140
82
|
WEB = "web"
|
|
141
83
|
}
|
|
84
|
+
/** 发布配置- web模式 */
|
|
85
|
+
export interface ConfigInfoWeb extends GetGitLastCommitParams {
|
|
86
|
+
/**
|
|
87
|
+
* web构建命令
|
|
88
|
+
*/
|
|
89
|
+
build?: string;
|
|
90
|
+
}
|
|
91
|
+
/** 发布配置- npm模式 */
|
|
92
|
+
export interface ConfigInfoNpm extends GetGitLastCommitParams {
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 配置信息
|
|
96
|
+
*/
|
|
97
|
+
export interface ConfigInfo {
|
|
98
|
+
/** web发布配置 */
|
|
99
|
+
[PublishModeEnum.WEB]?: ConfigInfoWeb;
|
|
100
|
+
/** NPM发布配置 */
|
|
101
|
+
[PublishModeEnum.NPM]?: ConfigInfoNpm;
|
|
102
|
+
}
|
|
142
103
|
export interface ExecOptions extends ReadConfigFileOptions {
|
|
143
104
|
/** 发布模式 */
|
|
144
105
|
mode: PublishModeEnum;
|
package/es/index-69c14c7f.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { getConfigFileCommonOptions as I, initHandlerCommon as b, log as g, readConfigFile as D, getPackageJson as J, xPrompts as x, createSubcommand as M, createMainCommand as _ } from "@done-coding/cli-utils";
|
|
3
|
-
import { inc as A, prerelease as j } from "semver";
|
|
4
|
-
import { execSync as o } from "node:child_process";
|
|
5
|
-
import u from "pinyin";
|
|
6
|
-
var v = /* @__PURE__ */ ((e) => (e.INIT = "init", e.EXEC = "exec", e))(v || {}), t = /* @__PURE__ */ ((e) => (e.MAJOR = "major", e.MINOR = "minor", e.PATCH = "patch", e.PREMAJOR = "premajor", e.PREMINOR = "preminor", e.PREPATCH = "prepatch", e.PRERELEASE = "prerelease", e))(t || {}), h = /* @__PURE__ */ ((e) => (e.LATEST = "latest", e.NEXT = "next", e.ALPHA = "alpha", e))(h || {}), f = /* @__PURE__ */ ((e) => (e.NPM = "npm", e.WEB = "web", e))(f || {});
|
|
7
|
-
const C = {
|
|
8
|
-
name: "@done-coding/cli-publish",
|
|
9
|
-
version: "0.6.0-alpha.0",
|
|
10
|
-
description: "项目发布命令行工具",
|
|
11
|
-
cliConfig: {
|
|
12
|
-
namespaceDir: ".done-coding",
|
|
13
|
-
moduleName: "publish"
|
|
14
|
-
}
|
|
15
|
-
}, {
|
|
16
|
-
cliConfig: { namespaceDir: F, moduleName: U }
|
|
17
|
-
} = C, B = `./${F}/${U}`, H = `${B}.json`, G = {}, X = () => I({
|
|
18
|
-
configPathDefault: H
|
|
19
|
-
}), w = async (e) => b(G, e, {
|
|
20
|
-
onFileGenerated: () => {
|
|
21
|
-
g.info("文件生成成功");
|
|
22
|
-
}
|
|
23
|
-
}), Y = {
|
|
24
|
-
command: v.INIT,
|
|
25
|
-
describe: "初始化配置文件",
|
|
26
|
-
options: X(),
|
|
27
|
-
handler: w
|
|
28
|
-
}, k = () => ({
|
|
29
|
-
...I({
|
|
30
|
-
configPathDefault: H
|
|
31
|
-
}),
|
|
32
|
-
mode: {
|
|
33
|
-
alias: "m",
|
|
34
|
-
describe: "发布模式",
|
|
35
|
-
choices: [f.NPM, f.WEB],
|
|
36
|
-
default: f.NPM
|
|
37
|
-
},
|
|
38
|
-
type: {
|
|
39
|
-
alias: "t",
|
|
40
|
-
describe: "发布类型",
|
|
41
|
-
choices: [
|
|
42
|
-
t.MAJOR,
|
|
43
|
-
t.MINOR,
|
|
44
|
-
t.PATCH,
|
|
45
|
-
t.PREMAJOR,
|
|
46
|
-
t.PREMINOR,
|
|
47
|
-
t.PREPATCH,
|
|
48
|
-
t.PRERELEASE
|
|
49
|
-
]
|
|
50
|
-
},
|
|
51
|
-
push: {
|
|
52
|
-
alias: "p",
|
|
53
|
-
describe: "是否推送至远程仓库",
|
|
54
|
-
type: "boolean",
|
|
55
|
-
default: !0
|
|
56
|
-
}
|
|
57
|
-
}), W = ({ gitOriginName: e }) => {
|
|
58
|
-
try {
|
|
59
|
-
const r = o("git rev-parse HEAD").toString().trim(), l = o('git log -1 --pretty=format:"%an"').toString().trim(), s = o('git log -1 --pretty=format:"%ae"').toString().trim(), a = o('git log -1 --pretty=format:"%s"').toString().trim(), n = o("git config user.name").toString().trim(), c = o("git config user.email").toString().trim(), p = o("git rev-parse --abbrev-ref HEAD").toString().trim();
|
|
60
|
-
let E = "";
|
|
61
|
-
try {
|
|
62
|
-
E = o(`git config --get remote.${e}.url`).toString().trim();
|
|
63
|
-
} catch {
|
|
64
|
-
throw new Error(`git remote ${e} 不存在`);
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
lastHash: r,
|
|
68
|
-
lastCommitter: l,
|
|
69
|
-
lastCommitterPinYin: u(l, {
|
|
70
|
-
style: u.STYLE_NORMAL,
|
|
71
|
-
heteronym: !1
|
|
72
|
-
}).join(""),
|
|
73
|
-
lastCommitEmail: s,
|
|
74
|
-
lastCommitMsg: a,
|
|
75
|
-
userName: n,
|
|
76
|
-
userNamePinYin: u(n, {
|
|
77
|
-
style: u.STYLE_NORMAL,
|
|
78
|
-
heteronym: !1
|
|
79
|
-
}).join(""),
|
|
80
|
-
userEmail: c,
|
|
81
|
-
branchName: p,
|
|
82
|
-
remoteUrl: E
|
|
83
|
-
};
|
|
84
|
-
} catch (r) {
|
|
85
|
-
throw console.error("Error fetching git information:", r), r;
|
|
86
|
-
}
|
|
87
|
-
}, $ = ({
|
|
88
|
-
packageJson: e,
|
|
89
|
-
type: r
|
|
90
|
-
}) => {
|
|
91
|
-
let l = e.name, s = "", a;
|
|
92
|
-
const { version: n } = e;
|
|
93
|
-
if (!n)
|
|
94
|
-
throw new Error("当前版本号为空");
|
|
95
|
-
if ([
|
|
96
|
-
t.MAJOR,
|
|
97
|
-
t.MINOR,
|
|
98
|
-
t.PATCH
|
|
99
|
-
].includes(r))
|
|
100
|
-
s = A(n, r), a = h.LATEST;
|
|
101
|
-
else if ([
|
|
102
|
-
t.PREMAJOR,
|
|
103
|
-
t.PREMINOR,
|
|
104
|
-
t.PREPATCH
|
|
105
|
-
].includes(r)) {
|
|
106
|
-
const c = j(n);
|
|
107
|
-
c ? (g.warn("当前版本已经是预发布版本,将会在当前版本基础上进行发布"), c.length === 1 && typeof c[0] == "number" ? s = A(
|
|
108
|
-
n,
|
|
109
|
-
t.PRERELEASE
|
|
110
|
-
) : s = n.split("-")[0] + "-0") : s = A(n, r), a = h.NEXT;
|
|
111
|
-
} else
|
|
112
|
-
a = h.ALPHA, s = A(
|
|
113
|
-
n,
|
|
114
|
-
t.PRERELEASE,
|
|
115
|
-
a
|
|
116
|
-
);
|
|
117
|
-
if (!s)
|
|
118
|
-
throw new Error("version is empty");
|
|
119
|
-
return {
|
|
120
|
-
name: l,
|
|
121
|
-
version: s,
|
|
122
|
-
tag: a
|
|
123
|
-
};
|
|
124
|
-
}, y = async (e) => {
|
|
125
|
-
const { mode: r, type: l, push: s, rootDir: a } = e, n = await D(e, () => ({
|
|
126
|
-
gitOriginName: "origin"
|
|
127
|
-
})), c = W(n), p = J({ rootDir: a });
|
|
128
|
-
let E = l, m;
|
|
129
|
-
if (E)
|
|
130
|
-
m = await $({
|
|
131
|
-
packageJson: p,
|
|
132
|
-
type: E
|
|
133
|
-
});
|
|
134
|
-
else {
|
|
135
|
-
const i = Object.values(t).filter(
|
|
136
|
-
(R) => R.toUpperCase() !== R
|
|
137
|
-
).reduce(
|
|
138
|
-
(R, N) => (R[N] = $({
|
|
139
|
-
packageJson: p,
|
|
140
|
-
type: N
|
|
141
|
-
}), R),
|
|
142
|
-
{}
|
|
143
|
-
), T = [
|
|
144
|
-
{
|
|
145
|
-
title: `主版本(${i[t.MAJOR].version})`,
|
|
146
|
-
value: t.MAJOR
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
title: `次版本(${i[t.MINOR].version})`,
|
|
150
|
-
value: t.MINOR
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
title: `修订版本(${i[t.PATCH].version})`,
|
|
154
|
-
value: t.PATCH
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
title: `预发布主版本(${i[t.PREMAJOR].version})`,
|
|
158
|
-
value: t.PREMAJOR
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
title: `预发布次版本(${i[t.PREMINOR].version})`,
|
|
162
|
-
value: t.PREMINOR
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
title: `预发布修订版本(${i[t.PREPATCH].version})`,
|
|
166
|
-
value: t.PREPATCH
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
title: `alpha版本(${i[t.PRERELEASE].version})`,
|
|
170
|
-
value: t.PRERELEASE
|
|
171
|
-
}
|
|
172
|
-
];
|
|
173
|
-
E = (await x({
|
|
174
|
-
type: "select",
|
|
175
|
-
name: "type",
|
|
176
|
-
message: `请选择发布类型,当前版本:${p.version}`,
|
|
177
|
-
choices: T
|
|
178
|
-
})).type, m = i[E];
|
|
179
|
-
}
|
|
180
|
-
const { version: P } = m;
|
|
181
|
-
o(`npm version ${P}`, {
|
|
182
|
-
stdio: "inherit"
|
|
183
|
-
});
|
|
184
|
-
try {
|
|
185
|
-
if (r === f.NPM) {
|
|
186
|
-
const { tag: d } = m;
|
|
187
|
-
o(`npm publish --tag ${d}`, {
|
|
188
|
-
stdio: "inherit"
|
|
189
|
-
});
|
|
190
|
-
} else if (r === f.WEB) {
|
|
191
|
-
const { webBuild: d } = n;
|
|
192
|
-
d ? o(`${d}`, {
|
|
193
|
-
stdio: "inherit"
|
|
194
|
-
}) : g.warn("webBuild为空,不执行web构建");
|
|
195
|
-
} else
|
|
196
|
-
throw new Error("未知命令");
|
|
197
|
-
} catch (d) {
|
|
198
|
-
g.error(`发布失败, error: ${d.message}`);
|
|
199
|
-
try {
|
|
200
|
-
g.info(`回滚本地版本到发布前的版本:${c.lastHash}`);
|
|
201
|
-
const { lastHash: i } = c;
|
|
202
|
-
o(`git reset --hard ${i}`, {
|
|
203
|
-
stdio: "inherit"
|
|
204
|
-
}), g.info(`删除本次发布时生成的tag:v${m.version}`), o(`git tag -d v${m.version}`, {
|
|
205
|
-
stdio: "inherit"
|
|
206
|
-
});
|
|
207
|
-
} catch (i) {
|
|
208
|
-
g.error(`回滚失败, error: ${i.message}`);
|
|
209
|
-
}
|
|
210
|
-
return process.exit(1);
|
|
211
|
-
}
|
|
212
|
-
s && (o(`git push ${n.gitOriginName} v${m.version}`, {
|
|
213
|
-
stdio: "inherit"
|
|
214
|
-
}), o(`git push ${n.gitOriginName} ${c.branchName}`, {
|
|
215
|
-
stdio: "inherit"
|
|
216
|
-
})), g.success(`发布成功,版本号:${P}`);
|
|
217
|
-
}, q = {
|
|
218
|
-
command: "$0",
|
|
219
|
-
describe: "执行发布命令",
|
|
220
|
-
options: k(),
|
|
221
|
-
handler: y
|
|
222
|
-
}, te = async (e, r) => {
|
|
223
|
-
switch (e) {
|
|
224
|
-
case v.INIT:
|
|
225
|
-
return w(r);
|
|
226
|
-
case v.EXEC:
|
|
227
|
-
return y(r);
|
|
228
|
-
default:
|
|
229
|
-
throw new Error(`不支持的命令 ${e}`);
|
|
230
|
-
}
|
|
231
|
-
}, { version: z, description: K } = C, L = {
|
|
232
|
-
describe: K,
|
|
233
|
-
version: z,
|
|
234
|
-
subcommands: [Y, q].map(M),
|
|
235
|
-
demandCommandCount: 1
|
|
236
|
-
}, {
|
|
237
|
-
cliConfig: { moduleName: O }
|
|
238
|
-
} = C, S = (e = !1) => {
|
|
239
|
-
const r = e ? O : void 0, l = `$0${e ? ` ${O}` : ""} [options]`;
|
|
240
|
-
return { command: r, usage: l };
|
|
241
|
-
}, re = async () => _({
|
|
242
|
-
...L,
|
|
243
|
-
...S()
|
|
244
|
-
}), ne = () => M({
|
|
245
|
-
...L,
|
|
246
|
-
...S(!0)
|
|
247
|
-
});
|
|
248
|
-
export {
|
|
249
|
-
ne as a,
|
|
250
|
-
re as c,
|
|
251
|
-
te as h
|
|
252
|
-
};
|