@done-coding/cli-utils 0.6.0-alpha.0 → 0.7.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/index.mjs CHANGED
@@ -1,55 +1,55 @@
1
1
  #!/usr/bin/env node
2
- import u from "chalk";
3
- import { default as Ae } from "chalk";
4
- import g from "node:path";
5
- import d, { existsSync as p, mkdirSync as j, writeFileSync as S, readFileSync as $, rmSync as A } from "node:fs";
6
- import y from "crypto";
7
- import I from "prompts";
8
- import N from "yargs";
9
- import { hideBin as M } from "yargs/helpers";
10
- import { execSync as f } from "node:child_process";
11
- import k from "json5";
2
+ import m from "chalk";
3
+ import { default as oe } from "chalk";
4
+ import f from "node:path";
5
+ import u, { existsSync as p, mkdirSync as W, writeFileSync as b, readFileSync as v, rmSync as X } from "node:fs";
6
+ import _ from "crypto";
7
+ import q from "prompts";
8
+ import z from "yargs";
9
+ import { hideBin as Q } from "yargs/helpers";
10
+ import { execSync as g } from "node:child_process";
11
+ import j from "json5";
12
12
  export * from "json5";
13
- import { default as Me } from "json5";
14
- import Y from "lodash.merge";
15
- import m from "pinyin";
16
- import J from "semver";
17
- import { tmpdir as L } from "node:os";
18
- import { default as Je } from "lodash.get";
19
- import { default as Ge } from "lodash.set";
20
- import { default as Be } from "lodash.curry";
21
- const a = Object.assign(
22
- (e, ...o) => console.log(...o.map((t) => u[e](t))),
13
+ import { default as ie } from "json5";
14
+ import Z from "lodash.merge";
15
+ import tt from "semver";
16
+ import { tmpdir as et } from "node:os";
17
+ import { default as ae } from "lodash.get";
18
+ import { default as fe } from "lodash.set";
19
+ import { default as ue } from "lodash.curry";
20
+ import E from "pinyin";
21
+ const l = Object.assign(
22
+ (t, ...e) => console.log(...e.map((r) => m[t](r))),
23
23
  {
24
24
  /** 成功 */
25
- success: (...e) => a("green", ...e),
25
+ success: (...t) => l("green", ...t),
26
26
  /** /步骤 */
27
- stage: (...e) => a("blue", ...e),
27
+ stage: (...t) => l("blue", ...t),
28
28
  /** 提示信息 */
29
- info: (...e) => a("cyan", ...e),
29
+ info: (...t) => l("cyan", ...t),
30
30
  /** 警告 */
31
- warn: (...e) => a("yellow", ...e),
31
+ warn: (...t) => l("yellow", ...t),
32
32
  /** 错误 */
33
- error: (...e) => a("red", ...e),
33
+ error: (...t) => l("red", ...t),
34
34
  /** 跳过 */
35
- skip: (...e) => a("gray", ...e)
35
+ skip: (...t) => l("gray", ...t)
36
36
  }
37
- ), Se = (e, {
37
+ ), Bt = (t, {
38
38
  /** 当前目录 */
39
- currentDir: o = process.cwd(),
39
+ currentDir: e = process.cwd(),
40
40
  /** 优先找最远的父目录 */
41
- isFindFarthest: t = !0
41
+ isFindFarthest: r = !0
42
42
  } = {}) => {
43
- const r = g.resolve(o).split(g.sep).map((n, s, c) => s ? g.join(c.slice(0, s).join(g.sep), n) : n);
44
- for (; r.length; ) {
45
- const n = t ? r.shift() : r.pop(), s = g.join(n, e);
46
- if (d.existsSync(s))
47
- return n;
43
+ const o = f.resolve(e).split(f.sep).map((s, n, c) => n ? f.join(c.slice(0, n).join(f.sep), s) : s);
44
+ for (; o.length; ) {
45
+ const s = r ? o.shift() : o.pop(), n = f.join(s, t);
46
+ if (u.existsSync(n))
47
+ return s;
48
48
  }
49
- }, w = "aes-256-cbc", _ = 16, h = "hex", v = ":";
50
- function P(e) {
51
- return y.pbkdf2Sync(
52
- e,
49
+ }, H = "aes-256-cbc", F = 16, M = "hex", A = ":";
50
+ function N(t) {
51
+ return _.pbkdf2Sync(
52
+ t,
53
53
  "done-coding-cli-salt",
54
54
  // 使用固定的盐值
55
55
  1e4,
@@ -59,84 +59,84 @@ function P(e) {
59
59
  "sha256"
60
60
  );
61
61
  }
62
- function $e({
63
- text: e,
64
- secretKey: o
62
+ function kt({
63
+ text: t,
64
+ secretKey: e
65
65
  }) {
66
66
  try {
67
- const t = P(o), r = y.randomBytes(_), n = y.createCipheriv(w, t, r);
68
- let s = n.update(e);
69
- s = Buffer.concat([s, n.final()]);
70
- const c = r.toString(h), i = s.toString(h);
71
- return `${c}${v}${i}`;
72
- } catch (t) {
73
- return a.error(
74
- `加密失败: ${t instanceof Error ? t.message : String(t)}`
67
+ const r = N(e), o = _.randomBytes(F), s = _.createCipheriv(H, r, o);
68
+ let n = s.update(t);
69
+ n = Buffer.concat([n, s.final()]);
70
+ const c = o.toString(M), i = n.toString(M);
71
+ return `${c}${A}${i}`;
72
+ } catch (r) {
73
+ return l.error(
74
+ `加密失败: ${r instanceof Error ? r.message : String(r)}`
75
75
  ), "";
76
76
  }
77
77
  }
78
- function ve({
79
- encryptedText: e,
80
- secretKey: o
78
+ function xt({
79
+ encryptedText: t,
80
+ secretKey: e
81
81
  }) {
82
82
  try {
83
- if (!e.includes(v))
83
+ if (!t.includes(A))
84
84
  return "";
85
- const t = P(o), [r, n] = e.split(v);
86
- if (r.length !== _ * 2)
85
+ const r = N(e), [o, s] = t.split(A);
86
+ if (o.length !== F * 2)
87
87
  return "";
88
- const s = Buffer.from(r, h), c = Buffer.from(n, h), i = y.createDecipheriv(w, t, s);
89
- let l = i.update(c);
90
- return l = Buffer.concat([l, i.final()]), l.toString();
91
- } catch (t) {
92
- return a.error(
93
- `解密失败: ${t instanceof Error ? t.message : String(t)}`
88
+ const n = Buffer.from(o, M), c = Buffer.from(s, M), i = _.createDecipheriv(H, r, n);
89
+ let a = i.update(c);
90
+ return a = Buffer.concat([a, i.final()]), a.toString();
91
+ } catch (r) {
92
+ return l.error(
93
+ `解密失败: ${r instanceof Error ? r.message : String(r)}`
94
94
  ), "";
95
95
  }
96
96
  }
97
- const D = (...e) => {
98
- const [o, t = {}] = e;
99
- return I(o, {
100
- onCancel(r) {
101
- return a.error(`退出${r == null ? void 0 : r.name}输入`), process.exit(1);
97
+ const G = (...t) => {
98
+ const [e, r = {}] = t;
99
+ return q(e, {
100
+ onCancel(o) {
101
+ return l.error(`退出${o == null ? void 0 : o.name}输入`), process.exit(1);
102
102
  },
103
- ...t
103
+ ...r
104
104
  });
105
- }, G = (e, o) => {
106
- e ? a.error(e) : a.error(o.message), o != null && o.stack && a.error(o.stack), process.exit(1);
107
- }, V = () => {
108
- const e = M(process.argv);
109
- return N(e);
110
- }, x = (e, {
111
- usage: o,
112
- version: t,
113
- demandCommandCount: r,
114
- options: n,
115
- positionals: s,
105
+ }, rt = (t, e) => {
106
+ t ? l.error(t) : l.error(e.message), e != null && e.stack && l.error(e.stack), process.exit(1);
107
+ }, ot = () => {
108
+ const t = Q(process.argv);
109
+ return z(t);
110
+ }, J = (t, {
111
+ usage: e,
112
+ version: r,
113
+ demandCommandCount: o,
114
+ options: s,
115
+ positionals: n,
116
116
  subcommands: c
117
117
  }) => {
118
- let i = e.strict();
119
- o && (i = i.usage(`Usage: ${o}`)), r && (i = i.demandCommand(r));
120
- const l = "help";
121
- return i = i.help(l), t ? i = i.version(t).alias("h", l).alias("v", "version") : i = i.alias("h", l), n && (i = i.options(n)), s && (i = Object.entries(s).reduce((E, [H, T]) => E.positional(H, T), i)), c && (i = i.command(c)), i;
122
- }, Re = async ({ handler: e, ...o }) => {
123
- const t = await x(V(), o).fail(G).argv;
124
- return e ? e(t) : t;
125
- }, Ee = (e) => {
126
- const { command: o, describe: t, handler: r = () => {
127
- }, ...n } = e;
118
+ let i = t.strict();
119
+ e && (i = i.usage(`Usage: ${e}`)), o && (i = i.demandCommand(o));
120
+ const a = "help";
121
+ return i = i.help(a), r ? i = i.version(r).alias("h", a).alias("v", "version") : i = i.alias("h", a), s && (i = i.options(s)), n && (i = Object.entries(n).reduce((y, [R, S]) => y.positional(R, S), i)), c && (i = i.command(c)), i;
122
+ }, jt = async ({ handler: t, ...e }) => {
123
+ const r = await J(ot(), e).fail(rt).argv;
124
+ return t ? t(r) : r;
125
+ }, Ht = (t) => {
126
+ const { command: e, describe: r, handler: o = () => {
127
+ }, ...s } = t;
128
128
  return {
129
- command: o,
130
- describe: t,
131
- builder(s) {
132
- return x(s, n);
129
+ command: e,
130
+ describe: r,
131
+ builder(n) {
132
+ return J(n, s);
133
133
  },
134
- handler: r
134
+ handler: o
135
135
  };
136
136
  };
137
- var B = /* @__PURE__ */ ((e) => (e.VSCODE = "VsCode", e.CURSOR = "Cursor", e.OTHER = "其他", e))(B || {});
138
- const K = async () => {
139
- const { editorType: e } = await D([
137
+ var st = /* @__PURE__ */ ((t) => (t.VSCODE = "VsCode", t.CURSOR = "Cursor", t.OTHER = "其他", t))(st || {});
138
+ const nt = async () => {
139
+ const { editorType: t } = await G([
140
140
  {
141
141
  name: "editorType",
142
142
  type: "select",
@@ -146,302 +146,503 @@ const K = async () => {
146
146
  "VsCode",
147
147
  "其他"
148
148
  /* OTHER */
149
- ].map((o) => ({
150
- title: o,
151
- value: o
149
+ ].map((e) => ({
150
+ title: e,
151
+ value: e
152
152
  }))
153
153
  }
154
154
  ]);
155
- return e;
156
- }, U = {
155
+ return t;
156
+ }, it = {
157
157
  Cursor: "cursor",
158
158
  VsCode: "code"
159
- }, W = (e, o, t) => {
159
+ }, ct = (t, e, r) => {
160
160
  try {
161
- f(`${e} -v`, { stdio: "ignore" }), f(`${e} ${o}`);
161
+ g(`${t} -v`, { stdio: "ignore" }), g(`${t} ${e}`);
162
162
  } catch {
163
- t();
163
+ r();
164
164
  }
165
- }, X = (e, o) => {
166
- const t = (r) => a.info(`
167
- ${r}, 请用编辑器打开 ${e} 进行编辑
165
+ }, at = (t, e) => {
166
+ const r = (o) => l.info(`
167
+ ${o}, 请用编辑器打开 ${t} 进行编辑
168
168
  `);
169
- switch (o) {
169
+ switch (e) {
170
170
  case "Cursor":
171
171
  case "VsCode": {
172
- const r = U[o];
173
- W(r, e, () => {
174
- t(`${r}命令未安装`);
172
+ const o = it[e];
173
+ ct(o, t, () => {
174
+ r(`${o}命令未安装`);
175
175
  });
176
176
  break;
177
177
  }
178
178
  default:
179
- t("其他编辑器");
179
+ r("其他编辑器");
180
180
  }
181
- }, q = (e = process.cwd()) => ({
181
+ }, lt = (t = process.cwd()) => ({
182
182
  /** 必须保留 */
183
183
  rootDir: {
184
184
  type: "string",
185
185
  alias: "R",
186
186
  describe: "运行目录",
187
187
  /** 必须设置默认值 */
188
- default: e
188
+ default: t
189
189
  }
190
- }), Oe = ({
191
- configPathDefault: e,
192
- rootDirDefault: o
190
+ }), Ft = ({
191
+ configPathDefault: t,
192
+ rootDirDefault: e
193
193
  }) => ({
194
194
  /** 必须保留 */
195
- ...q(o),
195
+ ...lt(e),
196
196
  /** 必须保留 */
197
197
  configPath: {
198
198
  type: "string",
199
199
  alias: "C",
200
200
  describe: "配置文件相对路径",
201
201
  /** 必须设置默认值 */
202
- default: e
202
+ default: t
203
203
  }
204
- }), z = async (e, o) => {
205
- const { configPath: t, rootDir: r } = o, n = g.resolve(r, t), s = g.dirname(n);
206
- return p(s) || j(s, {
204
+ }), ft = async (t, e) => {
205
+ const { configPath: r, rootDir: o } = e, s = f.resolve(o, r), n = f.dirname(s);
206
+ return p(n) || W(n, {
207
207
  recursive: !0
208
- }), n.endsWith(".json5") ? (a.info(`json5模式写入 ${n}`), S(n, k.stringify(e, null, 2)), n) : (a.info(`json模式写入 ${n}`), S(n, JSON.stringify(e, null, 2)), n);
209
- }, ke = async (e, o, {
210
- onFileGenerated: t,
211
- edit: r = !1
208
+ }), s.endsWith(".json5") ? (l.info(`json5模式写入 ${s}`), b(s, j.stringify(t, null, 2)), s) : (l.info(`json模式写入 ${s}`), b(s, JSON.stringify(t, null, 2)), s);
209
+ }, Nt = async (t, e, {
210
+ onFileGenerated: r,
211
+ edit: o = !1
212
212
  } = {}) => {
213
- const n = await z(e, o);
214
- if (t == null || t(n), r) {
215
- const s = await K();
216
- X(o.configPath, s);
213
+ const s = await ft(t, e);
214
+ if (r == null || r(s), o) {
215
+ const n = await nt();
216
+ at(e.configPath, n);
217
217
  }
218
- }, we = async (e, o) => {
219
- const { configPath: t, rootDir: r } = e, n = g.resolve(r, t);
220
- if (!p(n)) {
221
- if (o)
222
- return a.info("配置文件不存在,使用onNotExists返回值"), o();
223
- const s = `配置文件不存在 ${n}`;
224
- throw new Error(s);
218
+ }, Gt = async (t, e) => {
219
+ const { configPath: r, rootDir: o } = t, s = f.resolve(o, r);
220
+ if (!p(s)) {
221
+ if (e)
222
+ return l.info("配置文件不存在,使用onNotExists返回值"), e();
223
+ const n = `配置文件不存在 ${s}`;
224
+ throw new Error(n);
225
225
  }
226
- return n.endsWith(".json5") ? (a.info(`json5模式解析 ${n}`), k.parse($(n, "utf8"))) : (a.info(`json模式解析 ${n}`), JSON.parse($(n, "utf8")));
227
- }, _e = async () => {
228
- const { useDefaultConfig: e } = await D({
226
+ return s.endsWith(".json5") ? (l.info(`json5模式解析 ${s}`), j.parse(v(s, "utf8"))) : (l.info(`json模式解析 ${s}`), JSON.parse(v(s, "utf8")));
227
+ }, Jt = async () => {
228
+ const { useDefaultConfig: t } = await G({
229
229
  name: "useDefaultConfig",
230
230
  type: "confirm",
231
231
  message: "使用默认模板配置",
232
232
  initial: !0
233
233
  });
234
- return e;
235
- }, b = "package.json", R = ({
236
- rootDir: e
234
+ return t;
235
+ }, L = "package.json", w = ({
236
+ rootDir: t
237
237
  }) => {
238
- const o = g.resolve(e, b);
239
- if (!p(o))
240
- throw new Error(`${e}未找到package.json文件`);
241
- const t = $(o, "utf-8");
242
- return JSON.parse(t);
243
- }, Q = ({
244
- rootDir: e,
245
- pkgJson: o,
246
- pkgName: t,
247
- isDevPkg: r
238
+ const e = f.resolve(t, L);
239
+ if (!p(e))
240
+ throw new Error(`${t}未找到package.json文件`);
241
+ const r = v(e, "utf-8");
242
+ return JSON.parse(r);
243
+ }, gt = ({
244
+ rootDir: t,
245
+ pkgJson: e,
246
+ pkgName: r,
247
+ isDevPkg: o
248
248
  }) => {
249
- const n = o || R({ rootDir: e }), s = r ? n.devDependencies : n.dependencies;
250
- let c = s == null ? void 0 : s[t];
249
+ const s = e || w({ rootDir: t }), n = o ? s.devDependencies : s.dependencies;
250
+ let c = n == null ? void 0 : n[r];
251
251
  if (!c) {
252
- const i = r ? n.dependencies : n.devDependencies;
253
- c = i == null ? void 0 : i[t], c && console.log(
254
- u.yellow(
255
- `${r ? "开发" : "生产"}依赖包${t}可能错误的安装在${r ? "dependencies" : "devDependencies"}`
252
+ const i = o ? s.dependencies : s.devDependencies;
253
+ c = i == null ? void 0 : i[r], c && console.log(
254
+ m.yellow(
255
+ `${o ? "开发" : "生产"}依赖包${r}可能错误的安装在${o ? "dependencies" : "devDependencies"}`
256
256
  )
257
257
  );
258
258
  return;
259
259
  }
260
- return c || console.log(u.cyan(`依赖包${t}未安装`)), c;
261
- }, Pe = ({
262
- patchConfig: e,
263
- rootDir: o
260
+ return c || console.log(m.cyan(`依赖包${r}未安装`)), c;
261
+ }, Lt = ({
262
+ patchConfig: t,
263
+ rootDir: e
264
264
  }) => {
265
- if (!e)
265
+ if (!t)
266
266
  return;
267
- const t = R({ rootDir: o }), r = Y(t, e), n = g.resolve(o, b);
268
- S(n, JSON.stringify(r, null, 2), "utf-8");
269
- }, De = (e) => {
270
- const t = f("git rev-parse --show-toplevel", {
271
- cwd: e
267
+ const r = w({ rootDir: e }), o = Z(r, t), s = f.resolve(e, L);
268
+ b(s, JSON.stringify(o, null, 2), "utf-8");
269
+ }, O = (t) => {
270
+ const r = g("git rev-parse --show-toplevel", {
271
+ cwd: t
272
272
  }).toString();
273
- if (!t)
273
+ if (!r)
274
274
  throw new Error("获取git根目录失败");
275
- return t.trim();
276
- }, xe = ({
277
- remoteAlias: e
278
- } = {}) => {
275
+ return r.trim();
276
+ }, Ut = () => {
277
+ var t;
279
278
  try {
280
- const o = f("git rev-parse HEAD").toString().trim(), t = f('git log -1 --pretty=format:"%an"').toString().trim(), r = f('git log -1 --pretty=format:"%ae"').toString().trim(), n = f('git log -1 --pretty=format:"%s"').toString().trim(), s = f("git config user.name").toString().trim(), c = f("git config user.email").toString().trim(), i = f("git rev-parse --abbrev-ref HEAD").toString().trim();
281
- let l = "";
279
+ const e = g("git symbolic-ref --short HEAD", {
280
+ stdio: "ignore"
281
+ });
282
+ return (t = e == null ? void 0 : e.toString()) == null ? void 0 : t.trim();
283
+ } catch {
282
284
  try {
283
- l = f(`git config --get remote.${e}.url`).toString().trim();
284
- } catch {
285
- a.warn("git远程仓库地址获取失败或者不存在");
285
+ const r = g("git rev-parse --short HEAD").toString().trim();
286
+ l.skip(`当前未指向具体某个分支, 当前commit hash: ${r}`);
287
+ } finally {
288
+ return;
286
289
  }
290
+ }
291
+ }, ut = (t) => {
292
+ const e = t.match(/moving\s+from\s+(.*)\s+to\s+(.*)/);
293
+ if (e) {
294
+ const [, r, o] = e;
287
295
  return {
288
- lastHash: o,
289
- lastCommitter: t,
290
- lastCommitterPinYin: m(t, {
291
- style: m.STYLE_NORMAL,
292
- heteronym: !1
293
- }).join(""),
294
- lastCommitEmail: r,
295
- lastCommitMsg: n,
296
- userName: s,
297
- userNamePinYin: m(s, {
298
- style: m.STYLE_NORMAL,
299
- heteronym: !1
300
- }).join(""),
301
- userEmail: c,
302
- branchName: i,
303
- remoteInfo: l ? {
304
- alias: e,
305
- url: l
306
- } : void 0
296
+ fromBranch: r.trim(),
297
+ toBranch: o.trim()
307
298
  };
308
- } catch (o) {
309
- throw a.error("获取git最后提交信息失败"), o;
310
299
  }
311
- }, be = ({
312
- branchName: e,
313
- version: o,
314
- remoteInfo: t
315
- }) => {
316
- t && (f(`git push ${t.alias} v${o}`, {
317
- stdio: "inherit"
318
- }), f(`git push ${t.alias} ${e}`, {
319
- stdio: "inherit"
320
- }));
321
- }, C = 73, Z = (e) => {
322
- const t = d.statSync(e).mode;
323
- if ((t & C) === C)
300
+ }, I = 73, mt = (t) => {
301
+ const r = u.statSync(t).mode;
302
+ if ((r & I) === I)
324
303
  return;
325
- console.log(u.blue(`${e} 没有执行权限 添加... `));
326
- const r = t | C;
327
- d.chmodSync(e, r), console.log(u.green(`${e} 添加执行权限成功`));
328
- }, ee = "husky", te = ".husky", oe = ({
329
- projectRootDir: e
330
- }) => {
331
- const o = Q({
304
+ console.log(m.blue(`${t} 没有执行权限 添加... `));
305
+ const o = r | I;
306
+ u.chmodSync(t, o), console.log(m.green(`${t} 添加执行权限成功`));
307
+ };
308
+ var d = /* @__PURE__ */ ((t) => (t.PRE_COMMIT = "pre-commit", t.PRE_MERGE_COMMIT = "pre-merge-commit", t.PREPARE_COMMIT_MSG = "prepare-commit-msg", t.COMMIT_MSG = "commit-msg", t.PRE_REBASE = "pre-rebase", t.POST_COMMIT = "post-commit", t.POST_MERGE = "post-merge", t.PRE_PUSH = "pre-push", t))(d || {});
309
+ const pt = "husky", ht = ".husky", dt = ({ rootDir: t }) => {
310
+ const e = O(t), r = gt({
332
311
  rootDir: e,
333
- pkgJson: R({ rootDir: e }),
334
- pkgName: ee,
312
+ pkgJson: w({ rootDir: e }),
313
+ pkgName: pt,
335
314
  isDevPkg: !0
336
315
  });
337
- if (!o)
316
+ if (!r)
338
317
  throw new Error("husky版本获取失败, 可能husky未安装");
339
- const t = o.replace(/^(\^|~)/, ""), r = "<9.0.0";
340
- return J.satisfies(t, r) ? (console.log(u.cyan(`${t}符合${r}`)), `#!/usr/bin/env sh
341
- . "$(dirname -- "$0")/_/husky.sh"`) : (console.log(u.cyan(`${t}不符合${r}`)), "");
342
- }, re = ({
343
- projectRootDir: e
344
- }) => g.resolve(e, te), Fe = ({
345
- hookNames: e,
346
- projectRootDir: o,
347
- getCode: t
318
+ const o = r.replace(/^(\^|~)/, ""), s = "<9.0.0";
319
+ return tt.satisfies(o, s) ? (console.log(m.cyan(`${o}符合${s}`)), `#!/usr/bin/env sh
320
+ . "$(dirname -- "$0")/_/husky.sh"`) : (console.log(m.cyan(`${o}不符合${s}`)), "");
321
+ }, yt = ({ rootDir: t }) => {
322
+ const e = O(t);
323
+ return f.resolve(e, ht);
324
+ }, Kt = ({
325
+ hookNames: t,
326
+ rootDir: e,
327
+ getCode: r
348
328
  }) => {
349
- const r = re({ projectRootDir: o });
350
- d.existsSync(r) || d.mkdirSync(r, { recursive: !0 }), e.forEach((n) => {
351
- const s = g.resolve(r, n), c = d.existsSync(s);
352
- let i = t(n);
329
+ const o = yt({ rootDir: e });
330
+ u.existsSync(o) || u.mkdirSync(o, { recursive: !0 }), t.forEach((s) => {
331
+ const n = f.resolve(o, s), c = u.existsSync(n);
332
+ let i = r(s);
353
333
  if (c)
354
- d.readFileSync(s, "utf-8").includes(i) ? console.log(
355
- u.gray(`${s} ${n}相关调用 ${i} 已存在 跳过`)
356
- ) : (d.appendFileSync(
357
- s,
334
+ u.readFileSync(n, "utf-8").includes(i) ? console.log(
335
+ m.gray(`${n} ${s}相关调用 ${i} 已存在 跳过`)
336
+ ) : (u.appendFileSync(
337
+ n,
358
338
  `
359
339
  ${i}
360
340
  `
361
- ), console.log(u.green(`${s} 添加 ${n}相关调用成功`)));
341
+ ), console.log(m.green(`${n} 添加 ${s}相关调用成功`)));
362
342
  else {
363
- const l = oe({
364
- projectRootDir: o
343
+ const a = dt({
344
+ rootDir: e
365
345
  });
366
- d.writeFileSync(
367
- s,
368
- `${l}
346
+ u.writeFileSync(
347
+ n,
348
+ `${a}
369
349
 
370
350
  ${i}
371
351
  `,
372
352
  "utf-8"
373
- ), console.log(u.green(`${s} 添加 ${n}相关调用成功`));
353
+ ), console.log(m.green(`${n} 添加 ${s}相关调用成功`));
374
354
  }
375
- Z(s);
355
+ mt(n);
376
356
  });
377
- }, O = "git@gitee.com:justsosu/done-coding-cli-assets-config.git", ne = (e) => `./.DONE_CODING_CLI_CONFIG_TEMPORARY_DIRECTORY_FOR_${e}`, F = (e) => `./assets/${e}`, se = (e) => `${F(e)}/index.json`, He = async ({
378
- moduleName: e,
379
- onSuccess: o
357
+ }, Yt = [
358
+ // HooksNameEnum.PRE_MERGE_COMMIT,
359
+ d.PREPARE_COMMIT_MSG,
360
+ d.COMMIT_MSG
361
+ ], Vt = ({
362
+ hookName: t,
363
+ rootDir: e
364
+ }) => {
365
+ const r = O(e), o = f.resolve(r, ".git");
366
+ switch (t) {
367
+ case d.PREPARE_COMMIT_MSG:
368
+ case d.COMMIT_MSG: {
369
+ const s = f.resolve(o, "MERGE_MSG");
370
+ if (p(s))
371
+ return v(s, "utf-8");
372
+ }
373
+ }
374
+ return "";
375
+ }, Wt = ({
376
+ remoteAlias: t
377
+ } = {}) => {
378
+ try {
379
+ const e = g("git rev-parse HEAD").toString().trim(), r = g('git log -1 --pretty=format:"%an"').toString().trim(), o = g('git log -1 --pretty=format:"%ae"').toString().trim(), s = g('git log -1 --pretty=format:"%s"').toString().trim(), n = g("git config user.name").toString().trim(), c = g("git config user.email").toString().trim(), i = g("git rev-parse --abbrev-ref HEAD").toString().trim();
380
+ let a = "";
381
+ try {
382
+ a = g(`git config --get remote.${t}.url`).toString().trim();
383
+ } catch {
384
+ l.warn("git远程仓库地址获取失败或者不存在");
385
+ }
386
+ return {
387
+ lastHash: e,
388
+ lastCommitter: r,
389
+ lastCommitterPinYin: E(r, {
390
+ style: E.STYLE_NORMAL,
391
+ heteronym: !1
392
+ }).join(""),
393
+ lastCommitEmail: o,
394
+ lastCommitMsg: s,
395
+ userName: n,
396
+ userNamePinYin: E(n, {
397
+ style: E.STYLE_NORMAL,
398
+ heteronym: !1
399
+ }).join(""),
400
+ userEmail: c,
401
+ branchName: i,
402
+ remoteInfo: a ? {
403
+ alias: t,
404
+ url: a
405
+ } : void 0
406
+ };
407
+ } catch (e) {
408
+ throw l.error("获取git最后提交信息失败"), e;
409
+ }
410
+ }, U = (t = "") => {
411
+ const e = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+into\s+['|"](.+)['|"]\s*/i, r = t.match(e);
412
+ if (r) {
413
+ const [, i, a] = r;
414
+ return {
415
+ fromBranch: i,
416
+ toBranch: a
417
+ };
418
+ }
419
+ const o = /\s*Merge\s+branch\s+['|"](.+)['|"]\s+of\s+.+\s+into\s+['|"](.+)['|"]\s*/i, s = t.match(o);
420
+ if (s) {
421
+ const [, i, a] = s;
422
+ return {
423
+ fromBranch: i,
424
+ toBranch: a
425
+ };
426
+ }
427
+ const n = /\s*Merge\s+branch\s+['|"](.+)['|"](\s+of)?\s*/i, c = t.match(n);
428
+ if (c) {
429
+ const [, i] = c;
430
+ return {
431
+ fromBranch: i
432
+ };
433
+ }
434
+ }, Rt = (t) => {
435
+ if (t.startsWith(T.MERGE))
436
+ return {
437
+ fromBranch: t.replace(T.MERGE, "").trim()
438
+ };
439
+ }, Xt = () => {
440
+ const t = process.env.GIT_REFLOG_ACTION || "";
441
+ if (!t)
442
+ return;
443
+ const e = /merge\s+([^\s]+)\s*/i, r = t.match(e);
444
+ if (r) {
445
+ const [, n] = r;
446
+ return {
447
+ fromBranch: n
448
+ };
449
+ }
450
+ const o = /pull\s+([^\s]+)\s+([^\s]+)/, s = t.match(o);
451
+ if (s) {
452
+ const [, , n] = s;
453
+ return {
454
+ fromBranch: n
455
+ };
456
+ }
457
+ };
458
+ var T = /* @__PURE__ */ ((t) => (t.CHECKOUT = "checkout", t.MERGE = "merge", t.COMMIT = "commit", t.COMMIT_MERGE = "commit (merge)", t.PULL = "pull", t.RESET = "reset", t.REBASE_START = "rebase (start)", t.REBASE_FINISH = "rebase (finish)", t.REBASE_ABORT = "rebase (abort)", t.REBASE_CONTINUE = "rebase (continue)", t))(T || {});
459
+ const k = "__GIT_REPLACE_MARK__", $ = {
460
+ stringify(t) {
461
+ return JSON.stringify(t).replace(/"/g, k);
462
+ },
463
+ parse(t) {
464
+ return JSON.parse(t.replace(new RegExp(k, "g"), '"'));
465
+ }
466
+ }, qt = ({
467
+ count: t = 100
468
+ } = {}) => {
469
+ if (t <= 0)
470
+ return [];
471
+ const e = {
472
+ hash: "%H",
473
+ /** 提交信息 */
474
+ message: "%s",
475
+ /** 作者 */
476
+ author: "%an",
477
+ /** 作者邮箱 */
478
+ authorEmail: "%ae",
479
+ /** 创作日期 */
480
+ createDate: "%ai",
481
+ /** 提交者 */
482
+ committer: "%cn",
483
+ /** 提交者邮箱 */
484
+ committerEmail: "%ce",
485
+ /** 提交日期 */
486
+ commitTime: "%ci"
487
+ };
488
+ return g(
489
+ `git --no-pager log --oneline -n ${t} --pretty=format:"${$.stringify(
490
+ e
491
+ )}"`
492
+ ).toString().split(`
493
+ `).map((n) => {
494
+ const c = $.parse(n);
495
+ return {
496
+ ...c,
497
+ mergeInfo: U(c.message)
498
+ };
499
+ });
500
+ }, zt = ({
501
+ count: t = 100,
502
+ filterItem: e = () => !0
503
+ } = {}) => {
504
+ if (t <= 0)
505
+ return [];
506
+ const r = {
507
+ hash: "%H",
508
+ fullMessage: "%gs",
509
+ committer: "%cn",
510
+ committerEmail: "%ce",
511
+ commitTime: "%ci"
512
+ };
513
+ return g(
514
+ `git --no-pager reflog -n ${t} --pretty=format:"${$.stringify(
515
+ r
516
+ )}"`
517
+ ).toString().split(`
518
+ `).map((i) => $.parse(i)).filter(e).map((i) => {
519
+ const { fullMessage: a, ...y } = i, R = ":", [S] = a.split(R, 1), Y = a.slice(`${S}${R}`.length), h = S.trim(), C = Y.trim();
520
+ let P, D, V;
521
+ if (h.startsWith(
522
+ "checkout"
523
+ /* CHECKOUT */
524
+ ))
525
+ D = ut(C);
526
+ else if (h.startsWith(
527
+ "merge"
528
+ /* MERGE */
529
+ ))
530
+ P = Rt(h);
531
+ else if (h.startsWith(
532
+ "commit (merge)"
533
+ /* COMMIT_MERGE */
534
+ )) {
535
+ const B = U(C);
536
+ B || l.warn(
537
+ `${i.hash} 是合并提交 但是未从提交信息(${C})中检测到合并分支信息,推测手动更改了提交内容`
538
+ ), P = B;
539
+ }
540
+ return {
541
+ ...y,
542
+ type: h,
543
+ message: C,
544
+ mergeInfo: P,
545
+ checkoutInfo: D,
546
+ rebaseInfo: V
547
+ };
548
+ });
549
+ }, Qt = (t) => {
550
+ const e = O(t), r = f.resolve(e, ".git"), o = f.resolve(r, "rebase-merge");
551
+ if (u.existsSync(o))
552
+ return !0;
553
+ const s = f.resolve(r, "rebase-apply");
554
+ if (u.existsSync(s))
555
+ return !0;
556
+ const n = f.resolve(r, "REBASE_HEAD");
557
+ return !!u.existsSync(n);
558
+ }, Zt = ({
559
+ branchName: t,
560
+ version: e,
561
+ remoteInfo: r
562
+ }) => {
563
+ r && (g(`git push ${r.alias} v${e}`, {
564
+ stdio: "inherit"
565
+ }), g(`git push ${r.alias} ${t}`, {
566
+ stdio: "inherit"
567
+ }));
568
+ }, x = "git@gitee.com:justsosu/done-coding-cli-assets-config.git", St = (t) => `./.DONE_CODING_CLI/CONFIG_TEMP_DIR_FOR_${t}`, K = (t) => `./assets/${t}`, Ct = (t) => `${K(t)}/index.json`, te = async ({
569
+ moduleName: t,
570
+ onSuccess: e
380
571
  }) => {
381
- console.log(u.blue(`拉取${e}配置,请稍等...`));
382
- const t = ne(e), r = g.resolve(
383
- L(),
384
- t
572
+ console.log(m.blue(`拉取${t}配置,请稍等...`));
573
+ const r = St(t), o = f.resolve(
574
+ et(),
575
+ r
385
576
  );
386
- if (p(r))
577
+ if (p(o))
387
578
  return console.log(
388
- u.red(`${r} 已存在,请手动删除该目录再试`)
579
+ m.red(`${o} 已存在,请手动删除该目录再试`)
389
580
  ), process.exit(1);
390
- const n = () => {
391
- A(r, { recursive: !0, force: !0 });
581
+ const s = () => {
582
+ X(o, { recursive: !0, force: !0 });
392
583
  };
393
- let s;
584
+ let n;
394
585
  try {
395
- f(`git clone ${O} ${r} --depth=1`);
396
- const c = se(e), i = F(e), l = g.resolve(
397
- r,
586
+ g(`git clone ${x} ${o} --depth=1`);
587
+ const c = Ct(t), i = K(t), a = f.resolve(
588
+ o,
398
589
  c
399
590
  );
400
- s = JSON.parse(d.readFileSync(l, "utf-8")), process.once("exit", () => {
401
- p(r) && (console.log("发现进程退出,正在清理临时目录..."), n());
402
- }), await o({
403
- repoUrl: O,
404
- config: s,
591
+ n = JSON.parse(u.readFileSync(a, "utf-8")), process.once("exit", () => {
592
+ p(o) && (console.log("发现进程退出,正在清理临时目录..."), s());
593
+ }), await e({
594
+ repoUrl: x,
595
+ config: n,
405
596
  cliConfigFileRelativePath: c,
406
597
  cliConfigDirRelativePath: i,
407
- configTemporaryDir: r
598
+ configTemporaryDir: o
408
599
  });
409
600
  } finally {
410
- n();
601
+ s();
411
602
  }
412
- return s;
603
+ return n;
413
604
  };
414
605
  export {
415
- B as EditorTypeEnum,
416
- Be as _curry,
417
- Je as _get,
418
- Ge as _set,
419
- Fe as addHuskyHooks,
420
- Pe as addPackageConfig,
421
- Ae as chalk,
422
- Re as createMainCommand,
423
- Ee as createSubcommand,
424
- ve as decryptAES,
425
- $e as encryptAES,
426
- Z as fileAddX,
427
- Oe as getConfigFileCommonOptions,
428
- K as getEditorType,
429
- xe as getGitLastCommitInfo,
430
- De as getGitProjectDir,
431
- oe as getHuskyBootCode,
432
- re as getHuskyRootDir,
433
- R as getPackageJson,
434
- Q as getRelyPkgVersion,
435
- q as getRootDirOptions,
436
- _e as getUseDefaultConfig,
437
- z as initConfigFile,
438
- ke as initHandlerCommon,
439
- Me as json5,
440
- a as log,
441
- Se as lookForParentTarget,
442
- X as openFileInEditor,
443
- be as pushGitPublishInfoToRemote,
444
- He as readCliConfig,
445
- we as readConfigFile,
446
- D as xPrompts
606
+ st as EditorTypeEnum,
607
+ T as GitRefLogTypeEnum,
608
+ d as HooksNameEnum,
609
+ Yt as SUPPORT_GET_COMMIT_BY_HOOKS_NAMES,
610
+ ue as _curry,
611
+ ae as _get,
612
+ fe as _set,
613
+ Kt as addHuskyHooks,
614
+ Lt as addPackageConfig,
615
+ oe as chalk,
616
+ Qt as checkCurrentIsRebasing,
617
+ jt as createMainCommand,
618
+ Ht as createSubcommand,
619
+ xt as decryptAES,
620
+ kt as encryptAES,
621
+ mt as fileAddX,
622
+ Vt as getCommitByHookName,
623
+ Ft as getConfigFileCommonOptions,
624
+ qt as getCurrentBranchLastCommitList,
625
+ Ut as getCurrentBranchName,
626
+ nt as getEditorType,
627
+ Wt as getGitLastCommitInfo,
628
+ O as getGitProjectDir,
629
+ zt as getLastReflogList,
630
+ w as getPackageJson,
631
+ gt as getRelyPkgVersion,
632
+ lt as getRootDirOptions,
633
+ Jt as getUseDefaultConfig,
634
+ ft as initConfigFile,
635
+ Nt as initHandlerCommon,
636
+ ie as json5,
637
+ l as log,
638
+ Bt as lookForParentTarget,
639
+ at as openFileInEditor,
640
+ Zt as pushGitPublishInfoToRemote,
641
+ te as readCliConfig,
642
+ Gt as readConfigFile,
643
+ ut as resolveCheckoutInfoByRefInfo,
644
+ U as resolveMergeInfoByCommitMsg,
645
+ Xt as resolveMergeInfoByGitReflogAction,
646
+ Rt as resolveMergeInfoByRefType,
647
+ G as xPrompts
447
648
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-utils",
3
- "version": "0.6.0-alpha.0",
3
+ "version": "0.7.0-alpha.0",
4
4
  "description": "cli utils",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -67,5 +67,5 @@
67
67
  "semver": "^7.5.4",
68
68
  "yargs": "^17.7.2"
69
69
  },
70
- "gitHead": "5879161383e32e7bed351d71d3ef607d81dc021a"
70
+ "gitHead": "ff1616738586a268b50f46dce762774fa5fa6d52"
71
71
  }
@@ -0,0 +1,2 @@
1
+ /** 获取git项目目录 */
2
+ export declare const getGitProjectDir: (rootDir: string) => string;
@@ -0,0 +1,2 @@
1
+ /** 获取当前分支名 */
2
+ export declare const getCurrentBranchName: () => string | undefined;
@@ -0,0 +1,5 @@
1
+ /** 解析checkoutInfo */
2
+ export declare const resolveCheckoutInfoByRefInfo: (message: string) => {
3
+ fromBranch: string;
4
+ toBranch: string;
5
+ } | undefined;
@@ -1,21 +1,13 @@
1
- /** 获取git最好提交信息参数 */
2
- export interface GetGitLastCommitParams {
3
- /**
4
- * 远程仓库别名
5
- */
6
- remoteAlias?: string;
7
- }
8
- /** 远程仓库信息 */
9
- export interface GitRemoteInfo {
10
- /**
11
- * 远程仓库别名
12
- */
13
- alias?: GetGitLastCommitParams["remoteAlias"];
14
- /**
15
- * 仓库地址
16
- */
17
- url?: string;
18
- }
1
+ import { HooksNameEnum } from '../husky';
2
+ import type { GitRemoteInfo } from "./remote-operate";
3
+ /** 支持通过提交钩子获取提交信息的 */
4
+ export declare const SUPPORT_GET_COMMIT_BY_HOOKS_NAMES: readonly [HooksNameEnum.PREPARE_COMMIT_MSG, HooksNameEnum.COMMIT_MSG];
5
+ export type SupportGetCommitByHookName = (typeof SUPPORT_GET_COMMIT_BY_HOOKS_NAMES)[number];
6
+ /** 根据hookName获取(将)提交的信息 */
7
+ export declare const getCommitByHookName: ({ hookName, rootDir, }: {
8
+ hookName: SupportGetCommitByHookName;
9
+ rootDir: string;
10
+ }) => string;
19
11
  /**
20
12
  * git最后提交信息
21
13
  */
@@ -59,15 +51,14 @@ export interface GitLastCommitInfo {
59
51
  /** 远程仓库信息 */
60
52
  remoteInfo?: GitRemoteInfo;
61
53
  }
62
- /** 获取git项目目录 */
63
- export declare const getGitProjectDir: (rootDir: string) => string;
54
+ /** 获取git最好提交信息参数 */
55
+ export interface GetGitLastCommitParams {
56
+ /**
57
+ * 远程仓库别名
58
+ */
59
+ remoteAlias?: GitRemoteInfo["alias"];
60
+ }
64
61
  /**
65
62
  * 获取git 最后提交信息
66
63
  */
67
64
  export declare const getGitLastCommitInfo: ({ remoteAlias, }?: GetGitLastCommitParams) => GitLastCommitInfo;
68
- /** 推送git发布信息到远程仓库 */
69
- export declare const pushGitPublishInfoToRemote: ({ branchName, version, remoteInfo, }: {
70
- branchName: string;
71
- version: string;
72
- remoteInfo?: GitRemoteInfo | undefined;
73
- }) => void;
@@ -0,0 +1,8 @@
1
+ export * from "./base-info-resolve";
2
+ export * from "./branch-resolve";
3
+ export * from "./checkout-resolve";
4
+ export * from "./commit-resolve";
5
+ export * from "./log-resolve";
6
+ export * from "./merge-resolve";
7
+ export * from "./rebase-resolve";
8
+ export * from "./remote-operate";
@@ -0,0 +1,91 @@
1
+ import { type GitMergeBranchInfo } from "./merge-resolve";
2
+ /** git checkout信息 */
3
+ export interface GitCheckoutInfo {
4
+ fromBranch: string;
5
+ toBranch: string;
6
+ }
7
+ /** git日志通用信息 */
8
+ export interface GitLogCommonInfo {
9
+ hash: string;
10
+ /** 提交信息 */
11
+ message: string;
12
+ /** 合并信息 */
13
+ mergeInfo?: GitMergeBranchInfo;
14
+ }
15
+ export interface GitLogItemInfo extends GitLogCommonInfo {
16
+ /** 作者 */
17
+ author: string;
18
+ /** 作者邮箱 */
19
+ authorEmail: string;
20
+ /** 创作日期 */
21
+ createDate: string;
22
+ /** 提交者 */
23
+ committer: string;
24
+ /** 提交者邮箱 */
25
+ committerEmail: string;
26
+ /** 提交时间 */
27
+ commitTime: string;
28
+ }
29
+ /** 提交日志信息 */
30
+ export interface GitReflogItemInfoRaw extends Omit<GitLogCommonInfo, "message"> {
31
+ hash: string;
32
+ /** 完整信息 */
33
+ fullMessage: string;
34
+ /** 提交者 */
35
+ committer: string;
36
+ /** 提交者邮箱 */
37
+ committerEmail: string;
38
+ /** 提交时间 */
39
+ commitTime: string;
40
+ }
41
+ /** reflog类型 */
42
+ export declare enum GitRefLogTypeEnum {
43
+ /** checkout */
44
+ CHECKOUT = "checkout",
45
+ /** merge $branch */
46
+ MERGE = "merge",
47
+ /** 提交 */
48
+ COMMIT = "commit",
49
+ /** 合并提交 */
50
+ COMMIT_MERGE = "commit (merge)",
51
+ /** pull $origin $branch */
52
+ PULL = "pull",
53
+ /** reset */
54
+ RESET = "reset",
55
+ /** rebase (start) */
56
+ REBASE_START = "rebase (start)",
57
+ /** rebase (finish) */
58
+ REBASE_FINISH = "rebase (finish)",
59
+ /** rebase (abort) */
60
+ REBASE_ABORT = "rebase (abort)",
61
+ /** rebase (continue) */
62
+ REBASE_CONTINUE = "rebase (continue)"
63
+ }
64
+ /** rebase的阶段 */
65
+ export type GitRefLogRebaseStage = GitRefLogTypeEnum.REBASE_START | GitRefLogTypeEnum.REBASE_FINISH | GitRefLogTypeEnum.REBASE_ABORT | GitRefLogTypeEnum.REBASE_CONTINUE;
66
+ export interface GitRebaseInfo {
67
+ /** rebase的阶段 */
68
+ stage?: GitRefLogRebaseStage;
69
+ /** 变基的原始分支 */
70
+ originBranch: string;
71
+ /** 变基的目标分支 */
72
+ targetBranch: string;
73
+ }
74
+ /** reflog信息 */
75
+ export interface GitReflogItemInfo extends Omit<GitReflogItemInfoRaw, "fullMessage">, Pick<GitLogCommonInfo, "message"> {
76
+ type: GitRefLogTypeEnum;
77
+ }
78
+ /** 获取当前分支最近提交列表 */
79
+ export declare const getCurrentBranchLastCommitList: ({ count, }?: {
80
+ count?: number | undefined;
81
+ /** 某个hash之后的提交 */
82
+ afterHash?: string | undefined;
83
+ }) => GitLogItemInfo[];
84
+ /** 获取最后的reflog */
85
+ export declare const getLastReflogList: ({ count, filterItem, }?: {
86
+ count?: number | undefined;
87
+ /** 某个hash之后的提交 */
88
+ afterHash?: string | undefined;
89
+ /** 过滤函数 */
90
+ filterItem?: ((item: GitReflogItemInfoRaw) => boolean) | undefined;
91
+ }) => GitReflogItemInfo[];
@@ -0,0 +1,13 @@
1
+ /** git合并分支信息 */
2
+ export interface GitMergeBranchInfo {
3
+ /** 合并的源分支 */
4
+ fromBranch: string;
5
+ /** 合并到该分支 */
6
+ toBranch?: string;
7
+ }
8
+ /** 解析合并信息-通过提交信息 */
9
+ export declare const resolveMergeInfoByCommitMsg: (commitMsg?: string) => GitMergeBranchInfo | undefined;
10
+ /** 从reflog type解析合并信息 */
11
+ export declare const resolveMergeInfoByRefType: (type: string) => GitMergeBranchInfo | undefined;
12
+ /** 从reflog action解析合并信息 */
13
+ export declare const resolveMergeInfoByGitReflogAction: () => GitMergeBranchInfo | undefined;
@@ -0,0 +1,2 @@
1
+ /** 检测当前正在变基 */
2
+ export declare const checkCurrentIsRebasing: (rootDir: string) => boolean;
@@ -0,0 +1,17 @@
1
+ /** 远程仓库信息 */
2
+ export interface GitRemoteInfo {
3
+ /**
4
+ * 远程仓库别名
5
+ */
6
+ alias?: string;
7
+ /**
8
+ * 仓库地址
9
+ */
10
+ url?: string;
11
+ }
12
+ /** 推送git发布信息到远程仓库 */
13
+ export declare const pushGitPublishInfoToRemote: ({ branchName, version, remoteInfo, }: {
14
+ branchName: string;
15
+ version: string;
16
+ remoteInfo?: GitRemoteInfo | undefined;
17
+ }) => void;
package/types/husky.d.ts CHANGED
@@ -1,16 +1,26 @@
1
- /** 获取husky引导代码 */
2
- export declare const getHuskyBootCode: ({ projectRootDir, }: {
3
- projectRootDir: string;
4
- }) => "" | "#!/usr/bin/env sh\n. \"$(dirname -- \"$0\")/_/husky.sh\"";
5
- /** 获取husky根目录 */
6
- export declare const getHuskyRootDir: ({ projectRootDir, }: {
7
- projectRootDir: string;
8
- }) => string;
1
+ export declare enum HooksNameEnum {
2
+ /** 预提交 */
3
+ PRE_COMMIT = "pre-commit",
4
+ /** 预合并提交 */
5
+ PRE_MERGE_COMMIT = "pre-merge-commit",
6
+ /** 准备提交信息 */
7
+ PREPARE_COMMIT_MSG = "prepare-commit-msg",
8
+ /** 提交消息 */
9
+ COMMIT_MSG = "commit-msg",
10
+ /** 变基前 */
11
+ PRE_REBASE = "pre-rebase",
12
+ /** 提交后 */
13
+ POST_COMMIT = "post-commit",
14
+ /** 合并后 */
15
+ POST_MERGE = "post-merge",
16
+ /** 推送前 */
17
+ PRE_PUSH = "pre-push"
18
+ }
9
19
  /** 添加 husky hooks */
10
- export declare const addHuskyHooks: <H extends string>({ hookNames, projectRootDir, getCode, }: {
20
+ export declare const addHuskyHooks: <H extends string>({ hookNames, rootDir, getCode, }: {
11
21
  hookNames: H[];
12
- /** 项目根目录 */
13
- projectRootDir: string;
22
+ /** 运行目录 */
23
+ rootDir: string;
14
24
  /** 获取husky hooks 添加的代码 */
15
25
  getCode: (hook: string) => string;
16
26
  }) => void;