@done-coding/cli-publish 0.6.0-alpha.0 → 0.7.0-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 CHANGED
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { c as m } from "./index-69c14c7f.js";
2
+ import { c as m } from "./index-03fd1d3d.js";
3
3
  import "@done-coding/cli-utils";
4
- import "semver";
5
4
  import "node:child_process";
6
- import "pinyin";
5
+ import "semver";
6
+ import "uuid";
7
+ import "node:path";
8
+ import "node:fs";
9
+ import "node:os";
7
10
  m();
@@ -0,0 +1,305 @@
1
+ #!/usr/bin/env node
2
+ import { getConfigFileCommonOptions as v, initHandlerCommon as G, log as m, readConfigFile as J, getPackageJson as C, getGitLastCommitInfo as U, pushGitPublishInfoToRemote as W, xPrompts as X, createSubcommand as b, createMainCommand as q } from "@done-coding/cli-utils";
3
+ import { execSync as d } from "node:child_process";
4
+ import { inc as g, prerelease as z } from "semver";
5
+ import { v4 as K } from "uuid";
6
+ import w from "node:path";
7
+ import T, { rmSync as Q } from "node:fs";
8
+ import { homedir as Y } from "node:os";
9
+ var R = /* @__PURE__ */ ((e) => (e.INIT = "init", e.EXEC = "exec", e.ALIAS = "alias", e))(R || {}), 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 || {}), A = /* @__PURE__ */ ((e) => (e.LATEST = "latest", e.NEXT = "next", e.ALPHA = "alpha", e))(A || {}), c = /* @__PURE__ */ ((e) => (e.NPM = "npm", e.WEB = "web", e))(c || {});
10
+ const $ = {
11
+ name: "@done-coding/cli-publish",
12
+ version: "0.7.0-alpha.0",
13
+ description: "项目发布命令行工具",
14
+ cliConfig: {
15
+ namespaceDir: ".done-coding",
16
+ moduleName: "publish"
17
+ }
18
+ }, {
19
+ cliConfig: { namespaceDir: Z, moduleName: V }
20
+ } = $, ee = `./${Z}/${V}`, N = `${ee}.json`, te = {
21
+ [c.WEB]: {},
22
+ [c.NPM]: {
23
+ aliasInfo: [
24
+ {
25
+ packageJson: {
26
+ name: "",
27
+ bin: "",
28
+ scripts: {}
29
+ }
30
+ }
31
+ ]
32
+ }
33
+ }, ne = () => v({
34
+ configPathDefault: N
35
+ }), D = async (e) => G(te, e, {
36
+ onFileGenerated: () => {
37
+ m.info("文件生成成功");
38
+ }
39
+ }), oe = {
40
+ command: R.INIT,
41
+ describe: "初始化配置文件",
42
+ options: ne(),
43
+ handler: D
44
+ }, se = () => v({
45
+ configPathDefault: N
46
+ }), y = (e) => {
47
+ var a;
48
+ const n = ((a = e[c.NPM]) == null ? void 0 : a.aliasInfo) || [];
49
+ if (n.length)
50
+ return n;
51
+ }, O = async (e) => {
52
+ var M;
53
+ const n = await J(e, () => ({})), a = y(n);
54
+ if (!a) {
55
+ m.warn("没有配置别名发布信息");
56
+ return;
57
+ }
58
+ const { rootDir: o } = e, i = C({ rootDir: o }), { name: s, version: r } = i, l = `${Y()}/.DONE_CODING_CLI_PUBLISH_ALIAS`, u = w.resolve(l, K());
59
+ T.mkdirSync(u, { recursive: !0 }), d(`npm install ${s}@${r}`, {
60
+ stdio: "inherit",
61
+ cwd: u
62
+ });
63
+ const f = (M = d(`npm dist-tag ${s}`).toString().trim().split(`
64
+ `).map((I) => I.split(":").map((h) => h.trim())).find(
65
+ ([, I]) => I === r
66
+ )) == null ? void 0 : M[0];
67
+ if (!f)
68
+ return m.warn(`没有找到 ${s}@${r} 对应的dist-tag`);
69
+ const p = w.resolve(u, "node_modules", s), B = C({
70
+ rootDir: p
71
+ });
72
+ for (let I of a) {
73
+ const { packageJson: h } = I, F = {
74
+ ...B,
75
+ ...h
76
+ }, j = `${p}/package.json`;
77
+ T.writeFileSync(
78
+ j,
79
+ JSON.stringify(F, null, 2)
80
+ ), d(`npm publish --tag ${f}`, {
81
+ stdio: "inherit",
82
+ cwd: p
83
+ }), Q(u, { recursive: !0, force: !0 });
84
+ }
85
+ }, re = {
86
+ command: R.ALIAS,
87
+ describe: "别名发布",
88
+ options: se(),
89
+ handler: O
90
+ }, ie = () => ({
91
+ ...v({
92
+ configPathDefault: N
93
+ }),
94
+ mode: {
95
+ alias: "m",
96
+ describe: "发布模式",
97
+ choices: [c.NPM, c.WEB],
98
+ default: c.NPM
99
+ },
100
+ type: {
101
+ alias: "t",
102
+ describe: "发布类型",
103
+ choices: [
104
+ t.MAJOR,
105
+ t.MINOR,
106
+ t.PATCH,
107
+ t.PREMAJOR,
108
+ t.PREMINOR,
109
+ t.PREPATCH,
110
+ t.PRERELEASE
111
+ ]
112
+ },
113
+ push: {
114
+ alias: "p",
115
+ describe: "是否推送至远程仓库",
116
+ type: "boolean",
117
+ default: !0
118
+ }
119
+ }), H = ({
120
+ packageJson: e,
121
+ type: n
122
+ }) => {
123
+ let a = e.name, o = "", i;
124
+ const { version: s } = e;
125
+ if (!s)
126
+ throw new Error("当前版本号为空");
127
+ if ([
128
+ t.MAJOR,
129
+ t.MINOR,
130
+ t.PATCH
131
+ ].includes(n))
132
+ o = g(s, n), i = A.LATEST;
133
+ else if ([
134
+ t.PREMAJOR,
135
+ t.PREMINOR,
136
+ t.PREPATCH
137
+ ].includes(n)) {
138
+ const r = z(s);
139
+ r ? (m.warn("当前版本已经是预发布版本,将会在当前版本基础上进行发布"), r.length === 1 && typeof r[0] == "number" ? o = g(
140
+ s,
141
+ t.PRERELEASE
142
+ ) : o = s.split("-")[0] + "-0") : o = g(s, n), i = A.NEXT;
143
+ } else
144
+ i = A.ALPHA, o = g(
145
+ s,
146
+ t.PRERELEASE,
147
+ i
148
+ );
149
+ if (!o)
150
+ throw new Error("version is empty");
151
+ return {
152
+ name: a,
153
+ version: o,
154
+ tag: i
155
+ };
156
+ }, ae = async ({
157
+ type: e,
158
+ packageJson: n
159
+ }) => {
160
+ if (e)
161
+ return await H({
162
+ packageJson: n,
163
+ type: e
164
+ });
165
+ {
166
+ const o = Object.values(t).filter(
167
+ (r) => r.toUpperCase() !== r
168
+ ).reduce(
169
+ (r, l) => (r[l] = H({
170
+ packageJson: n,
171
+ type: l
172
+ }), r),
173
+ {}
174
+ ), i = [
175
+ {
176
+ title: `主版本(${o[t.MAJOR].version})`,
177
+ value: t.MAJOR
178
+ },
179
+ {
180
+ title: `次版本(${o[t.MINOR].version})`,
181
+ value: t.MINOR
182
+ },
183
+ {
184
+ title: `修订版本(${o[t.PATCH].version})`,
185
+ value: t.PATCH
186
+ },
187
+ {
188
+ title: `预发布主版本(${o[t.PREMAJOR].version})`,
189
+ value: t.PREMAJOR
190
+ },
191
+ {
192
+ title: `预发布次版本(${o[t.PREMINOR].version})`,
193
+ value: t.PREMINOR
194
+ },
195
+ {
196
+ title: `预发布修订版本(${o[t.PREPATCH].version})`,
197
+ value: t.PREPATCH
198
+ },
199
+ {
200
+ title: `alpha版本(${o[t.PRERELEASE].version})`,
201
+ value: t.PRERELEASE
202
+ }
203
+ ], { type: s } = await X({
204
+ type: "select",
205
+ name: "type",
206
+ message: `请选择发布类型,当前版本:${n.version}`,
207
+ choices: i
208
+ });
209
+ return o[s];
210
+ }
211
+ }, k = async (e) => {
212
+ const { mode: n, type: a, push: o, rootDir: i } = e, s = await J(e, () => ({})), r = s[n], l = await U(r), u = C({ rootDir: i }), E = await ae({
213
+ type: a,
214
+ packageJson: u
215
+ }), { version: P } = E;
216
+ d(`npm version ${P}`, {
217
+ cwd: i,
218
+ stdio: "inherit"
219
+ });
220
+ const { tag: L } = E;
221
+ try {
222
+ switch (n) {
223
+ case c.WEB: {
224
+ const { build: f } = r;
225
+ if (f)
226
+ d(`${f}`, {
227
+ stdio: "inherit",
228
+ cwd: i
229
+ });
230
+ else
231
+ throw new Error("未配置build命令");
232
+ break;
233
+ }
234
+ case c.NPM: {
235
+ d(`npm publish --tag ${L}`, {
236
+ cwd: i,
237
+ stdio: "inherit"
238
+ });
239
+ break;
240
+ }
241
+ default:
242
+ throw new Error(`未知发布模式:${n}`);
243
+ }
244
+ } catch (f) {
245
+ m.error(`发布失败, error: ${f.message}`);
246
+ try {
247
+ m.info(`回滚本地版本到发布前的版本:${l.lastHash}`);
248
+ const { lastHash: p } = l;
249
+ d(`git reset --hard ${p}`, {
250
+ stdio: "inherit"
251
+ }), m.info(`删除本次发布时生成的tag:v${E.version}`), d(`git tag -d v${E.version}`, {
252
+ stdio: "inherit"
253
+ });
254
+ } catch (p) {
255
+ m.error(`回滚失败, error: ${p.message}`);
256
+ }
257
+ return process.exit(1);
258
+ }
259
+ o && W({
260
+ branchName: l.branchName,
261
+ version: E.version,
262
+ remoteInfo: l.remoteInfo
263
+ }), m.success(`发布成功,版本号:${P}`), n === c.NPM && y(s) && O(e);
264
+ }, ce = {
265
+ command: "$0",
266
+ describe: "执行发布命令",
267
+ options: ie(),
268
+ handler: k
269
+ }, ge = async (e, n) => {
270
+ switch (e) {
271
+ case R.INIT:
272
+ return D(n);
273
+ case R.EXEC:
274
+ return k(n);
275
+ case R.ALIAS:
276
+ return O(n);
277
+ default:
278
+ throw new Error(`不支持的命令 ${e}`);
279
+ }
280
+ }, { version: le, description: me } = $, _ = {
281
+ describe: me,
282
+ version: le,
283
+ subcommands: [
284
+ oe,
285
+ ce,
286
+ re
287
+ ].map(b),
288
+ demandCommandCount: 1
289
+ }, {
290
+ cliConfig: { moduleName: S }
291
+ } = $, x = (e = !1) => {
292
+ const n = e ? S : void 0, a = `$0${e ? ` ${S}` : ""} [options]`;
293
+ return { command: n, usage: a };
294
+ }, Ae = async () => q({
295
+ ..._,
296
+ ...x()
297
+ }), Pe = () => b({
298
+ ..._,
299
+ ...x(!0)
300
+ });
301
+ export {
302
+ Pe as a,
303
+ Ae as c,
304
+ ge as h
305
+ };
package/es/index.mjs CHANGED
@@ -1,10 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import { a as i, h as n } from "./index-69c14c7f.js";
2
+ import { a as s, h as d } from "./index-03fd1d3d.js";
3
3
  import "@done-coding/cli-utils";
4
- import "semver";
5
4
  import "node:child_process";
6
- import "pinyin";
5
+ import "semver";
6
+ import "uuid";
7
+ import "node:path";
8
+ import "node:fs";
9
+ import "node:os";
7
10
  export {
8
- i as crateAsSubcommand,
9
- n as handler
11
+ s as crateAsSubcommand,
12
+ d as handler
10
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-publish",
3
- "version": "0.6.0-alpha.0",
3
+ "version": "0.7.0-alpha.0",
4
4
  "description": "项目发布命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -40,10 +40,10 @@
40
40
  "license": "MIT",
41
41
  "sideEffects": false,
42
42
  "devDependencies": {
43
- "@done-coding/cli-inject": "^0.5.6-alpha.0",
43
+ "@done-coding/cli-inject": "^0.5.8-alpha.0",
44
44
  "@types/node": "^18.0.0",
45
- "@types/pinyin": "^2.10.0",
46
45
  "@types/semver": "^7.5.3",
46
+ "@types/uuid": "^10.0.0",
47
47
  "@types/yargs": "^17.0.28",
48
48
  "rimraf": "^6.0.1",
49
49
  "typescript": "^5.2.2",
@@ -54,9 +54,9 @@
54
54
  "node": ">=18.0.0"
55
55
  },
56
56
  "dependencies": {
57
- "@done-coding/cli-utils": "^0.4.0-alpha.0",
58
- "pinyin": "^2.11.2",
59
- "semver": "^7.5.4"
57
+ "@done-coding/cli-utils": "^0.6.0-alpha.0",
58
+ "semver": "^7.5.4",
59
+ "uuid": "^11.1.0"
60
60
  },
61
- "gitHead": "360b14a641064f732b01ffd6339c2f1963945b61"
61
+ "gitHead": "5879161383e32e7bed351d71d3ef607d81dc021a"
62
62
  }
@@ -1,2 +1,3 @@
1
- declare const _default: {};
2
- export default _default;
1
+ import { type ConfigInfo } from '../types';
2
+ declare const config: ConfigInfo;
3
+ export default config;
@@ -0,0 +1,10 @@
1
+ /// <reference types="yargs" />
2
+ import type { CliHandlerArgv, SubCliInfo } from "@done-coding/cli-utils";
3
+ import type { AliasOptions, ConfigInfo } from '../types';
4
+ /** 获取别名发布选项 */
5
+ export declare const getAliasOptions: () => Record<keyof import("@done-coding/cli-utils").ConfigFileCommonOptions, import("yargs").Options>;
6
+ /** 获取别名发布信息列表 */
7
+ export declare const getAliasInfoList: (configInfo: ConfigInfo) => import('../types').ConfigInfoNpmAliasInfo[] | undefined;
8
+ /** 别名发布命令处理器 */
9
+ export declare const aliasHandler: (argv: CliHandlerArgv<AliasOptions>) => Promise<void>;
10
+ export declare const aliasCommandCliInfo: SubCliInfo;
@@ -1,6 +1,5 @@
1
- import { type ExecOptions } from '../types';
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;
@@ -1,7 +1,8 @@
1
1
  import { initHandler, initCommandCliInfo } from "./init";
2
2
  import { execHandler, execCommandCliInfo } from "./exec";
3
+ import { aliasHandler, aliasCommandCliInfo } from "./alias";
3
4
  import { SubcommandEnum } from '../types';
4
5
  import { type CliHandlerArgv, type CliInfo } from "@done-coding/cli-utils";
5
- export { initHandler, initCommandCliInfo, execHandler, execCommandCliInfo };
6
+ export { initHandler, initCommandCliInfo, execHandler, execCommandCliInfo, aliasHandler, aliasCommandCliInfo, };
6
7
  export declare const handler: (command: SubcommandEnum, argv: CliHandlerArgv<any>) => Promise<void>;
7
8
  export declare const commandCliInfo: Omit<CliInfo, "usage">;
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
2
  "name": "@done-coding/cli-publish",
3
- "version": "0.6.0-alpha.0",
3
+ "version": "0.7.0-alpha.0",
4
4
  "description": "项目发布命令行工具",
5
5
  "cliConfig": {
6
6
  "namespaceDir": ".done-coding",
@@ -1,10 +1,12 @@
1
- import type { InitConfigFileOptions, ReadConfigFileOptions } from "@done-coding/cli-utils";
1
+ import type { GetGitLastCommitParams, InitConfigFileOptions, PackageJson, ReadConfigFileOptions } from "@done-coding/cli-utils";
2
2
  /** 子命令枚举 */
3
3
  export declare enum SubcommandEnum {
4
4
  /** 初始化发布配置文件 */
5
5
  INIT = "init",
6
6
  /** 发布执行 */
7
- EXEC = "exec"
7
+ EXEC = "exec",
8
+ /** 发布别名 */
9
+ ALIAS = "alias"
8
10
  }
9
11
  export type InitOptions = InitConfigFileOptions;
10
12
  /**
@@ -57,51 +59,6 @@ export declare enum PublishTagEnum {
57
59
  */
58
60
  ALPHA = "alpha"
59
61
  }
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
62
  /**
106
63
  * npm信息
107
64
  */
@@ -119,19 +76,6 @@ export interface NpmInfo {
119
76
  */
120
77
  tag: PublishTagEnum;
121
78
  }
122
- /**
123
- * 配置信息
124
- */
125
- export interface ConfigInfo {
126
- /**
127
- * web构建命令
128
- */
129
- webBuild?: string;
130
- /**
131
- * git远程仓库名
132
- */
133
- gitOriginName: string;
134
- }
135
79
  /** 发布模式 */
136
80
  export declare enum PublishModeEnum {
137
81
  /** npm发布模式 */
@@ -139,6 +83,33 @@ export declare enum PublishModeEnum {
139
83
  /** web发布模式 */
140
84
  WEB = "web"
141
85
  }
86
+ /** 发布配置- web模式 */
87
+ export interface ConfigInfoWeb extends GetGitLastCommitParams {
88
+ /**
89
+ * web构建命令
90
+ */
91
+ build?: string;
92
+ }
93
+ /** 发布配置- npm模式-别名信息 */
94
+ export interface ConfigInfoNpmAliasInfo {
95
+ packageJson: Partial<Omit<PackageJson, "name">> & {
96
+ name: string;
97
+ };
98
+ }
99
+ /** 发布配置- npm模式 */
100
+ export interface ConfigInfoNpm extends GetGitLastCommitParams {
101
+ /** 别名信息 */
102
+ aliasInfo?: ConfigInfoNpmAliasInfo[];
103
+ }
104
+ /**
105
+ * 配置信息
106
+ */
107
+ export interface ConfigInfo {
108
+ /** web发布配置 */
109
+ [PublishModeEnum.WEB]?: ConfigInfoWeb;
110
+ /** NPM发布配置 */
111
+ [PublishModeEnum.NPM]?: ConfigInfoNpm;
112
+ }
142
113
  export interface ExecOptions extends ReadConfigFileOptions {
143
114
  /** 发布模式 */
144
115
  mode: PublishModeEnum;
@@ -149,3 +120,5 @@ export interface ExecOptions extends ReadConfigFileOptions {
149
120
  /** (发布成功后)是否推送至远程仓库 */
150
121
  push: boolean;
151
122
  }
123
+ export interface AliasOptions extends ReadConfigFileOptions {
124
+ }
@@ -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
- };