@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 CHANGED
@@ -1,13 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { c as r } from "./index-3eb0cae4.js";
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
- import "yargs";
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 C } from "semver";
3
- import { join as v } from "node:path";
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 h, existsSync as y } from "node:fs";
7
- import p from "chalk";
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 L = "/.dc/publish.json", N = "/package.json", T = ({ gitOriginName: t = "origin" }) => {
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(), 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();
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: i,
31
- userName: s,
32
- userNamePinYin: P(s, {
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(h(v(process.cwd(), N), "utf-8"))) => {
44
- let m = o.name, c = "", i;
45
- const { version: s } = o;
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(s, t), i = d.LATEST;
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 = C(s);
58
- l ? (console.log(
59
- p.yellow("当前版本已经是预发布版本,将会在当前版本基础上进行发布")
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 = s.split("-")[0] + "-0") : c = A(s, t), i = d.NEXT;
57
+ ) : c = i.split("-")[0] + "-0") : c = A(i, t), s = d.NEXT;
64
58
  } else
65
- i = d.ALPHA, c = A(
66
- s,
59
+ s = d.ALPHA, c = A(
60
+ i,
67
61
  e.PRERELEASE,
68
- i
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: i
69
+ tag: s
76
70
  };
77
- }, b = () => {
71
+ }, L = () => {
78
72
  let t;
79
- const o = v(process.cwd(), L);
80
- if (y(o)) {
81
- const m = h(o, "utf-8");
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
- console.log(
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
- }, M = async (t) => {
85
+ }, T = async (t) => {
94
86
  console.log(t);
95
- const { mode: o, type: m, push: c } = t, i = b(), s = T(i);
96
- console.log("gitInfo:", s);
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(h(v(process.cwd(), N), "utf-8")), a = {
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 } = i;
176
- r ? n(`${r} 1>&2`) : console.log(p.yellow("webBuild为空,不执行web构建"));
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
- console.log(p.red(`发布失败, error: ${r.message}`));
171
+ p.error(`发布失败, error: ${r.message}`);
181
172
  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`);
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
- console.log(p.red(`回滚失败, error: ${a.message}`));
177
+ p.error(`回滚失败, error: ${a.message}`);
189
178
  }
190
179
  return process.exit(1);
191
180
  }
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
- }, O = {
194
- version: "0.4.5-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 = {
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
- }, j = () => ({
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 = O.cliConfig.moduleName, x = (t, o) => {
228
- console.log(t ? p.red(t) : p.red(o.message)), process.exit(1);
229
- }, B = O.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(O.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
- };
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
- Z as a,
244
- V as c,
245
- M as h
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 u, a as b, h as l } from "./index-3eb0cae4.js";
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
- u as PublishModeEnum,
15
- b as command,
16
- l as handler
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.4.5-alpha.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.4.6-alpha.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.2.1-alpha.0",
60
- "chalk": "^5.3.0",
58
+ "@done-coding/cli-utils": "^0.3.0-alpha.0",
61
59
  "pinyin": "^2.11.2",
62
- "prompts": "^2.4.2",
63
- "semver": "^7.5.4",
64
- "yargs": "^17.7.2"
60
+ "semver": "^7.5.4"
65
61
  },
66
- "gitHead": "21eb698f64179882cfec979bd8f19920b047dacb"
62
+ "gitHead": "c5a54bdf08759425701a2024442a923883065189"
67
63
  }
@@ -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,5 +1,5 @@
1
1
  declare const _default: {
2
- "version": "0.4.5-alpha.0",
2
+ "version": "0.5.0-alpha.0",
3
3
  "name": "@done-coding/cli-publish",
4
4
  "description": "项目发布命令行工具",
5
5
  "cliConfig": {
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<{}, {}>;