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