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