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