@done-coding/cli-publish 0.7.0-alpha.0 → 0.7.0-alpha.2
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 -2
- package/es/{index-03fd1d3d.js → index-73a13ac6.js} +86 -85
- package/es/index.mjs +2 -2
- package/package.json +4 -4
- package/types/injectInfo.json.d.ts +1 -1
- package/types/utils/path.d.ts +2 -0
package/es/cli.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { c as m } from "./index-
|
|
2
|
+
import { c as m } from "./index-73a13ac6.js";
|
|
3
3
|
import "@done-coding/cli-utils";
|
|
4
|
+
import "node:os";
|
|
4
5
|
import "node:child_process";
|
|
5
6
|
import "semver";
|
|
6
7
|
import "uuid";
|
|
7
8
|
import "node:path";
|
|
8
9
|
import "node:fs";
|
|
9
|
-
import "node:os";
|
|
10
10
|
m();
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { getConfigFileCommonOptions as v, initHandlerCommon as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { getConfigFileCommonOptions as v, initHandlerCommon as U, log as m, readConfigFile as J, getPackageJson as C, getGitLastCommitInfo as j, pushGitPublishInfoToRemote as G, xPrompts as W, createSubcommand as D, createMainCommand as X } from "@done-coding/cli-utils";
|
|
3
|
+
import { tmpdir as q } from "node:os";
|
|
4
|
+
import { execSync as f } from "node:child_process";
|
|
5
|
+
import { inc as A, prerelease as z } from "semver";
|
|
5
6
|
import { v4 as K } from "uuid";
|
|
6
7
|
import w from "node:path";
|
|
7
8
|
import T, { rmSync as Q } from "node:fs";
|
|
8
|
-
|
|
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 || {});
|
|
9
|
+
var E = /* @__PURE__ */ ((e) => (e.INIT = "init", e.EXEC = "exec", e.ALIAS = "alias", e))(E || {}), 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 || {}), g = /* @__PURE__ */ ((e) => (e.LATEST = "latest", e.NEXT = "next", e.ALPHA = "alpha", e))(g || {}), l = /* @__PURE__ */ ((e) => (e.NPM = "npm", e.WEB = "web", e))(l || {});
|
|
10
10
|
const $ = {
|
|
11
11
|
name: "@done-coding/cli-publish",
|
|
12
|
-
version: "0.7.0-alpha.
|
|
12
|
+
version: "0.7.0-alpha.2",
|
|
13
13
|
description: "项目发布命令行工具",
|
|
14
14
|
cliConfig: {
|
|
15
15
|
namespaceDir: ".done-coding",
|
|
16
16
|
moduleName: "publish"
|
|
17
17
|
}
|
|
18
|
-
}, {
|
|
18
|
+
}, Y = `${q()}/.DONE_CODING_CLI/PUBLISH_ALIAS_TEMP_DIR`, {
|
|
19
19
|
cliConfig: { namespaceDir: Z, moduleName: V }
|
|
20
20
|
} = $, ee = `./${Z}/${V}`, N = `${ee}.json`, te = {
|
|
21
|
-
[
|
|
22
|
-
[
|
|
21
|
+
[l.WEB]: {},
|
|
22
|
+
[l.NPM]: {
|
|
23
23
|
aliasInfo: [
|
|
24
24
|
{
|
|
25
25
|
packageJson: {
|
|
@@ -32,61 +32,62 @@ const $ = {
|
|
|
32
32
|
}
|
|
33
33
|
}, ne = () => v({
|
|
34
34
|
configPathDefault: N
|
|
35
|
-
}),
|
|
35
|
+
}), _ = async (e) => U(te, e, {
|
|
36
36
|
onFileGenerated: () => {
|
|
37
37
|
m.info("文件生成成功");
|
|
38
38
|
}
|
|
39
39
|
}), oe = {
|
|
40
|
-
command:
|
|
40
|
+
command: E.INIT,
|
|
41
41
|
describe: "初始化配置文件",
|
|
42
42
|
options: ne(),
|
|
43
|
-
handler:
|
|
43
|
+
handler: _
|
|
44
44
|
}, se = () => v({
|
|
45
45
|
configPathDefault: N
|
|
46
|
-
}),
|
|
46
|
+
}), b = (e) => {
|
|
47
47
|
var a;
|
|
48
|
-
const n = ((a = e[
|
|
48
|
+
const n = ((a = e[l.NPM]) == null ? void 0 : a.aliasInfo) || [];
|
|
49
49
|
if (n.length)
|
|
50
50
|
return n;
|
|
51
|
-
},
|
|
52
|
-
var
|
|
53
|
-
const n = await J(e, () => ({})), a =
|
|
51
|
+
}, L = async (e) => {
|
|
52
|
+
var O;
|
|
53
|
+
const n = await J(e, () => ({})), a = b(n);
|
|
54
54
|
if (!a) {
|
|
55
55
|
m.warn("没有配置别名发布信息");
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
const { rootDir: o } = e, i = C({ rootDir: o }), { name: s, version: r } = i,
|
|
59
|
-
T.mkdirSync(
|
|
58
|
+
const { rootDir: o } = e, i = C({ rootDir: o }), { name: s, version: r } = i, c = w.resolve(Y, K());
|
|
59
|
+
T.mkdirSync(c, { recursive: !0 }), f(`pnpm add ${s}@${r}`, {
|
|
60
60
|
stdio: "inherit",
|
|
61
|
-
cwd:
|
|
61
|
+
cwd: c
|
|
62
62
|
});
|
|
63
|
-
const
|
|
63
|
+
const R = (O = f(`npm dist-tag ${s}`).toString().trim().split(`
|
|
64
64
|
`).map((I) => I.split(":").map((h) => h.trim())).find(
|
|
65
65
|
([, I]) => I === r
|
|
66
|
-
)) == null ? void 0 :
|
|
67
|
-
if (!
|
|
66
|
+
)) == null ? void 0 : O[0];
|
|
67
|
+
if (!R)
|
|
68
68
|
return m.warn(`没有找到 ${s}@${r} 对应的dist-tag`);
|
|
69
|
-
const
|
|
70
|
-
rootDir:
|
|
69
|
+
const d = w.resolve(c, "node_modules", s), u = C({
|
|
70
|
+
rootDir: d
|
|
71
71
|
});
|
|
72
72
|
for (let I of a) {
|
|
73
|
-
const { packageJson: h } = I,
|
|
74
|
-
...
|
|
73
|
+
const { packageJson: h } = I, B = {
|
|
74
|
+
...u,
|
|
75
75
|
...h
|
|
76
|
-
},
|
|
76
|
+
}, F = `${d}/package.json`;
|
|
77
77
|
T.writeFileSync(
|
|
78
|
-
|
|
79
|
-
JSON.stringify(
|
|
80
|
-
),
|
|
78
|
+
F,
|
|
79
|
+
JSON.stringify(B, null, 2)
|
|
80
|
+
), f(`pnpm publish --tag ${R}`, {
|
|
81
81
|
stdio: "inherit",
|
|
82
|
-
cwd:
|
|
83
|
-
})
|
|
82
|
+
cwd: d
|
|
83
|
+
});
|
|
84
84
|
}
|
|
85
|
+
Q(c, { recursive: !0, force: !0 });
|
|
85
86
|
}, re = {
|
|
86
|
-
command:
|
|
87
|
+
command: E.ALIAS,
|
|
87
88
|
describe: "别名发布",
|
|
88
89
|
options: se(),
|
|
89
|
-
handler:
|
|
90
|
+
handler: L
|
|
90
91
|
}, ie = () => ({
|
|
91
92
|
...v({
|
|
92
93
|
configPathDefault: N
|
|
@@ -94,8 +95,8 @@ const $ = {
|
|
|
94
95
|
mode: {
|
|
95
96
|
alias: "m",
|
|
96
97
|
describe: "发布模式",
|
|
97
|
-
choices: [
|
|
98
|
-
default:
|
|
98
|
+
choices: [l.NPM, l.WEB],
|
|
99
|
+
default: l.NPM
|
|
99
100
|
},
|
|
100
101
|
type: {
|
|
101
102
|
alias: "t",
|
|
@@ -129,19 +130,19 @@ const $ = {
|
|
|
129
130
|
t.MINOR,
|
|
130
131
|
t.PATCH
|
|
131
132
|
].includes(n))
|
|
132
|
-
o =
|
|
133
|
+
o = A(s, n), i = g.LATEST;
|
|
133
134
|
else if ([
|
|
134
135
|
t.PREMAJOR,
|
|
135
136
|
t.PREMINOR,
|
|
136
137
|
t.PREPATCH
|
|
137
138
|
].includes(n)) {
|
|
138
139
|
const r = z(s);
|
|
139
|
-
r ? (m.warn("当前版本已经是预发布版本,将会在当前版本基础上进行发布"), r.length === 1 && typeof r[0] == "number" ? o =
|
|
140
|
+
r ? (m.warn("当前版本已经是预发布版本,将会在当前版本基础上进行发布"), r.length === 1 && typeof r[0] == "number" ? o = A(
|
|
140
141
|
s,
|
|
141
142
|
t.PRERELEASE
|
|
142
|
-
) : o = s.split("-")[0] + "-0") : o =
|
|
143
|
+
) : o = s.split("-")[0] + "-0") : o = A(s, n), i = g.NEXT;
|
|
143
144
|
} else
|
|
144
|
-
i =
|
|
145
|
+
i = g.ALPHA, o = A(
|
|
145
146
|
s,
|
|
146
147
|
t.PRERELEASE,
|
|
147
148
|
i
|
|
@@ -166,9 +167,9 @@ const $ = {
|
|
|
166
167
|
const o = Object.values(t).filter(
|
|
167
168
|
(r) => r.toUpperCase() !== r
|
|
168
169
|
).reduce(
|
|
169
|
-
(r,
|
|
170
|
+
(r, c) => (r[c] = H({
|
|
170
171
|
packageJson: n,
|
|
171
|
-
type:
|
|
172
|
+
type: c
|
|
172
173
|
}), r),
|
|
173
174
|
{}
|
|
174
175
|
), i = [
|
|
@@ -200,7 +201,7 @@ const $ = {
|
|
|
200
201
|
title: `alpha版本(${o[t.PRERELEASE].version})`,
|
|
201
202
|
value: t.PRERELEASE
|
|
202
203
|
}
|
|
203
|
-
], { type: s } = await
|
|
204
|
+
], { type: s } = await W({
|
|
204
205
|
type: "select",
|
|
205
206
|
name: "type",
|
|
206
207
|
message: `请选择发布类型,当前版本:${n.version}`,
|
|
@@ -208,22 +209,22 @@ const $ = {
|
|
|
208
209
|
});
|
|
209
210
|
return o[s];
|
|
210
211
|
}
|
|
211
|
-
},
|
|
212
|
-
const { mode: n, type: a, push: o, rootDir: i } = e, s = await J(e, () => ({})), r = s[n],
|
|
212
|
+
}, y = async (e) => {
|
|
213
|
+
const { mode: n, type: a, push: o, rootDir: i } = e, s = await J(e, () => ({})), r = s[n], c = await j(r), M = C({ rootDir: i }), p = await ae({
|
|
213
214
|
type: a,
|
|
214
|
-
packageJson:
|
|
215
|
-
}), { version: P } =
|
|
216
|
-
|
|
215
|
+
packageJson: M
|
|
216
|
+
}), { version: P } = p;
|
|
217
|
+
f(`npm version ${P}`, {
|
|
217
218
|
cwd: i,
|
|
218
219
|
stdio: "inherit"
|
|
219
220
|
});
|
|
220
|
-
const { tag:
|
|
221
|
+
const { tag: R } = p;
|
|
221
222
|
try {
|
|
222
223
|
switch (n) {
|
|
223
|
-
case
|
|
224
|
-
const { build:
|
|
225
|
-
if (
|
|
226
|
-
|
|
224
|
+
case l.WEB: {
|
|
225
|
+
const { build: d } = r;
|
|
226
|
+
if (d)
|
|
227
|
+
f(`${d}`, {
|
|
227
228
|
stdio: "inherit",
|
|
228
229
|
cwd: i
|
|
229
230
|
});
|
|
@@ -231,8 +232,8 @@ const $ = {
|
|
|
231
232
|
throw new Error("未配置build命令");
|
|
232
233
|
break;
|
|
233
234
|
}
|
|
234
|
-
case
|
|
235
|
-
|
|
235
|
+
case l.NPM: {
|
|
236
|
+
f(`npm publish --tag ${R}`, {
|
|
236
237
|
cwd: i,
|
|
237
238
|
stdio: "inherit"
|
|
238
239
|
});
|
|
@@ -241,65 +242,65 @@ const $ = {
|
|
|
241
242
|
default:
|
|
242
243
|
throw new Error(`未知发布模式:${n}`);
|
|
243
244
|
}
|
|
244
|
-
} catch (
|
|
245
|
-
m.error(`发布失败, error: ${
|
|
245
|
+
} catch (d) {
|
|
246
|
+
m.error(`发布失败, error: ${d.message}`);
|
|
246
247
|
try {
|
|
247
|
-
m.info(`回滚本地版本到发布前的版本:${
|
|
248
|
-
const { lastHash:
|
|
249
|
-
|
|
248
|
+
m.info(`回滚本地版本到发布前的版本:${c.lastHash}`);
|
|
249
|
+
const { lastHash: u } = c;
|
|
250
|
+
f(`git reset --hard ${u}`, {
|
|
250
251
|
stdio: "inherit"
|
|
251
|
-
}), m.info(`删除本次发布时生成的tag:v${
|
|
252
|
+
}), m.info(`删除本次发布时生成的tag:v${p.version}`), f(`git tag -d v${p.version}`, {
|
|
252
253
|
stdio: "inherit"
|
|
253
254
|
});
|
|
254
|
-
} catch (
|
|
255
|
-
m.error(`回滚失败, error: ${
|
|
255
|
+
} catch (u) {
|
|
256
|
+
m.error(`回滚失败, error: ${u.message}`);
|
|
256
257
|
}
|
|
257
258
|
return process.exit(1);
|
|
258
259
|
}
|
|
259
|
-
o &&
|
|
260
|
-
branchName:
|
|
261
|
-
version:
|
|
262
|
-
remoteInfo:
|
|
263
|
-
}), m.success(`发布成功,版本号:${P}`), n ===
|
|
260
|
+
o && G({
|
|
261
|
+
branchName: c.branchName,
|
|
262
|
+
version: p.version,
|
|
263
|
+
remoteInfo: c.remoteInfo
|
|
264
|
+
}), m.success(`发布成功,版本号:${P}`), n === l.NPM && b(s) && L(e);
|
|
264
265
|
}, ce = {
|
|
265
266
|
command: "$0",
|
|
266
267
|
describe: "执行发布命令",
|
|
267
268
|
options: ie(),
|
|
268
|
-
handler:
|
|
269
|
-
},
|
|
269
|
+
handler: y
|
|
270
|
+
}, Ae = async (e, n) => {
|
|
270
271
|
switch (e) {
|
|
271
|
-
case
|
|
272
|
-
return
|
|
273
|
-
case
|
|
274
|
-
return
|
|
275
|
-
case
|
|
276
|
-
return
|
|
272
|
+
case E.INIT:
|
|
273
|
+
return _(n);
|
|
274
|
+
case E.EXEC:
|
|
275
|
+
return y(n);
|
|
276
|
+
case E.ALIAS:
|
|
277
|
+
return L(n);
|
|
277
278
|
default:
|
|
278
279
|
throw new Error(`不支持的命令 ${e}`);
|
|
279
280
|
}
|
|
280
|
-
}, { version: le, description: me } = $,
|
|
281
|
+
}, { version: le, description: me } = $, k = {
|
|
281
282
|
describe: me,
|
|
282
283
|
version: le,
|
|
283
284
|
subcommands: [
|
|
284
285
|
oe,
|
|
285
286
|
ce,
|
|
286
287
|
re
|
|
287
|
-
].map(
|
|
288
|
+
].map(D),
|
|
288
289
|
demandCommandCount: 1
|
|
289
290
|
}, {
|
|
290
291
|
cliConfig: { moduleName: S }
|
|
291
292
|
} = $, x = (e = !1) => {
|
|
292
293
|
const n = e ? S : void 0, a = `$0${e ? ` ${S}` : ""} [options]`;
|
|
293
294
|
return { command: n, usage: a };
|
|
294
|
-
},
|
|
295
|
-
...
|
|
295
|
+
}, ge = async () => X({
|
|
296
|
+
...k,
|
|
296
297
|
...x()
|
|
297
|
-
}), Pe = () =>
|
|
298
|
-
...
|
|
298
|
+
}), Pe = () => D({
|
|
299
|
+
...k,
|
|
299
300
|
...x(!0)
|
|
300
301
|
});
|
|
301
302
|
export {
|
|
302
303
|
Pe as a,
|
|
303
|
-
|
|
304
|
-
|
|
304
|
+
ge as c,
|
|
305
|
+
Ae as h
|
|
305
306
|
};
|
package/es/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as s, h as d } from "./index-
|
|
2
|
+
import { a as s, h as d } from "./index-73a13ac6.js";
|
|
3
3
|
import "@done-coding/cli-utils";
|
|
4
|
+
import "node:os";
|
|
4
5
|
import "node:child_process";
|
|
5
6
|
import "semver";
|
|
6
7
|
import "uuid";
|
|
7
8
|
import "node:path";
|
|
8
9
|
import "node:fs";
|
|
9
|
-
import "node:os";
|
|
10
10
|
export {
|
|
11
11
|
s as crateAsSubcommand,
|
|
12
12
|
d as handler
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-publish",
|
|
3
|
-
"version": "0.7.0-alpha.
|
|
3
|
+
"version": "0.7.0-alpha.2",
|
|
4
4
|
"description": "项目发布命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"sideEffects": false,
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@done-coding/cli-inject": "^0.5.8-alpha.
|
|
43
|
+
"@done-coding/cli-inject": "^0.5.8-alpha.1",
|
|
44
44
|
"@types/node": "^18.0.0",
|
|
45
45
|
"@types/semver": "^7.5.3",
|
|
46
46
|
"@types/uuid": "^10.0.0",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"node": ">=18.0.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@done-coding/cli-utils": "^0.
|
|
57
|
+
"@done-coding/cli-utils": "^0.7.0-alpha.0",
|
|
58
58
|
"semver": "^7.5.4",
|
|
59
59
|
"uuid": "^11.1.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "2ab236d6a17411d64f4429eeacf39e40a10576e4"
|
|
62
62
|
}
|