@done-coding/cli-publish 0.4.6-alpha.0 → 0.5.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 +2 -4
- package/es/{index-f4b0258f.js → index-1c86019f.js} +79 -76
- package/es/index.mjs +4 -6
- package/package.json +5 -6
- package/types/handler.d.ts +2 -2
- package/types/index.d.ts +1 -1
- package/types/injectInfo.json.d.ts +1 -1
- package/types/main.d.ts +9 -4
package/es/cli.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { c as
|
|
2
|
+
import { c as m } from "./index-1c86019f.js";
|
|
3
3
|
import "semver";
|
|
4
4
|
import "node:path";
|
|
5
5
|
import "node:child_process";
|
|
6
6
|
import "pinyin";
|
|
7
7
|
import "node:fs";
|
|
8
8
|
import "@done-coding/cli-utils";
|
|
9
|
-
|
|
10
|
-
import "yargs/helpers";
|
|
11
|
-
r();
|
|
9
|
+
m();
|
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { inc as A, prerelease as
|
|
3
|
-
import { join as
|
|
4
|
-
import { execSync as
|
|
2
|
+
import { inc as A, prerelease as $ } from "semver";
|
|
3
|
+
import { join as O } from "node:path";
|
|
4
|
+
import { execSync as n } from "node:child_process";
|
|
5
5
|
import P from "pinyin";
|
|
6
|
-
import { readFileSync as
|
|
7
|
-
import { xPrompts as
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var E = /* @__PURE__ */ ((t) => (t.NPM = "npm", t.WEB = "web", t))(E || {}), e = /* @__PURE__ */ ((t) => (t.MAJOR = "major", t.MINOR = "minor", t.PATCH = "patch", t.PREMAJOR = "premajor", t.PREMINOR = "preminor", t.PREPATCH = "prepatch", t.PRERELEASE = "prerelease", t))(e || {}), v = /* @__PURE__ */ ((t) => (t.LATEST = "latest", t.NEXT = "next", t.ALPHA = "alpha", t))(v || {});
|
|
11
|
-
const J = "/.dc/publish.json", N = "/package.json", L = ({ gitOriginName: t = "origin" }) => {
|
|
6
|
+
import { readFileSync as v, existsSync as C } from "node:fs";
|
|
7
|
+
import { xPrompts as I, log as p, createMainCommand as H, createSubcommand as w } from "@done-coding/cli-utils";
|
|
8
|
+
var E = /* @__PURE__ */ ((t) => (t.NPM = "npm", t.WEB = "web", t))(E || {}), e = /* @__PURE__ */ ((t) => (t.MAJOR = "major", t.MINOR = "minor", t.PATCH = "patch", t.PREMAJOR = "premajor", t.PREMINOR = "preminor", t.PREPATCH = "prepatch", t.PRERELEASE = "prerelease", t))(e || {}), d = /* @__PURE__ */ ((t) => (t.LATEST = "latest", t.NEXT = "next", t.ALPHA = "alpha", t))(d || {});
|
|
9
|
+
const y = "/.dc/publish.json", N = "/package.json", J = ({ gitOriginName: t = "origin" }) => {
|
|
12
10
|
try {
|
|
13
|
-
const
|
|
11
|
+
const o = n("git rev-parse HEAD").toString().trim(), m = n('git log -1 --pretty=format:"%an"').toString().trim(), c = n('git log -1 --pretty=format:"%ae"').toString().trim(), s = n('git log -1 --pretty=format:"%s"').toString().trim(), i = n("git config user.name").toString().trim(), l = n("git config user.email").toString().trim(), g = n("git rev-parse --abbrev-ref HEAD").toString().trim();
|
|
14
12
|
let f = "";
|
|
15
13
|
try {
|
|
16
|
-
f =
|
|
14
|
+
f = n(`git config --get remote.${t}.url`).toString().trim();
|
|
17
15
|
} catch {
|
|
18
16
|
throw new Error(`git remote ${t} 不存在`);
|
|
19
17
|
}
|
|
20
18
|
return {
|
|
21
|
-
lastHash:
|
|
19
|
+
lastHash: o,
|
|
22
20
|
lastCommitter: m,
|
|
23
21
|
lastCommitterPinYin: P(m, {
|
|
24
22
|
style: P.STYLE_NORMAL,
|
|
@@ -26,8 +24,8 @@ const J = "/.dc/publish.json", N = "/package.json", L = ({ gitOriginName: t = "o
|
|
|
26
24
|
}).join(""),
|
|
27
25
|
lastCommitEmail: c,
|
|
28
26
|
lastCommitMsg: s,
|
|
29
|
-
userName:
|
|
30
|
-
userNamePinYin: P(
|
|
27
|
+
userName: i,
|
|
28
|
+
userNamePinYin: P(i, {
|
|
31
29
|
style: P.STYLE_NORMAL,
|
|
32
30
|
heteronym: !1
|
|
33
31
|
}).join(""),
|
|
@@ -35,31 +33,31 @@ const J = "/.dc/publish.json", N = "/package.json", L = ({ gitOriginName: t = "o
|
|
|
35
33
|
branchName: g,
|
|
36
34
|
remoteUrl: f
|
|
37
35
|
};
|
|
38
|
-
} catch (
|
|
39
|
-
throw console.error("Error fetching git information:",
|
|
36
|
+
} catch (o) {
|
|
37
|
+
throw console.error("Error fetching git information:", o), o;
|
|
40
38
|
}
|
|
41
|
-
}, R = (t,
|
|
42
|
-
let m =
|
|
43
|
-
const { version:
|
|
39
|
+
}, R = (t, o = JSON.parse(v(O(process.cwd(), N), "utf-8"))) => {
|
|
40
|
+
let m = o.name, c = "", s;
|
|
41
|
+
const { version: i } = o;
|
|
44
42
|
if ([
|
|
45
43
|
e.MAJOR,
|
|
46
44
|
e.MINOR,
|
|
47
45
|
e.PATCH
|
|
48
46
|
].includes(t))
|
|
49
|
-
c = A(
|
|
47
|
+
c = A(i, t), s = d.LATEST;
|
|
50
48
|
else if ([
|
|
51
49
|
e.PREMAJOR,
|
|
52
50
|
e.PREMINOR,
|
|
53
51
|
e.PREPATCH
|
|
54
52
|
].includes(t)) {
|
|
55
|
-
const l =
|
|
53
|
+
const l = $(i);
|
|
56
54
|
l ? (p.warn("当前版本已经是预发布版本,将会在当前版本基础上进行发布"), l.length === 1 && typeof l[0] == "number" ? c = A(
|
|
57
|
-
|
|
55
|
+
i,
|
|
58
56
|
e.PRERELEASE
|
|
59
|
-
) : c =
|
|
57
|
+
) : c = i.split("-")[0] + "-0") : c = A(i, t), s = d.NEXT;
|
|
60
58
|
} else
|
|
61
|
-
s =
|
|
62
|
-
|
|
59
|
+
s = d.ALPHA, c = A(
|
|
60
|
+
i,
|
|
63
61
|
e.PRERELEASE,
|
|
64
62
|
s
|
|
65
63
|
);
|
|
@@ -70,11 +68,11 @@ const J = "/.dc/publish.json", N = "/package.json", L = ({ gitOriginName: t = "o
|
|
|
70
68
|
version: c,
|
|
71
69
|
tag: s
|
|
72
70
|
};
|
|
73
|
-
},
|
|
71
|
+
}, L = () => {
|
|
74
72
|
let t;
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
const m =
|
|
73
|
+
const o = O(process.cwd(), y);
|
|
74
|
+
if (C(o)) {
|
|
75
|
+
const m = v(o, "utf-8");
|
|
78
76
|
t = JSON.parse(m);
|
|
79
77
|
} else
|
|
80
78
|
p.warn(`未找到配置文件,将使用默认配置
|
|
@@ -84,44 +82,44 @@ const J = "/.dc/publish.json", N = "/package.json", L = ({ gitOriginName: t = "o
|
|
|
84
82
|
gitOriginName: "origin",
|
|
85
83
|
...t || {}
|
|
86
84
|
};
|
|
87
|
-
},
|
|
85
|
+
}, T = async (t) => {
|
|
88
86
|
console.log(t);
|
|
89
|
-
const { mode:
|
|
90
|
-
console.log("gitInfo:",
|
|
87
|
+
const { mode: o, type: m, push: c } = t, s = L(), i = J(s);
|
|
88
|
+
console.log("gitInfo:", i);
|
|
91
89
|
let l = m, g;
|
|
92
90
|
if (l)
|
|
93
91
|
console.log("type:", l), g = await R(l);
|
|
94
92
|
else {
|
|
95
|
-
const
|
|
93
|
+
const r = JSON.parse(v(O(process.cwd(), N), "utf-8")), a = {
|
|
96
94
|
[e.MAJOR]: R(
|
|
97
95
|
e.MAJOR,
|
|
98
|
-
|
|
96
|
+
r
|
|
99
97
|
),
|
|
100
98
|
[e.MINOR]: R(
|
|
101
99
|
e.MINOR,
|
|
102
|
-
|
|
100
|
+
r
|
|
103
101
|
),
|
|
104
102
|
[e.PATCH]: R(
|
|
105
103
|
e.PATCH,
|
|
106
|
-
|
|
104
|
+
r
|
|
107
105
|
),
|
|
108
106
|
[e.PREMAJOR]: R(
|
|
109
107
|
e.PREMAJOR,
|
|
110
|
-
|
|
108
|
+
r
|
|
111
109
|
),
|
|
112
110
|
[e.PREMINOR]: R(
|
|
113
111
|
e.PREMINOR,
|
|
114
|
-
|
|
112
|
+
r
|
|
115
113
|
),
|
|
116
114
|
[e.PREPATCH]: R(
|
|
117
115
|
e.PREPATCH,
|
|
118
|
-
|
|
116
|
+
r
|
|
119
117
|
),
|
|
120
118
|
[e.PRERELEASE]: R(
|
|
121
119
|
e.PRERELEASE,
|
|
122
|
-
|
|
120
|
+
r
|
|
123
121
|
)
|
|
124
|
-
},
|
|
122
|
+
}, S = [
|
|
125
123
|
{
|
|
126
124
|
title: `主版本(${a[e.MAJOR].version})`,
|
|
127
125
|
value: e.MAJOR
|
|
@@ -151,45 +149,49 @@ const J = "/.dc/publish.json", N = "/package.json", L = ({ gitOriginName: t = "o
|
|
|
151
149
|
value: e.PRERELEASE
|
|
152
150
|
}
|
|
153
151
|
];
|
|
154
|
-
l = (await
|
|
152
|
+
l = (await I({
|
|
155
153
|
type: "select",
|
|
156
154
|
name: "type",
|
|
157
|
-
message: `请选择发布类型,当前版本:${
|
|
158
|
-
choices:
|
|
155
|
+
message: `请选择发布类型,当前版本:${r.version}`,
|
|
156
|
+
choices: S
|
|
159
157
|
})).type, g = a[l];
|
|
160
158
|
}
|
|
161
159
|
const { version: f } = g;
|
|
162
|
-
console.log("npmInfo:", g),
|
|
160
|
+
console.log("npmInfo:", g), n(`npm version ${f} 1>&2`);
|
|
163
161
|
try {
|
|
164
|
-
if (
|
|
165
|
-
const { tag:
|
|
166
|
-
|
|
167
|
-
} else if (
|
|
168
|
-
const { webBuild:
|
|
169
|
-
|
|
162
|
+
if (o === E.NPM) {
|
|
163
|
+
const { tag: r } = g;
|
|
164
|
+
n(`npm publish --tag ${r} 1>&2`);
|
|
165
|
+
} else if (o === E.WEB) {
|
|
166
|
+
const { webBuild: r } = s;
|
|
167
|
+
r ? n(`${r} 1>&2`) : p.warn("webBuild为空,不执行web构建");
|
|
170
168
|
} else
|
|
171
169
|
throw new Error("未知命令");
|
|
172
|
-
} catch (
|
|
173
|
-
p.error(`发布失败, error: ${
|
|
170
|
+
} catch (r) {
|
|
171
|
+
p.error(`发布失败, error: ${r.message}`);
|
|
174
172
|
try {
|
|
175
|
-
p.info(`回滚本地版本到发布前的版本:${
|
|
176
|
-
const { lastHash: a } =
|
|
177
|
-
|
|
173
|
+
p.info(`回滚本地版本到发布前的版本:${i.lastHash}`);
|
|
174
|
+
const { lastHash: a } = i;
|
|
175
|
+
n(`git reset --hard ${a} 1>&2`), p.info(`删除本次发布时生成的tag:v${g.version}`), n(`git tag -d v${g.version} 1>&2`);
|
|
178
176
|
} catch (a) {
|
|
179
177
|
p.error(`回滚失败, error: ${a.message}`);
|
|
180
178
|
}
|
|
181
179
|
return process.exit(1);
|
|
182
180
|
}
|
|
183
|
-
c && (
|
|
184
|
-
},
|
|
185
|
-
version: "0.
|
|
181
|
+
c && (n(`git push ${s.gitOriginName} v${g.version} 1>&2`), n(`git push ${s.gitOriginName} ${i.branchName} 1>&2`)), p.success(`发布成功,版本号:${f}`);
|
|
182
|
+
}, b = {
|
|
183
|
+
version: "0.5.0-alpha.0",
|
|
186
184
|
name: "@done-coding/cli-publish",
|
|
187
185
|
description: "项目发布命令行工具",
|
|
188
186
|
cliConfig: {
|
|
189
187
|
namespaceDir: ".done-coding",
|
|
190
188
|
moduleName: "publish"
|
|
191
189
|
}
|
|
192
|
-
},
|
|
190
|
+
}, {
|
|
191
|
+
version: j,
|
|
192
|
+
description: x,
|
|
193
|
+
cliConfig: { moduleName: M }
|
|
194
|
+
} = b, B = () => ({
|
|
193
195
|
mode: {
|
|
194
196
|
alias: "m",
|
|
195
197
|
describe: "发布模式",
|
|
@@ -215,23 +217,24 @@ const J = "/.dc/publish.json", N = "/package.json", L = ({ gitOriginName: t = "o
|
|
|
215
217
|
type: "boolean",
|
|
216
218
|
default: !0
|
|
217
219
|
}
|
|
218
|
-
}), u =
|
|
219
|
-
t ? p.error(t) : p.error(r.message), process.exit(1);
|
|
220
|
-
}, x = h.description, B = `Usage: $0 ${u} [options]`, U = "Usage: $0 [options]", S = (t, r) => {
|
|
221
|
-
const m = b();
|
|
222
|
-
return t.strict().usage(r).help("help").version(h.version).alias("v", "version").alias("h", "help").options(m).fail(j).argv;
|
|
223
|
-
}, D = (t) => S(t, B), z = {
|
|
224
|
-
command: u,
|
|
220
|
+
}), u = {
|
|
225
221
|
describe: x,
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
};
|
|
222
|
+
version: j,
|
|
223
|
+
options: B(),
|
|
224
|
+
handler: T
|
|
225
|
+
}, h = (t = !1) => {
|
|
226
|
+
const o = t ? M : void 0, m = `$0${t ? ` ${M}` : ""} [options]`;
|
|
227
|
+
return { command: o, usage: m };
|
|
228
|
+
}, _ = async () => H({
|
|
229
|
+
...u,
|
|
230
|
+
...h()
|
|
231
|
+
}), F = () => w({
|
|
232
|
+
...u,
|
|
233
|
+
...h(!0)
|
|
234
|
+
});
|
|
232
235
|
export {
|
|
233
236
|
E as P,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
+
F as a,
|
|
238
|
+
_ as c,
|
|
239
|
+
T as h
|
|
237
240
|
};
|
package/es/index.mjs
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { P as
|
|
2
|
+
import { P as n, a as s, h as d } from "./index-1c86019f.js";
|
|
3
3
|
import "semver";
|
|
4
4
|
import "node:path";
|
|
5
5
|
import "node:child_process";
|
|
6
6
|
import "pinyin";
|
|
7
7
|
import "node:fs";
|
|
8
8
|
import "@done-coding/cli-utils";
|
|
9
|
-
import "yargs";
|
|
10
|
-
import "yargs/helpers";
|
|
11
9
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
n as PublishModeEnum,
|
|
11
|
+
s as crateAsSubcommand,
|
|
12
|
+
d as handler
|
|
15
13
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-publish",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-alpha.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.
|
|
44
|
+
"@done-coding/cli-inject": "^0.5.0-alpha.0",
|
|
45
45
|
"@types/node": "^18.0.0",
|
|
46
46
|
"@types/pinyin": "^2.10.0",
|
|
47
47
|
"@types/semver": "^7.5.3",
|
|
@@ -55,10 +55,9 @@
|
|
|
55
55
|
"node": ">=18.0.0"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@done-coding/cli-utils": "^0.
|
|
58
|
+
"@done-coding/cli-utils": "^0.3.0-alpha.0",
|
|
59
59
|
"pinyin": "^2.11.2",
|
|
60
|
-
"semver": "^7.5.4"
|
|
61
|
-
"yargs": "^17.7.2"
|
|
60
|
+
"semver": "^7.5.4"
|
|
62
61
|
},
|
|
63
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "c5a54bdf08759425701a2024442a923883065189"
|
|
64
63
|
}
|
package/types/handler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ArgumentsCamelCase } from "yargs";
|
|
2
1
|
import { type Options } from './utils';
|
|
2
|
+
import type { CliHandlerArgv } from "@done-coding/cli-utils";
|
|
3
3
|
export type ChildCmd = "npm" | "web";
|
|
4
|
-
export declare const handler: (argv:
|
|
4
|
+
export declare const handler: (argv: CliHandlerArgv<Options>) => Promise<undefined>;
|
package/types/index.d.ts
CHANGED
package/types/main.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
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<{}, {}>;
|