@done-coding/cli-publish 0.4.5-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 -6
- package/es/{index-3eb0cae4.js → index-1c86019f.js} +66 -72
- package/es/index.mjs +4 -8
- package/package.json +5 -9
- 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,13 +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
|
-
import "chalk";
|
|
9
|
-
import "prompts";
|
|
10
8
|
import "@done-coding/cli-utils";
|
|
11
|
-
|
|
12
|
-
import "yargs/helpers";
|
|
13
|
-
r();
|
|
9
|
+
m();
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { inc as A, prerelease as
|
|
3
|
-
import { join as
|
|
2
|
+
import { inc as A, prerelease as $ } from "semver";
|
|
3
|
+
import { join as O } from "node:path";
|
|
4
4
|
import { execSync as n } from "node:child_process";
|
|
5
5
|
import P from "pinyin";
|
|
6
|
-
import { readFileSync as
|
|
7
|
-
import p from "
|
|
8
|
-
import I from "prompts";
|
|
9
|
-
import { onPromptFormStateForSigint as H } from "@done-coding/cli-utils";
|
|
10
|
-
import w from "yargs";
|
|
11
|
-
import { hideBin as J } from "yargs/helpers";
|
|
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";
|
|
12
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 || {});
|
|
13
|
-
const
|
|
9
|
+
const y = "/.dc/publish.json", N = "/package.json", J = ({ gitOriginName: t = "origin" }) => {
|
|
14
10
|
try {
|
|
15
|
-
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(),
|
|
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();
|
|
16
12
|
let f = "";
|
|
17
13
|
try {
|
|
18
14
|
f = n(`git config --get remote.${t}.url`).toString().trim();
|
|
@@ -27,9 +23,9 @@ const L = "/.dc/publish.json", N = "/package.json", T = ({ gitOriginName: t = "o
|
|
|
27
23
|
heteronym: !1
|
|
28
24
|
}).join(""),
|
|
29
25
|
lastCommitEmail: c,
|
|
30
|
-
lastCommitMsg:
|
|
31
|
-
userName:
|
|
32
|
-
userNamePinYin: P(
|
|
26
|
+
lastCommitMsg: s,
|
|
27
|
+
userName: i,
|
|
28
|
+
userNamePinYin: P(i, {
|
|
33
29
|
style: P.STYLE_NORMAL,
|
|
34
30
|
heteronym: !1
|
|
35
31
|
}).join(""),
|
|
@@ -40,65 +36,61 @@ const L = "/.dc/publish.json", N = "/package.json", T = ({ gitOriginName: t = "o
|
|
|
40
36
|
} catch (o) {
|
|
41
37
|
throw console.error("Error fetching git information:", o), o;
|
|
42
38
|
}
|
|
43
|
-
}, R = (t, o = JSON.parse(
|
|
44
|
-
let m = o.name, c = "",
|
|
45
|
-
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;
|
|
46
42
|
if ([
|
|
47
43
|
e.MAJOR,
|
|
48
44
|
e.MINOR,
|
|
49
45
|
e.PATCH
|
|
50
46
|
].includes(t))
|
|
51
|
-
c = A(
|
|
47
|
+
c = A(i, t), s = d.LATEST;
|
|
52
48
|
else if ([
|
|
53
49
|
e.PREMAJOR,
|
|
54
50
|
e.PREMINOR,
|
|
55
51
|
e.PREPATCH
|
|
56
52
|
].includes(t)) {
|
|
57
|
-
const l =
|
|
58
|
-
l ? (
|
|
59
|
-
|
|
60
|
-
), l.length === 1 && typeof l[0] == "number" ? c = A(
|
|
61
|
-
s,
|
|
53
|
+
const l = $(i);
|
|
54
|
+
l ? (p.warn("当前版本已经是预发布版本,将会在当前版本基础上进行发布"), l.length === 1 && typeof l[0] == "number" ? c = A(
|
|
55
|
+
i,
|
|
62
56
|
e.PRERELEASE
|
|
63
|
-
) : c =
|
|
57
|
+
) : c = i.split("-")[0] + "-0") : c = A(i, t), s = d.NEXT;
|
|
64
58
|
} else
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
s = d.ALPHA, c = A(
|
|
60
|
+
i,
|
|
67
61
|
e.PRERELEASE,
|
|
68
|
-
|
|
62
|
+
s
|
|
69
63
|
);
|
|
70
64
|
if (!c)
|
|
71
65
|
throw new Error("version is empty");
|
|
72
66
|
return {
|
|
73
67
|
name: m,
|
|
74
68
|
version: c,
|
|
75
|
-
tag:
|
|
69
|
+
tag: s
|
|
76
70
|
};
|
|
77
|
-
},
|
|
71
|
+
}, L = () => {
|
|
78
72
|
let t;
|
|
79
|
-
const o =
|
|
80
|
-
if (
|
|
81
|
-
const m =
|
|
73
|
+
const o = O(process.cwd(), y);
|
|
74
|
+
if (C(o)) {
|
|
75
|
+
const m = v(o, "utf-8");
|
|
82
76
|
t = JSON.parse(m);
|
|
83
77
|
} else
|
|
84
|
-
|
|
85
|
-
p.yellow(`未找到配置文件,将使用默认配置
|
|
78
|
+
p.warn(`未找到配置文件,将使用默认配置
|
|
86
79
|
{ gitOriginName: "origin" }
|
|
87
|
-
`)
|
|
88
|
-
);
|
|
80
|
+
`);
|
|
89
81
|
return {
|
|
90
82
|
gitOriginName: "origin",
|
|
91
83
|
...t || {}
|
|
92
84
|
};
|
|
93
|
-
},
|
|
85
|
+
}, T = async (t) => {
|
|
94
86
|
console.log(t);
|
|
95
|
-
const { mode: o, type: m, push: c } = t,
|
|
96
|
-
console.log("gitInfo:",
|
|
87
|
+
const { mode: o, type: m, push: c } = t, s = L(), i = J(s);
|
|
88
|
+
console.log("gitInfo:", i);
|
|
97
89
|
let l = m, g;
|
|
98
90
|
if (l)
|
|
99
91
|
console.log("type:", l), g = await R(l);
|
|
100
92
|
else {
|
|
101
|
-
const r = JSON.parse(
|
|
93
|
+
const r = JSON.parse(v(O(process.cwd(), N), "utf-8")), a = {
|
|
102
94
|
[e.MAJOR]: R(
|
|
103
95
|
e.MAJOR,
|
|
104
96
|
r
|
|
@@ -127,7 +119,7 @@ const L = "/.dc/publish.json", N = "/package.json", T = ({ gitOriginName: t = "o
|
|
|
127
119
|
e.PRERELEASE,
|
|
128
120
|
r
|
|
129
121
|
)
|
|
130
|
-
},
|
|
122
|
+
}, S = [
|
|
131
123
|
{
|
|
132
124
|
title: `主版本(${a[e.MAJOR].version})`,
|
|
133
125
|
value: e.MAJOR
|
|
@@ -161,8 +153,7 @@ const L = "/.dc/publish.json", N = "/package.json", T = ({ gitOriginName: t = "o
|
|
|
161
153
|
type: "select",
|
|
162
154
|
name: "type",
|
|
163
155
|
message: `请选择发布类型,当前版本:${r.version}`,
|
|
164
|
-
choices:
|
|
165
|
-
onState: H
|
|
156
|
+
choices: S
|
|
166
157
|
})).type, g = a[l];
|
|
167
158
|
}
|
|
168
159
|
const { version: f } = g;
|
|
@@ -172,33 +163,35 @@ const L = "/.dc/publish.json", N = "/package.json", T = ({ gitOriginName: t = "o
|
|
|
172
163
|
const { tag: r } = g;
|
|
173
164
|
n(`npm publish --tag ${r} 1>&2`);
|
|
174
165
|
} else if (o === E.WEB) {
|
|
175
|
-
const { webBuild: r } =
|
|
176
|
-
r ? n(`${r} 1>&2`) :
|
|
166
|
+
const { webBuild: r } = s;
|
|
167
|
+
r ? n(`${r} 1>&2`) : p.warn("webBuild为空,不执行web构建");
|
|
177
168
|
} else
|
|
178
169
|
throw new Error("未知命令");
|
|
179
170
|
} catch (r) {
|
|
180
|
-
|
|
171
|
+
p.error(`发布失败, error: ${r.message}`);
|
|
181
172
|
try {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
);
|
|
185
|
-
const { lastHash: a } = s;
|
|
186
|
-
n(`git reset --hard ${a} 1>&2`), console.log(p.blue(`删除本次发布时生成的tag:v${g.version}`)), n(`git tag -d v${g.version} 1>&2`);
|
|
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`);
|
|
187
176
|
} catch (a) {
|
|
188
|
-
|
|
177
|
+
p.error(`回滚失败, error: ${a.message}`);
|
|
189
178
|
}
|
|
190
179
|
return process.exit(1);
|
|
191
180
|
}
|
|
192
|
-
c && (n(`git push ${
|
|
193
|
-
},
|
|
194
|
-
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",
|
|
195
184
|
name: "@done-coding/cli-publish",
|
|
196
185
|
description: "项目发布命令行工具",
|
|
197
186
|
cliConfig: {
|
|
198
187
|
namespaceDir: ".done-coding",
|
|
199
188
|
moduleName: "publish"
|
|
200
189
|
}
|
|
201
|
-
},
|
|
190
|
+
}, {
|
|
191
|
+
version: j,
|
|
192
|
+
description: x,
|
|
193
|
+
cliConfig: { moduleName: M }
|
|
194
|
+
} = b, B = () => ({
|
|
202
195
|
mode: {
|
|
203
196
|
alias: "m",
|
|
204
197
|
describe: "发布模式",
|
|
@@ -224,23 +217,24 @@ const L = "/.dc/publish.json", N = "/package.json", T = ({ gitOriginName: t = "o
|
|
|
224
217
|
type: "boolean",
|
|
225
218
|
default: !0
|
|
226
219
|
}
|
|
227
|
-
}), u =
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
},
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
220
|
+
}), u = {
|
|
221
|
+
describe: x,
|
|
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
|
+
});
|
|
241
235
|
export {
|
|
242
236
|
E as P,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
237
|
+
F as a,
|
|
238
|
+
_ as c,
|
|
239
|
+
T as h
|
|
246
240
|
};
|
package/es/index.mjs
CHANGED
|
@@ -1,17 +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
|
-
import "chalk";
|
|
9
|
-
import "prompts";
|
|
10
8
|
import "@done-coding/cli-utils";
|
|
11
|
-
import "yargs";
|
|
12
|
-
import "yargs/helpers";
|
|
13
9
|
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
n as PublishModeEnum,
|
|
11
|
+
s as crateAsSubcommand,
|
|
12
|
+
d as handler
|
|
17
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,10 +41,9 @@
|
|
|
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
|
-
"@types/prompts": "^2.4.6",
|
|
48
47
|
"@types/semver": "^7.5.3",
|
|
49
48
|
"@types/yargs": "^17.0.28",
|
|
50
49
|
"rimraf": "^6.0.1",
|
|
@@ -56,12 +55,9 @@
|
|
|
56
55
|
"node": ">=18.0.0"
|
|
57
56
|
},
|
|
58
57
|
"dependencies": {
|
|
59
|
-
"@done-coding/cli-utils": "^0.
|
|
60
|
-
"chalk": "^5.3.0",
|
|
58
|
+
"@done-coding/cli-utils": "^0.3.0-alpha.0",
|
|
61
59
|
"pinyin": "^2.11.2",
|
|
62
|
-
"
|
|
63
|
-
"semver": "^7.5.4",
|
|
64
|
-
"yargs": "^17.7.2"
|
|
60
|
+
"semver": "^7.5.4"
|
|
65
61
|
},
|
|
66
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "c5a54bdf08759425701a2024442a923883065189"
|
|
67
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<{}, {}>;
|