dc-publish 0.6.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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @done-coding/cli-publish
2
+
3
+ 项目发布命令行工具
4
+
5
+ ## 使用
6
+
7
+ npm install @done-coding/cli-publish
package/es/cli.mjs ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { c as m } from "./index-69c14c7f.js";
3
+ import "@done-coding/cli-utils";
4
+ import "semver";
5
+ import "node:child_process";
6
+ import "pinyin";
7
+ m();
@@ -0,0 +1,252 @@
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
+ };
package/es/index.mjs ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { a as i, h as n } from "./index-69c14c7f.js";
3
+ import "@done-coding/cli-utils";
4
+ import "semver";
5
+ import "node:child_process";
6
+ import "pinyin";
7
+ export {
8
+ i as crateAsSubcommand,
9
+ n as handler
10
+ };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "dc-publish",
3
+ "version": "0.6.0-alpha.0",
4
+ "description": "项目发布命令行工具",
5
+ "private": false,
6
+ "module": "es/index.mjs",
7
+ "type": "module",
8
+ "types": "types/index.d.ts",
9
+ "bin": "es/cli.mjs",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./es/index.mjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "es",
17
+ "lib",
18
+ "types"
19
+ ],
20
+ "scripts": {},
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://gitee.com/justsosu/done-coding-cli.git",
24
+ "directory": "packages/publish"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "registry": "https://registry.npmjs.org/"
29
+ },
30
+ "author": "JustSoSu",
31
+ "license": "MIT",
32
+ "sideEffects": false,
33
+ "devDependencies": {
34
+ "@done-coding/cli-inject": "^0.5.6-alpha.0",
35
+ "@types/node": "^18.0.0",
36
+ "@types/pinyin": "^2.10.0",
37
+ "@types/semver": "^7.5.3",
38
+ "@types/yargs": "^17.0.28",
39
+ "rimraf": "^6.0.1",
40
+ "typescript": "^5.2.2",
41
+ "vite": "^4.4.11",
42
+ "vite-plugin-dts": "^3.6.0"
43
+ },
44
+ "engines": {
45
+ "node": ">=18.0.0"
46
+ },
47
+ "dependencies": {
48
+ "@done-coding/cli-utils": "^0.4.0-alpha.0",
49
+ "pinyin": "^2.11.2",
50
+ "semver": "^7.5.4"
51
+ },
52
+ "gitHead": "360b14a641064f732b01ffd6339c2f1963945b61"
53
+ }
package/types/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,6 @@
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 type ChildCmd = "npm" | "web";
5
+ export declare const execHandler: (argv: CliHandlerArgv<ExecOptions>) => Promise<undefined>;
6
+ 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;
@@ -0,0 +1,2 @@
1
+ export { handler } from './handlers';
2
+ export { crateAsSubcommand } from "./main";
@@ -0,0 +1,11 @@
1
+ declare const _default: {
2
+ "name": "@done-coding/cli-publish",
3
+ "version": "0.6.0-alpha.0",
4
+ "description": "项目发布命令行工具",
5
+ "cliConfig": {
6
+ "namespaceDir": ".done-coding",
7
+ "moduleName": "publish"
8
+ }
9
+ };
10
+
11
+ export default _default;
@@ -0,0 +1,9 @@
1
+ /// <reference types="yargs" />
2
+ /** 作为主命令创建 */
3
+ export declare const createCommand: () => Promise<void | {
4
+ [x: string]: unknown;
5
+ _: (string | number)[];
6
+ $0: string;
7
+ }>;
8
+ /** 作为子命令创建 */
9
+ export declare const crateAsSubcommand: () => import("yargs").CommandModule<{}, {}>;
@@ -0,0 +1,151 @@
1
+ import type { 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
+ * 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
+ /**
106
+ * npm信息
107
+ */
108
+ export interface NpmInfo {
109
+ /**
110
+ * 正式包名
111
+ */
112
+ name: string;
113
+ /**
114
+ * 当前版本号
115
+ */
116
+ version: string;
117
+ /**
118
+ * 标签
119
+ */
120
+ tag: PublishTagEnum;
121
+ }
122
+ /**
123
+ * 配置信息
124
+ */
125
+ export interface ConfigInfo {
126
+ /**
127
+ * web构建命令
128
+ */
129
+ webBuild?: string;
130
+ /**
131
+ * git远程仓库名
132
+ */
133
+ gitOriginName: string;
134
+ }
135
+ /** 发布模式 */
136
+ export declare enum PublishModeEnum {
137
+ /** npm发布模式 */
138
+ NPM = "npm",
139
+ /** web发布模式 */
140
+ WEB = "web"
141
+ }
142
+ export interface ExecOptions extends ReadConfigFileOptions {
143
+ /** 发布模式 */
144
+ mode: PublishModeEnum;
145
+ /**
146
+ * 发布类型
147
+ */
148
+ type?: PublishVersionTypeEnum;
149
+ /** (发布成功后)是否推送至远程仓库 */
150
+ push: boolean;
151
+ }
@@ -0,0 +1 @@
1
+ export * from "./path";
@@ -0,0 +1,4 @@
1
+ /** 模块配置相对路径 */
2
+ export declare const MODULE_CONFIG_RELATIVE_PATH: string;
3
+ /** 模块默认配置文件相对路径 */
4
+ export declare const MODULE_DEFAULT_CONFIG_RELATIVE_PATH: string;