@done-coding/cli-publish 0.4.6-alpha.0 → 0.5.1-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,11 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { c as r } from "./index-f4b0258f.js";
2
+ import { c as m } from "./index-4d304e01.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
- r();
9
+ m();
@@ -1,24 +1,22 @@
1
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";
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 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" }) => {
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 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();
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 = i(`git config --get remote.${t}.url`).toString().trim();
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: r,
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: n,
30
- userNamePinYin: P(n, {
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 (r) {
39
- throw console.error("Error fetching git information:", r), r;
36
+ } catch (o) {
37
+ throw console.error("Error fetching git information:", o), o;
40
38
  }
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;
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(n, t), s = v.LATEST;
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 = C(n);
53
+ const l = $(i);
56
54
  l ? (p.warn("当前版本已经是预发布版本,将会在当前版本基础上进行发布"), l.length === 1 && typeof l[0] == "number" ? c = A(
57
- n,
55
+ i,
58
56
  e.PRERELEASE
59
- ) : c = n.split("-")[0] + "-0") : c = A(n, t), s = v.NEXT;
57
+ ) : c = i.split("-")[0] + "-0") : c = A(i, t), s = d.NEXT;
60
58
  } else
61
- s = v.ALPHA, c = A(
62
- n,
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
- }, T = () => {
71
+ }, L = () => {
74
72
  let t;
75
- const r = d(process.cwd(), J);
76
- if (I(r)) {
77
- const m = O(r, "utf-8");
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
- }, M = async (t) => {
85
+ }, T = async (t) => {
88
86
  console.log(t);
89
- const { mode: r, type: m, push: c } = t, s = T(), n = L(s);
90
- console.log("gitInfo:", n);
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 o = JSON.parse(O(d(process.cwd(), N), "utf-8")), a = {
93
+ const r = JSON.parse(v(O(process.cwd(), N), "utf-8")), a = {
96
94
  [e.MAJOR]: R(
97
95
  e.MAJOR,
98
- o
96
+ r
99
97
  ),
100
98
  [e.MINOR]: R(
101
99
  e.MINOR,
102
- o
100
+ r
103
101
  ),
104
102
  [e.PATCH]: R(
105
103
  e.PATCH,
106
- o
104
+ r
107
105
  ),
108
106
  [e.PREMAJOR]: R(
109
107
  e.PREMAJOR,
110
- o
108
+ r
111
109
  ),
112
110
  [e.PREMINOR]: R(
113
111
  e.PREMINOR,
114
- o
112
+ r
115
113
  ),
116
114
  [e.PREPATCH]: R(
117
115
  e.PREPATCH,
118
- o
116
+ r
119
117
  ),
120
118
  [e.PRERELEASE]: R(
121
119
  e.PRERELEASE,
122
- o
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 H({
152
+ l = (await I({
155
153
  type: "select",
156
154
  name: "type",
157
- message: `请选择发布类型,当前版本:${o.version}`,
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), i(`npm version ${f} 1>&2`);
160
+ console.log("npmInfo:", g), n(`npm version ${f} 1>&2`);
163
161
  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构建");
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 (o) {
173
- p.error(`发布失败, error: ${o.message}`);
170
+ } catch (r) {
171
+ p.error(`发布失败, error: ${r.message}`);
174
172
  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`);
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 && (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",
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 = {
186
183
  name: "@done-coding/cli-publish",
184
+ version: "0.5.1-alpha.0",
187
185
  description: "项目发布命令行工具",
188
186
  cliConfig: {
189
187
  namespaceDir: ".done-coding",
190
188
  moduleName: "publish"
191
189
  }
192
- }, b = () => ({
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 = 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,
220
+ }), u = {
225
221
  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
- };
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
- z as a,
235
- K as c,
236
- M as h
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 d, a as h, h as u } from "./index-f4b0258f.js";
2
+ import { P as n, a as s, h as d } from "./index-4d304e01.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
- d as PublishModeEnum,
13
- h as command,
14
- u as handler
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.4.6-alpha.0",
3
+ "version": "0.5.1-alpha.0",
4
4
  "description": "项目发布命令行工具",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -17,8 +17,7 @@
17
17
  "files": [
18
18
  "es",
19
19
  "lib",
20
- "types",
21
- "gif"
20
+ "types"
22
21
  ],
23
22
  "scripts": {
24
23
  "clean": "rimraf es lib types",
@@ -41,7 +40,7 @@
41
40
  "license": "MIT",
42
41
  "sideEffects": false,
43
42
  "devDependencies": {
44
- "@done-coding/cli-inject": "^0.4.7-alpha.0",
43
+ "@done-coding/cli-inject": "^0.5.1-alpha.0",
45
44
  "@types/node": "^18.0.0",
46
45
  "@types/pinyin": "^2.10.0",
47
46
  "@types/semver": "^7.5.3",
@@ -55,10 +54,9 @@
55
54
  "node": ">=18.0.0"
56
55
  },
57
56
  "dependencies": {
58
- "@done-coding/cli-utils": "^0.2.2-alpha.0",
57
+ "@done-coding/cli-utils": "^0.3.1-alpha.0",
59
58
  "pinyin": "^2.11.2",
60
- "semver": "^7.5.4",
61
- "yargs": "^17.7.2"
59
+ "semver": "^7.5.4"
62
60
  },
63
- "gitHead": "2e59e86ee192e023138e7475f4abbb5e7c42b29e"
61
+ "gitHead": "ec6957606bbae68d7268159b38b9d36dab4a2731"
64
62
  }
@@ -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: ArgumentsCamelCase<Options> | Options) => Promise<undefined>;
4
+ export declare const handler: (argv: CliHandlerArgv<Options>) => Promise<undefined>;
package/types/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { handler } from "./handler";
2
- export { command } from "./main";
2
+ export { crateAsSubcommand } from "./main";
3
3
  export * from './utils/types';
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
- "version": "0.4.6-alpha.0",
3
2
  "name": "@done-coding/cli-publish",
3
+ "version": "0.5.1-alpha.0",
4
4
  "description": "项目发布命令行工具",
5
5
  "cliConfig": {
6
6
  "namespaceDir": ".done-coding",
package/types/main.d.ts CHANGED
@@ -1,4 +1,9 @@
1
- import type { CommandModule } from "yargs";
2
- import { type Options } from './utils';
3
- export declare const command: CommandModule<Options, Options>;
4
- export declare const createCli: () => Promise<undefined>;
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<{}, {}>;