@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 +504 -303
- package/package.json +2 -2
- package/types/git/base-info-resolve.d.ts +2 -0
- package/types/git/branch-resolve.d.ts +2 -0
- package/types/git/checkout-resolve.d.ts +5 -0
- package/types/{git.d.ts → git/commit-resolve.d.ts} +17 -26
- package/types/git/index.d.ts +8 -0
- package/types/git/log-resolve.d.ts +91 -0
- package/types/git/merge-resolve.d.ts +13 -0
- package/types/git/rebase-resolve.d.ts +2 -0
- package/types/git/remote-operate.d.ts +17 -0
- package/types/husky.d.ts +21 -11
package/es/index.mjs
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import { default as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { hideBin as
|
|
10
|
-
import { execSync as
|
|
11
|
-
import
|
|
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
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
import { default as
|
|
19
|
-
import { default as
|
|
20
|
-
import
|
|
21
|
-
const
|
|
22
|
-
(
|
|
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: (...
|
|
25
|
+
success: (...t) => l("green", ...t),
|
|
26
26
|
/** /步骤 */
|
|
27
|
-
stage: (...
|
|
27
|
+
stage: (...t) => l("blue", ...t),
|
|
28
28
|
/** 提示信息 */
|
|
29
|
-
info: (...
|
|
29
|
+
info: (...t) => l("cyan", ...t),
|
|
30
30
|
/** 警告 */
|
|
31
|
-
warn: (...
|
|
31
|
+
warn: (...t) => l("yellow", ...t),
|
|
32
32
|
/** 错误 */
|
|
33
|
-
error: (...
|
|
33
|
+
error: (...t) => l("red", ...t),
|
|
34
34
|
/** 跳过 */
|
|
35
|
-
skip: (...
|
|
35
|
+
skip: (...t) => l("gray", ...t)
|
|
36
36
|
}
|
|
37
|
-
),
|
|
37
|
+
), Bt = (t, {
|
|
38
38
|
/** 当前目录 */
|
|
39
|
-
currentDir:
|
|
39
|
+
currentDir: e = process.cwd(),
|
|
40
40
|
/** 优先找最远的父目录 */
|
|
41
|
-
isFindFarthest:
|
|
41
|
+
isFindFarthest: r = !0
|
|
42
42
|
} = {}) => {
|
|
43
|
-
const
|
|
44
|
-
for (;
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
return
|
|
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
|
-
},
|
|
50
|
-
function
|
|
51
|
-
return
|
|
52
|
-
|
|
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
|
|
63
|
-
text:
|
|
64
|
-
secretKey:
|
|
62
|
+
function kt({
|
|
63
|
+
text: t,
|
|
64
|
+
secretKey: e
|
|
65
65
|
}) {
|
|
66
66
|
try {
|
|
67
|
-
const
|
|
68
|
-
let
|
|
69
|
-
|
|
70
|
-
const c =
|
|
71
|
-
return `${c}${
|
|
72
|
-
} catch (
|
|
73
|
-
return
|
|
74
|
-
`加密失败: ${
|
|
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
|
|
79
|
-
encryptedText:
|
|
80
|
-
secretKey:
|
|
78
|
+
function xt({
|
|
79
|
+
encryptedText: t,
|
|
80
|
+
secretKey: e
|
|
81
81
|
}) {
|
|
82
82
|
try {
|
|
83
|
-
if (!
|
|
83
|
+
if (!t.includes(A))
|
|
84
84
|
return "";
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
85
|
+
const r = N(e), [o, s] = t.split(A);
|
|
86
|
+
if (o.length !== F * 2)
|
|
87
87
|
return "";
|
|
88
|
-
const
|
|
89
|
-
let
|
|
90
|
-
return
|
|
91
|
-
} catch (
|
|
92
|
-
return
|
|
93
|
-
`解密失败: ${
|
|
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
|
|
98
|
-
const [
|
|
99
|
-
return
|
|
100
|
-
onCancel(
|
|
101
|
-
return
|
|
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
|
-
...
|
|
103
|
+
...r
|
|
104
104
|
});
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
},
|
|
108
|
-
const
|
|
109
|
-
return
|
|
110
|
-
},
|
|
111
|
-
usage:
|
|
112
|
-
version:
|
|
113
|
-
demandCommandCount:
|
|
114
|
-
options:
|
|
115
|
-
positionals:
|
|
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 =
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
return i = i.help(
|
|
122
|
-
},
|
|
123
|
-
const
|
|
124
|
-
return
|
|
125
|
-
},
|
|
126
|
-
const { command:
|
|
127
|
-
}, ...
|
|
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:
|
|
130
|
-
describe:
|
|
131
|
-
builder(
|
|
132
|
-
return
|
|
129
|
+
command: e,
|
|
130
|
+
describe: r,
|
|
131
|
+
builder(n) {
|
|
132
|
+
return J(n, s);
|
|
133
133
|
},
|
|
134
|
-
handler:
|
|
134
|
+
handler: o
|
|
135
135
|
};
|
|
136
136
|
};
|
|
137
|
-
var
|
|
138
|
-
const
|
|
139
|
-
const { editorType:
|
|
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((
|
|
150
|
-
title:
|
|
151
|
-
value:
|
|
149
|
+
].map((e) => ({
|
|
150
|
+
title: e,
|
|
151
|
+
value: e
|
|
152
152
|
}))
|
|
153
153
|
}
|
|
154
154
|
]);
|
|
155
|
-
return
|
|
156
|
-
},
|
|
155
|
+
return t;
|
|
156
|
+
}, it = {
|
|
157
157
|
Cursor: "cursor",
|
|
158
158
|
VsCode: "code"
|
|
159
|
-
},
|
|
159
|
+
}, ct = (t, e, r) => {
|
|
160
160
|
try {
|
|
161
|
-
|
|
161
|
+
g(`${t} -v`, { stdio: "ignore" }), g(`${t} ${e}`);
|
|
162
162
|
} catch {
|
|
163
|
-
|
|
163
|
+
r();
|
|
164
164
|
}
|
|
165
|
-
},
|
|
166
|
-
const
|
|
167
|
-
${
|
|
165
|
+
}, at = (t, e) => {
|
|
166
|
+
const r = (o) => l.info(`
|
|
167
|
+
${o}, 请用编辑器打开 ${t} 进行编辑
|
|
168
168
|
`);
|
|
169
|
-
switch (
|
|
169
|
+
switch (e) {
|
|
170
170
|
case "Cursor":
|
|
171
171
|
case "VsCode": {
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
const o = it[e];
|
|
173
|
+
ct(o, t, () => {
|
|
174
|
+
r(`${o}命令未安装`);
|
|
175
175
|
});
|
|
176
176
|
break;
|
|
177
177
|
}
|
|
178
178
|
default:
|
|
179
|
-
|
|
179
|
+
r("其他编辑器");
|
|
180
180
|
}
|
|
181
|
-
},
|
|
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:
|
|
188
|
+
default: t
|
|
189
189
|
}
|
|
190
|
-
}),
|
|
191
|
-
configPathDefault:
|
|
192
|
-
rootDirDefault:
|
|
190
|
+
}), Ft = ({
|
|
191
|
+
configPathDefault: t,
|
|
192
|
+
rootDirDefault: e
|
|
193
193
|
}) => ({
|
|
194
194
|
/** 必须保留 */
|
|
195
|
-
...
|
|
195
|
+
...lt(e),
|
|
196
196
|
/** 必须保留 */
|
|
197
197
|
configPath: {
|
|
198
198
|
type: "string",
|
|
199
199
|
alias: "C",
|
|
200
200
|
describe: "配置文件相对路径",
|
|
201
201
|
/** 必须设置默认值 */
|
|
202
|
-
default:
|
|
202
|
+
default: t
|
|
203
203
|
}
|
|
204
|
-
}),
|
|
205
|
-
const { configPath:
|
|
206
|
-
return p(
|
|
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
|
-
}),
|
|
209
|
-
},
|
|
210
|
-
onFileGenerated:
|
|
211
|
-
edit:
|
|
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
|
|
214
|
-
if (
|
|
215
|
-
const
|
|
216
|
-
|
|
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
|
-
},
|
|
219
|
-
const { configPath:
|
|
220
|
-
if (!p(
|
|
221
|
-
if (
|
|
222
|
-
return
|
|
223
|
-
const
|
|
224
|
-
throw new Error(
|
|
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
|
|
227
|
-
},
|
|
228
|
-
const { useDefaultConfig:
|
|
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
|
|
235
|
-
},
|
|
236
|
-
rootDir:
|
|
234
|
+
return t;
|
|
235
|
+
}, L = "package.json", w = ({
|
|
236
|
+
rootDir: t
|
|
237
237
|
}) => {
|
|
238
|
-
const
|
|
239
|
-
if (!p(
|
|
240
|
-
throw new Error(`${
|
|
241
|
-
const
|
|
242
|
-
return JSON.parse(
|
|
243
|
-
},
|
|
244
|
-
rootDir:
|
|
245
|
-
pkgJson:
|
|
246
|
-
pkgName:
|
|
247
|
-
isDevPkg:
|
|
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
|
|
250
|
-
let c =
|
|
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 =
|
|
253
|
-
c = i == null ? void 0 : i[
|
|
254
|
-
|
|
255
|
-
`${
|
|
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(
|
|
261
|
-
},
|
|
262
|
-
patchConfig:
|
|
263
|
-
rootDir:
|
|
260
|
+
return c || console.log(m.cyan(`依赖包${r}未安装`)), c;
|
|
261
|
+
}, Lt = ({
|
|
262
|
+
patchConfig: t,
|
|
263
|
+
rootDir: e
|
|
264
264
|
}) => {
|
|
265
|
-
if (!
|
|
265
|
+
if (!t)
|
|
266
266
|
return;
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
},
|
|
270
|
-
const
|
|
271
|
-
cwd:
|
|
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 (!
|
|
273
|
+
if (!r)
|
|
274
274
|
throw new Error("获取git根目录失败");
|
|
275
|
-
return
|
|
276
|
-
},
|
|
277
|
-
|
|
278
|
-
} = {}) => {
|
|
275
|
+
return r.trim();
|
|
276
|
+
}, Ut = () => {
|
|
277
|
+
var t;
|
|
279
278
|
try {
|
|
280
|
-
const
|
|
281
|
-
|
|
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
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
-
|
|
289
|
-
|
|
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
|
-
},
|
|
312
|
-
|
|
313
|
-
|
|
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(
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
}) => {
|
|
331
|
-
const
|
|
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:
|
|
334
|
-
pkgName:
|
|
312
|
+
pkgJson: w({ rootDir: e }),
|
|
313
|
+
pkgName: pt,
|
|
335
314
|
isDevPkg: !0
|
|
336
315
|
});
|
|
337
|
-
if (!
|
|
316
|
+
if (!r)
|
|
338
317
|
throw new Error("husky版本获取失败, 可能husky未安装");
|
|
339
|
-
const
|
|
340
|
-
return
|
|
341
|
-
. "$(dirname -- "$0")/_/husky.sh"`) : (console.log(
|
|
342
|
-
},
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
|
350
|
-
|
|
351
|
-
const
|
|
352
|
-
let i =
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
) : (
|
|
357
|
-
|
|
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(
|
|
341
|
+
), console.log(m.green(`${n} 添加 ${s}相关调用成功`)));
|
|
362
342
|
else {
|
|
363
|
-
const
|
|
364
|
-
|
|
343
|
+
const a = dt({
|
|
344
|
+
rootDir: e
|
|
365
345
|
});
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
`${
|
|
346
|
+
u.writeFileSync(
|
|
347
|
+
n,
|
|
348
|
+
`${a}
|
|
369
349
|
|
|
370
350
|
${i}
|
|
371
351
|
`,
|
|
372
352
|
"utf-8"
|
|
373
|
-
), console.log(
|
|
353
|
+
), console.log(m.green(`${n} 添加 ${s}相关调用成功`));
|
|
374
354
|
}
|
|
375
|
-
|
|
355
|
+
mt(n);
|
|
376
356
|
});
|
|
377
|
-
},
|
|
378
|
-
|
|
379
|
-
|
|
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(
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
572
|
+
console.log(m.blue(`拉取${t}配置,请稍等...`));
|
|
573
|
+
const r = St(t), o = f.resolve(
|
|
574
|
+
et(),
|
|
575
|
+
r
|
|
385
576
|
);
|
|
386
|
-
if (p(
|
|
577
|
+
if (p(o))
|
|
387
578
|
return console.log(
|
|
388
|
-
|
|
579
|
+
m.red(`${o} 已存在,请手动删除该目录再试`)
|
|
389
580
|
), process.exit(1);
|
|
390
|
-
const
|
|
391
|
-
|
|
581
|
+
const s = () => {
|
|
582
|
+
X(o, { recursive: !0, force: !0 });
|
|
392
583
|
};
|
|
393
|
-
let
|
|
584
|
+
let n;
|
|
394
585
|
try {
|
|
395
|
-
|
|
396
|
-
const c =
|
|
397
|
-
|
|
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
|
-
|
|
401
|
-
p(
|
|
402
|
-
}), await
|
|
403
|
-
repoUrl:
|
|
404
|
-
config:
|
|
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:
|
|
598
|
+
configTemporaryDir: o
|
|
408
599
|
});
|
|
409
600
|
} finally {
|
|
410
|
-
|
|
601
|
+
s();
|
|
411
602
|
}
|
|
412
|
-
return
|
|
603
|
+
return n;
|
|
413
604
|
};
|
|
414
605
|
export {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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.
|
|
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": "
|
|
70
|
+
"gitHead": "ff1616738586a268b50f46dce762774fa5fa6d52"
|
|
71
71
|
}
|
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
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,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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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,
|
|
20
|
+
export declare const addHuskyHooks: <H extends string>({ hookNames, rootDir, getCode, }: {
|
|
11
21
|
hookNames: H[];
|
|
12
|
-
/**
|
|
13
|
-
|
|
22
|
+
/** 运行目录 */
|
|
23
|
+
rootDir: string;
|
|
14
24
|
/** 获取husky hooks 添加的代码 */
|
|
15
25
|
getCode: (hook: string) => string;
|
|
16
26
|
}) => void;
|