cli-z-develop 0.14.3 → 0.14.5
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/dist/index.js +1153 -916
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -1,43 +1,49 @@
|
|
|
1
|
-
import { program as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
1
|
+
import { program as D } from "commander";
|
|
2
|
+
import kt from "node:child_process";
|
|
3
|
+
import * as Je from "node:fs";
|
|
4
|
+
import { existsSync as $, readdirSync as Tt, lstatSync as Et, createWriteStream as Rt, writeFileSync as It } from "node:fs";
|
|
5
|
+
import { readdir as Ce, mkdir as pe, writeFile as P, rename as qe, readFile as Ie, stat as Ct } from "node:fs/promises";
|
|
6
|
+
import l from "node:path";
|
|
7
|
+
import le, { AxiosError as xt } from "axios";
|
|
8
|
+
import A from "chalk";
|
|
9
|
+
import Dt from "dayjs";
|
|
9
10
|
import L from "shelljs";
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import { confirm as
|
|
11
|
+
import Pt from "node:os";
|
|
12
|
+
import Ue from "child_process";
|
|
13
|
+
import { confirm as Ze, select as b, input as B, password as Lt, checkbox as ve, number as Be } from "@inquirer/prompts";
|
|
13
14
|
import y from "ora";
|
|
14
|
-
import
|
|
15
|
-
import { select as
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import { run as
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
import C from "fs-extra";
|
|
16
|
+
import { select as te } from "inquirer-select-pro";
|
|
17
|
+
import Ot from "lint-staged";
|
|
18
|
+
import Mt from "semver";
|
|
19
|
+
import { run as zt } from "npm-check-updates";
|
|
20
|
+
import Ft from "p-limit";
|
|
21
|
+
import { generateTypescriptBundleApi as Jt, validateSwagger as Ut, getParsedSwagger as Bt, generateTypescriptApi as _t } from "@lonely9/api-generate";
|
|
22
|
+
import { highlight as Gt } from "cli-highlight";
|
|
23
|
+
import { ESLint as He } from "eslint";
|
|
24
|
+
import { readFileSync as Wt } from "fs";
|
|
25
|
+
import Vt from "prettier";
|
|
26
|
+
import qt from "minimist";
|
|
27
|
+
const Ke = "dev", Ye = "test", Xe = "release", Zt = "production", Ht = "master";
|
|
28
|
+
var k = /* @__PURE__ */ ((e) => (e[e.DEV = Ke] = "DEV", e[e.TEST = Ye] = "TEST", e[e.RELEASE = Xe] = "RELEASE", e[e.PROD = Zt] = "PROD", e))(k || {}), v = /* @__PURE__ */ ((e) => (e[e.DEV = Ke] = "DEV", e[e.TEST = Ye] = "TEST", e[e.RELEASE = Xe] = "RELEASE", e[e.MASTER = Ht] = "MASTER", e))(v || {}), W = /* @__PURE__ */ ((e) => (e.H5 = "h5", e.NPM = "npm", e.SERVER = "server", e))(W || {});
|
|
29
|
+
const Qe = [
|
|
24
30
|
{
|
|
25
|
-
name: `开发环境 - ${
|
|
26
|
-
value:
|
|
31
|
+
name: `开发环境 - ${k.DEV}`,
|
|
32
|
+
value: k.DEV
|
|
27
33
|
},
|
|
28
34
|
{
|
|
29
|
-
name: `测试环境 - ${
|
|
30
|
-
value:
|
|
35
|
+
name: `测试环境 - ${k.TEST}`,
|
|
36
|
+
value: k.TEST
|
|
31
37
|
},
|
|
32
38
|
{
|
|
33
|
-
name: `预发环境 - ${
|
|
34
|
-
value:
|
|
39
|
+
name: `预发环境 - ${k.RELEASE}`,
|
|
40
|
+
value: k.RELEASE
|
|
35
41
|
},
|
|
36
42
|
{
|
|
37
|
-
name: `正式环境 - ${
|
|
38
|
-
value:
|
|
43
|
+
name: `正式环境 - ${k.PROD}`,
|
|
44
|
+
value: k.PROD
|
|
39
45
|
}
|
|
40
|
-
],
|
|
46
|
+
], Kt = [
|
|
41
47
|
{
|
|
42
48
|
name: "网页 - h5",
|
|
43
49
|
value: "h5"
|
|
@@ -54,8 +60,8 @@ const Dt = [
|
|
|
54
60
|
/* SERVER */
|
|
55
61
|
}
|
|
56
62
|
];
|
|
57
|
-
var
|
|
58
|
-
const
|
|
63
|
+
var de = /* @__PURE__ */ ((e) => (e.FEAT = "feat", e.FIX = "fix", e.REFACTOR = "refactor", e))(de || {}), ue = /* @__PURE__ */ ((e) => (e.FRONT_END = "fe", e.BACK_END = "be", e.QUALITY_ASSURANCE = "qa", e))(ue || {}), w = /* @__PURE__ */ ((e) => (e.JAVA = "Java", e.JAVASCRIPT = "JavaScript", e.PYTHON = "Python", e.MARKDOWN = "Markdown", e))(w || {});
|
|
64
|
+
const Yt = {
|
|
59
65
|
1: "研发",
|
|
60
66
|
2: "测试",
|
|
61
67
|
3: "产品",
|
|
@@ -65,11 +71,11 @@ const Ot = {
|
|
|
65
71
|
7: "行政",
|
|
66
72
|
8: "财务",
|
|
67
73
|
9: "其他"
|
|
68
|
-
},
|
|
69
|
-
var
|
|
70
|
-
const
|
|
71
|
-
var
|
|
72
|
-
const
|
|
74
|
+
}, fe = "http://git.cxlqd.com", Xt = ["fe-biz", "fe-base", "fe-tpl", "fe-component", "fe-demo"];
|
|
75
|
+
var S = /* @__PURE__ */ ((e) => (e.FEAT = "feat", e.FIX = "fix", e.REFACTOR = "refactor", e.CHORE = "chore", e.CI = "ci", e.Break = "BREAKING CHANGE", e))(S || {});
|
|
76
|
+
const Qt = "fe-biz7tvsd", et = "https://hxhtbr8t8uy.feishu.cn/wiki/LWW5wAQFPiXkmRkKcjOcyDDknLg";
|
|
77
|
+
var I = /* @__PURE__ */ ((e) => (e.MODULE = "module", e.CASE = "case", e))(I || {});
|
|
78
|
+
const ea = [
|
|
73
79
|
{
|
|
74
80
|
name: "模块",
|
|
75
81
|
value: "module"
|
|
@@ -80,119 +86,122 @@ const zt = [
|
|
|
80
86
|
value: "case"
|
|
81
87
|
/* CASE */
|
|
82
88
|
}
|
|
83
|
-
],
|
|
84
|
-
function
|
|
85
|
-
return
|
|
89
|
+
], ta = 150 * 1024, aa = ".z", ia = "develop-config.json", X = ".z", na = ".commit-msg-tpl", sa = "project.json";
|
|
90
|
+
function R(e = "") {
|
|
91
|
+
return l.join(X, e);
|
|
86
92
|
}
|
|
87
|
-
function
|
|
88
|
-
return
|
|
93
|
+
function tt() {
|
|
94
|
+
return R(sa);
|
|
89
95
|
}
|
|
90
|
-
function
|
|
91
|
-
return
|
|
96
|
+
function Ne() {
|
|
97
|
+
return R(na);
|
|
92
98
|
}
|
|
93
|
-
function
|
|
94
|
-
|
|
99
|
+
function at() {
|
|
100
|
+
Ue.spawnSync("git", ["config", "core.hooksPath", R()]), Ue.spawnSync("git", ["config", "commit.template", Ne()]);
|
|
95
101
|
}
|
|
96
|
-
function
|
|
97
|
-
return
|
|
102
|
+
function he(e = "") {
|
|
103
|
+
return l.resolve(Pt.homedir(), aa, e);
|
|
98
104
|
}
|
|
99
|
-
function
|
|
100
|
-
return
|
|
105
|
+
function Ae() {
|
|
106
|
+
return he(ia);
|
|
101
107
|
}
|
|
102
|
-
function
|
|
103
|
-
return
|
|
108
|
+
function ra() {
|
|
109
|
+
return $(he());
|
|
104
110
|
}
|
|
105
|
-
function
|
|
106
|
-
return
|
|
111
|
+
function it() {
|
|
112
|
+
return ra() && $(Ae());
|
|
107
113
|
}
|
|
108
|
-
function
|
|
109
|
-
let
|
|
110
|
-
const n =
|
|
114
|
+
function Q(e, t = !0) {
|
|
115
|
+
let a = e.trim();
|
|
116
|
+
const n = a.match(/^git@([^:]+):(.+)$/);
|
|
111
117
|
if (n)
|
|
112
|
-
|
|
118
|
+
a = n[2];
|
|
113
119
|
else {
|
|
114
|
-
const s =
|
|
115
|
-
|
|
120
|
+
const s = fe.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
121
|
+
a = a.replace(/^https?:\/\//, ""), a.startsWith(`${s}/`) ? a = a.slice(s.length + 1) : a = a.replace(`${fe.replace(/\/$/, "")}/`, "");
|
|
116
122
|
}
|
|
117
|
-
const
|
|
118
|
-
return t ? encodeURIComponent(
|
|
123
|
+
const i = a.replace(/\.git$/, "");
|
|
124
|
+
return t ? encodeURIComponent(i) : i;
|
|
119
125
|
}
|
|
120
|
-
|
|
121
|
-
|
|
126
|
+
function nt(e, t) {
|
|
127
|
+
return Q(e) === Q(t);
|
|
128
|
+
}
|
|
129
|
+
const { red: _e, green: oa, blue: ns, magenta: ca, yellow: ss } = A;
|
|
130
|
+
function ye(...e) {
|
|
122
131
|
}
|
|
123
132
|
function V(...e) {
|
|
124
|
-
console.log(
|
|
133
|
+
console.log(oa(...e));
|
|
125
134
|
}
|
|
126
|
-
function
|
|
127
|
-
e instanceof Error && (e.name === "ExitPromptError" || e.message.includes("User force closed the prompt with")) && (console.log(), console.log(
|
|
135
|
+
function st(e) {
|
|
136
|
+
e instanceof Error && (e.name === "ExitPromptError" || e.message.includes("User force closed the prompt with")) && (console.log(), console.log(A.cyan(" 👋 下次见~")), console.log(), process.exit(1));
|
|
128
137
|
}
|
|
129
138
|
function m(e, t = !1) {
|
|
130
|
-
|
|
131
|
-
let
|
|
132
|
-
e instanceof Error ? (
|
|
139
|
+
st(e);
|
|
140
|
+
let a = e;
|
|
141
|
+
e instanceof Error ? (a = e.message, le.isAxiosError(e) && (a = `请求失败:${e.message}`), console.log(_e(a)), console.log(ca(e.stack))) : console.log(_e(e)), t || process.exit(1);
|
|
133
142
|
}
|
|
134
|
-
function
|
|
135
|
-
return
|
|
143
|
+
function Ge(e) {
|
|
144
|
+
return $(e) ? Et(e).isDirectory() : !1;
|
|
136
145
|
}
|
|
137
|
-
function
|
|
138
|
-
return
|
|
146
|
+
function rt(e = process.cwd()) {
|
|
147
|
+
return Ge(e) ? Tt(e).filter((a) => Ge(l.resolve(e, a))) : [];
|
|
139
148
|
}
|
|
140
|
-
async function
|
|
149
|
+
async function d(e, t = {
|
|
141
150
|
removeTailLinkBreak: !0,
|
|
142
151
|
silent: !0
|
|
143
152
|
}) {
|
|
144
|
-
let
|
|
153
|
+
let a = await new Promise((n, i) => {
|
|
145
154
|
try {
|
|
146
155
|
const s = L.exec(e, {
|
|
147
156
|
silent: t.silent
|
|
148
157
|
});
|
|
149
158
|
n(s);
|
|
150
159
|
} catch (s) {
|
|
151
|
-
|
|
160
|
+
i(s);
|
|
152
161
|
}
|
|
153
162
|
});
|
|
154
|
-
return
|
|
163
|
+
return a = a.toString(), t.removeTailLinkBreak && (a = a.replace(/\n$/, "")), a;
|
|
155
164
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
165
|
+
function ua(e) {
|
|
166
|
+
kt.execSync(e, {
|
|
158
167
|
stdio: "inherit"
|
|
159
168
|
});
|
|
160
169
|
}
|
|
161
|
-
function
|
|
162
|
-
return
|
|
170
|
+
function ot() {
|
|
171
|
+
return Dt(Date.now()).format("YYMMDD");
|
|
163
172
|
}
|
|
164
|
-
function
|
|
165
|
-
for (const
|
|
166
|
-
if (!e.includes(
|
|
173
|
+
function la(e, t) {
|
|
174
|
+
for (const a of t)
|
|
175
|
+
if (!e.includes(a))
|
|
167
176
|
return !1;
|
|
168
177
|
return !0;
|
|
169
178
|
}
|
|
170
179
|
function ae() {
|
|
171
|
-
|
|
180
|
+
$(R()) || m("当前不在项目根目录。请切换到项目根目录");
|
|
172
181
|
}
|
|
173
|
-
function
|
|
174
|
-
|
|
182
|
+
function Z() {
|
|
183
|
+
$(l.resolve(".git")) || m("当前不是git项目根目录,请先执行git init,或切换到根目录");
|
|
175
184
|
}
|
|
176
185
|
async function be() {
|
|
177
|
-
await
|
|
186
|
+
await d("git status -s") !== "" && m("请先提交代码变动,再进行操作");
|
|
178
187
|
}
|
|
179
|
-
function
|
|
180
|
-
return e ===
|
|
188
|
+
function ma(e) {
|
|
189
|
+
return e === v.MASTER ? k.PROD : e;
|
|
181
190
|
}
|
|
182
|
-
function
|
|
183
|
-
return e ===
|
|
191
|
+
function pa(e) {
|
|
192
|
+
return e === k.PROD ? v.MASTER : e;
|
|
184
193
|
}
|
|
185
194
|
async function F(e, ...t) {
|
|
186
195
|
try {
|
|
187
196
|
await e(...t);
|
|
188
|
-
} catch (
|
|
189
|
-
throw
|
|
197
|
+
} catch (a) {
|
|
198
|
+
throw st(a), a;
|
|
190
199
|
}
|
|
191
200
|
}
|
|
192
|
-
async function
|
|
193
|
-
return (await
|
|
201
|
+
async function da(e) {
|
|
202
|
+
return (await Ce(e)).length === 0;
|
|
194
203
|
}
|
|
195
|
-
function
|
|
204
|
+
function fa(e = "项目中文名", t = "项目描述") {
|
|
196
205
|
return `
|
|
197
206
|
# ${e}
|
|
198
207
|
${t}
|
|
@@ -249,7 +258,7 @@ ${t}
|
|
|
249
258
|
在此处放入飞书文档链接。请在[前端团队-项目手册](https://hxhtbr8t8uy.feishu.cn/drive/folder/QfQ7favVWljQk7d63Prc8mUGnJf)中按照分类新建文档。
|
|
250
259
|
`;
|
|
251
260
|
}
|
|
252
|
-
const
|
|
261
|
+
const ga = {
|
|
253
262
|
[w.JAVA]: {
|
|
254
263
|
"**/*.{java}": "java -jar ./.z/checkstyle.jar -c ./.z/checkstyle.xml"
|
|
255
264
|
},
|
|
@@ -267,17 +276,17 @@ const Qt = {
|
|
|
267
276
|
"**/*.{vue,js,jsx,cjs,mjs,ts,tsx,cts,mts}": "eslint --fix",
|
|
268
277
|
"**/*.md": "markdownlint --fix"
|
|
269
278
|
}
|
|
270
|
-
},
|
|
271
|
-
name:
|
|
272
|
-
version:
|
|
273
|
-
description:
|
|
274
|
-
main:
|
|
275
|
-
bin:
|
|
276
|
-
scripts:
|
|
277
|
-
type:
|
|
278
|
-
author:
|
|
279
|
-
devDependencies:
|
|
280
|
-
dependencies:
|
|
279
|
+
}, ha = "cli-z-develop", wa = "0.14.5", ya = "技术团队开发流程管理工具", va = "dist/index.js", $a = { z: "bin/z.js", "z-develop": "bin/z.js" }, Na = { prepare: "[ -n '$z' ] && z init prepare || echo 'Warning: z not exist at global'", dev: "vite build --watch", test: "bun src/main.ts", "test:debug": "DEBUG=true bun src/main.ts", "dev:debug": "DEBUG=true vite build --watch", build: "vite build", eslint: "eslint '**/*.{ts,js}' --fix", prettier: "prettier -wu .", upload: "npm run build && npm publish --access public --registry https://registry.npmjs.org/", "upload:patch": "npm version patch && npm run upload", "upload:minor": "npm version minor && npm run upload", "upload:major": "npm version major && npm run upload" }, Aa = "module", ba = "z", ja = { "@lonely9/eslint-config-team": "^1.3.8", "@tsconfig/node22": "^22.0.5", "@types/fs-extra": "^11.0.4", "@types/inquirer": "^9.0.9", "@types/minimist": "^1.2.5", "@types/node": "^22.15.29", "@types/semver": "^7.7.1", "@types/shelljs": "^0.10.0", "@typescript-eslint/eslint-plugin": "^8.58.2", "@typescript-eslint/parser": "^8.58.2", eslint: "^9.39.2", jiti: "^2.6.1", prettier: "^3.8.2", typescript: "^5.9.3", vite: "^7.3.1", "vue-tsc": "^3.2.6" }, Sa = { "@inquirer/prompts": "^8.4.1", "@lonely9/api-generate": "^0.2.5", axios: "^1.15.0", chalk: "^5.6.2", "cli-highlight": "^2.1.11", commander: "^14.0.3", dayjs: "^1.11.20", eslint: "^9.39.2", "fs-extra": "^11.3.4", "inquirer-select-pro": "^1.0.0-alpha.9", "lint-staged": "^16.4.0", minimist: "^1.2.8", "npm-check-updates": "^19.3.1", ora: "^9.3.0", "p-limit": "^7.3.0", prettier: "^3.8.2", semver: "^7.7.4", shelljs: "^0.10.0" }, re = {
|
|
280
|
+
name: ha,
|
|
281
|
+
version: wa,
|
|
282
|
+
description: ya,
|
|
283
|
+
main: va,
|
|
284
|
+
bin: $a,
|
|
285
|
+
scripts: Na,
|
|
286
|
+
type: Aa,
|
|
287
|
+
author: ba,
|
|
288
|
+
devDependencies: ja,
|
|
289
|
+
dependencies: Sa
|
|
281
290
|
}, x = {
|
|
282
291
|
// 个人数据
|
|
283
292
|
profile: {
|
|
@@ -290,13 +299,13 @@ const Qt = {
|
|
|
290
299
|
gitEmail: "",
|
|
291
300
|
weWorkName: "",
|
|
292
301
|
weWorkUserId: "",
|
|
293
|
-
jobType:
|
|
302
|
+
jobType: ue.FRONT_END,
|
|
294
303
|
zenTaoToken: "",
|
|
295
304
|
k8sToken: ""
|
|
296
305
|
},
|
|
297
306
|
// 包数据
|
|
298
307
|
main: {
|
|
299
|
-
version:
|
|
308
|
+
version: re.version,
|
|
300
309
|
latestCheckVersionTimestamp: 0,
|
|
301
310
|
// 3天检查一次
|
|
302
311
|
versionCheckDuring: 3,
|
|
@@ -312,66 +321,66 @@ const Qt = {
|
|
|
312
321
|
FECDNDomain: ""
|
|
313
322
|
}
|
|
314
323
|
};
|
|
315
|
-
function
|
|
324
|
+
function E(e) {
|
|
316
325
|
return e ? x.profile[e] : x.profile;
|
|
317
326
|
}
|
|
318
|
-
function
|
|
327
|
+
function ge(e) {
|
|
319
328
|
return e ? x.main[e] : x.main;
|
|
320
329
|
}
|
|
321
|
-
function
|
|
330
|
+
function z(e) {
|
|
322
331
|
return e ? x.constants[e] : x.constants;
|
|
323
332
|
}
|
|
324
|
-
let
|
|
333
|
+
let _ = null, G = null;
|
|
325
334
|
function xe() {
|
|
326
|
-
if (
|
|
327
|
-
return
|
|
328
|
-
const e =
|
|
329
|
-
return
|
|
335
|
+
if (_)
|
|
336
|
+
return _;
|
|
337
|
+
const e = l.join("package.json");
|
|
338
|
+
return $(e) || m(`当前目录(${L.pwd()})不存在${e}文件,请在项目根目录执行该命令。`), _ = C.readJsonSync(e), _;
|
|
330
339
|
}
|
|
331
|
-
function
|
|
340
|
+
function ie() {
|
|
332
341
|
if (G)
|
|
333
342
|
return G;
|
|
334
|
-
const e =
|
|
335
|
-
return
|
|
343
|
+
const e = tt();
|
|
344
|
+
return $(e) || m(
|
|
336
345
|
`当前目录(${L.pwd()})不存在${e}文件,请在项目根目录执行该命令,或者初始化项目(z init .)。`
|
|
337
|
-
), G =
|
|
346
|
+
), G = C.readJsonSync(e), G;
|
|
338
347
|
}
|
|
339
|
-
function
|
|
348
|
+
function ct(e) {
|
|
340
349
|
G ? G = {
|
|
341
350
|
...G,
|
|
342
351
|
...e
|
|
343
|
-
} : G = e,
|
|
352
|
+
} : G = e, C.writeJSONSync(tt(), G, { spaces: 2 });
|
|
344
353
|
}
|
|
345
|
-
function
|
|
346
|
-
|
|
347
|
-
...
|
|
354
|
+
function ka(e) {
|
|
355
|
+
_ ? _ = {
|
|
356
|
+
..._,
|
|
348
357
|
...e
|
|
349
|
-
} :
|
|
358
|
+
} : _ = e, C.writeJSONSync(l.join("package.json"), _, { spaces: 2 });
|
|
350
359
|
}
|
|
351
|
-
const
|
|
360
|
+
const Y = {
|
|
352
361
|
id: 0,
|
|
353
362
|
path: "",
|
|
354
363
|
group: "",
|
|
355
364
|
sourceBranch: "",
|
|
356
365
|
mergeRequestUrl: ""
|
|
357
366
|
};
|
|
358
|
-
async function
|
|
359
|
-
if (!
|
|
367
|
+
async function Ta() {
|
|
368
|
+
if (!Y.id)
|
|
360
369
|
try {
|
|
361
|
-
const e =
|
|
362
|
-
|
|
370
|
+
const e = ie(), t = Q(e.repository.url), a = await mt(t);
|
|
371
|
+
Y.id = a.id, Y.path = t, Y.group = a.namespace.full_path, Y.mergeRequestUrl = `${a.web_url}/merge_requests`;
|
|
363
372
|
} catch (e) {
|
|
364
373
|
m(e);
|
|
365
374
|
}
|
|
366
|
-
return
|
|
375
|
+
return Y.sourceBranch || (Y.sourceBranch = await d("git branch --show-current")), Y;
|
|
367
376
|
}
|
|
368
|
-
function
|
|
369
|
-
|
|
370
|
-
|
|
377
|
+
function oe() {
|
|
378
|
+
C.writeJSONSync(
|
|
379
|
+
Ae(),
|
|
371
380
|
{
|
|
372
|
-
main:
|
|
373
|
-
profile:
|
|
374
|
-
constants:
|
|
381
|
+
main: ge(),
|
|
382
|
+
profile: E(),
|
|
383
|
+
constants: z()
|
|
375
384
|
},
|
|
376
385
|
{
|
|
377
386
|
spaces: 2
|
|
@@ -384,330 +393,347 @@ function M(e, t) {
|
|
|
384
393
|
...e
|
|
385
394
|
};
|
|
386
395
|
}
|
|
387
|
-
function
|
|
396
|
+
function je(e, t) {
|
|
388
397
|
x.constants = {
|
|
389
398
|
...x.constants,
|
|
390
399
|
...e
|
|
391
400
|
};
|
|
392
401
|
}
|
|
393
|
-
function
|
|
402
|
+
function me(e, t) {
|
|
394
403
|
t !== void 0 ? x.main[e] = t : x.main = {
|
|
395
404
|
...x.main,
|
|
396
405
|
...e
|
|
397
406
|
};
|
|
398
407
|
}
|
|
399
|
-
async function
|
|
400
|
-
const t = e.method || "get",
|
|
408
|
+
async function H(e) {
|
|
409
|
+
const t = e.method || "get", a = e.headers || {}, n = e.data || {}, i = e.dataKey ?? (["GET", "get"].includes(t) ? "params" : "data");
|
|
401
410
|
try {
|
|
402
411
|
const s = {
|
|
403
412
|
url: e.url,
|
|
404
413
|
method: t,
|
|
405
|
-
[
|
|
406
|
-
headers:
|
|
414
|
+
[i]: n,
|
|
415
|
+
headers: a,
|
|
407
416
|
responseType: e?.responseType || "json"
|
|
408
417
|
};
|
|
409
|
-
|
|
410
|
-
const o = await
|
|
411
|
-
return
|
|
418
|
+
ye(A.magenta(s.method.toUpperCase()), A.yellow(s.url), JSON.stringify(s.headers)), ye(A.gray(JSON.stringify(s[i], null, 2)));
|
|
419
|
+
const o = await le(s);
|
|
420
|
+
return ye(A.green("Response"), A.grey(JSON.stringify(o.data, null, 2))), Promise.resolve(o.data);
|
|
412
421
|
} catch (s) {
|
|
413
|
-
return s instanceof
|
|
422
|
+
return s instanceof xt && ye(A.red("Error"), A.grey(JSON.stringify(s?.response?.data))), Promise.reject(s);
|
|
414
423
|
}
|
|
415
424
|
}
|
|
416
|
-
async function
|
|
417
|
-
const e =
|
|
425
|
+
async function Ea() {
|
|
426
|
+
const e = E("gitToken");
|
|
418
427
|
if (e)
|
|
419
428
|
return e;
|
|
420
429
|
{
|
|
421
|
-
const { access_token: t } = await
|
|
422
|
-
url: `${
|
|
430
|
+
const { access_token: t } = await H({
|
|
431
|
+
url: `${fe}/oauth/token`,
|
|
423
432
|
method: "post",
|
|
424
433
|
data: {
|
|
425
434
|
grant_type: "password",
|
|
426
|
-
username:
|
|
427
|
-
password:
|
|
435
|
+
username: E("ldapAccount"),
|
|
436
|
+
password: E("ldapPassword")
|
|
428
437
|
}
|
|
429
|
-
}),
|
|
430
|
-
return M("gitToken",
|
|
438
|
+
}), a = `Bearer ${t}`;
|
|
439
|
+
return M("gitToken", a), oe(), a;
|
|
431
440
|
}
|
|
432
441
|
}
|
|
433
442
|
async function N(e) {
|
|
434
|
-
return
|
|
443
|
+
return H({
|
|
435
444
|
...e,
|
|
436
445
|
headers: {
|
|
437
|
-
Authorization: await
|
|
446
|
+
Authorization: await Ea()
|
|
438
447
|
}
|
|
439
448
|
});
|
|
440
449
|
}
|
|
441
|
-
async function
|
|
442
|
-
const e =
|
|
450
|
+
async function Ra() {
|
|
451
|
+
const e = E("zenTaoToken");
|
|
443
452
|
if (e)
|
|
444
453
|
return e;
|
|
445
454
|
{
|
|
446
|
-
const { token: t } = await
|
|
447
|
-
url: `${
|
|
455
|
+
const { token: t } = await H({
|
|
456
|
+
url: `${z("ZenTaoDomain")}/api.php/v1/tokens`,
|
|
448
457
|
method: "post",
|
|
449
458
|
data: {
|
|
450
|
-
account:
|
|
451
|
-
password:
|
|
459
|
+
account: E("ldapAccount"),
|
|
460
|
+
password: E("ldapPassword")
|
|
452
461
|
}
|
|
453
462
|
});
|
|
454
|
-
return M("zenTaoToken", t),
|
|
463
|
+
return M("zenTaoToken", t), oe(), t;
|
|
455
464
|
}
|
|
456
465
|
}
|
|
457
466
|
async function $e(e) {
|
|
458
|
-
const t = await
|
|
467
|
+
const t = await H({
|
|
459
468
|
...e,
|
|
460
469
|
headers: {
|
|
461
|
-
Token: await
|
|
470
|
+
Token: await Ra()
|
|
462
471
|
}
|
|
463
472
|
});
|
|
464
473
|
if (e.url.includes("local")) {
|
|
465
474
|
if (typeof t == "string") {
|
|
466
|
-
const
|
|
467
|
-
return JSON.parse(
|
|
475
|
+
const a = JSON.parse(t.slice(0, t.indexOf("<script>")));
|
|
476
|
+
return JSON.parse(a.data);
|
|
468
477
|
}
|
|
469
478
|
if (typeof t == "object")
|
|
470
479
|
return t.error === "Unauthorized" || t.data.indexOf("<script>") < 0 ? (M("zenTaoToken", ""), $e({
|
|
471
480
|
...e
|
|
472
481
|
})) : t;
|
|
473
482
|
} else {
|
|
474
|
-
const { status:
|
|
475
|
-
if (
|
|
476
|
-
const
|
|
477
|
-
return
|
|
483
|
+
const { status: a, data: n } = t;
|
|
484
|
+
if (a === "success") {
|
|
485
|
+
const i = JSON.parse(n);
|
|
486
|
+
return i.title === "用户登录" ? (M("zenTaoToken", ""), $e({
|
|
478
487
|
...e
|
|
479
|
-
})) :
|
|
488
|
+
})) : i;
|
|
480
489
|
} else
|
|
481
490
|
return {};
|
|
482
491
|
}
|
|
483
492
|
}
|
|
484
|
-
async function
|
|
485
|
-
const e =
|
|
493
|
+
async function Ia() {
|
|
494
|
+
const e = E("k8sToken");
|
|
486
495
|
if (e)
|
|
487
496
|
return e;
|
|
488
497
|
{
|
|
489
|
-
const { access_token: t } = await
|
|
490
|
-
url: `${
|
|
498
|
+
const { access_token: t } = await H({
|
|
499
|
+
url: `${z("K8sDomain")}/oauth/login/LDAP`,
|
|
491
500
|
method: "post",
|
|
492
501
|
headers: {
|
|
493
502
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
494
503
|
},
|
|
495
504
|
data: {
|
|
496
|
-
username:
|
|
497
|
-
password:
|
|
505
|
+
username: E("ldapAccount"),
|
|
506
|
+
password: E("ldapPassword")
|
|
498
507
|
}
|
|
499
|
-
}),
|
|
500
|
-
return M("k8sToken",
|
|
508
|
+
}), a = `Bearer ${t}`;
|
|
509
|
+
return M("k8sToken", a), oe(), a;
|
|
501
510
|
}
|
|
502
511
|
}
|
|
503
|
-
async function
|
|
504
|
-
const t = await
|
|
512
|
+
async function ut(e) {
|
|
513
|
+
const t = await H({
|
|
505
514
|
...e,
|
|
506
515
|
headers: {
|
|
507
|
-
Authorization: await
|
|
516
|
+
Authorization: await Ia()
|
|
508
517
|
}
|
|
509
518
|
});
|
|
510
|
-
return t.code === 401 ? (M("k8sToken", ""),
|
|
519
|
+
return t.code === 401 ? (M("k8sToken", ""), ut({
|
|
511
520
|
...e
|
|
512
521
|
})) : t;
|
|
513
522
|
}
|
|
514
|
-
async function
|
|
523
|
+
async function Ca(e, t) {
|
|
515
524
|
try {
|
|
516
|
-
const
|
|
517
|
-
return (await
|
|
525
|
+
const a = Rt(t, { mode: 493 });
|
|
526
|
+
return (await le({
|
|
518
527
|
method: "get",
|
|
519
528
|
url: e,
|
|
520
529
|
responseType: "stream",
|
|
521
530
|
headers: {
|
|
522
531
|
"Content-Type": "application/octet-stream"
|
|
523
532
|
}
|
|
524
|
-
})).data.pipe(
|
|
525
|
-
|
|
533
|
+
})).data.pipe(a), new Promise((i, s) => {
|
|
534
|
+
a.on("finish", () => i(1)), a.on("error", s);
|
|
526
535
|
});
|
|
527
|
-
} catch (
|
|
528
|
-
throw console.error("下载失败:",
|
|
536
|
+
} catch (a) {
|
|
537
|
+
throw console.error("下载失败:", a), a;
|
|
529
538
|
}
|
|
530
539
|
}
|
|
531
|
-
const
|
|
532
|
-
function
|
|
540
|
+
const J = () => `${fe}/api/v4`, U = (e) => `${J()}/projects/100/repository/files/${encodeURIComponent(e)}/raw?ref=master`;
|
|
541
|
+
function xa() {
|
|
533
542
|
return N({
|
|
534
|
-
url:
|
|
543
|
+
url: U("src/data/template-projects.json")
|
|
535
544
|
});
|
|
536
545
|
}
|
|
537
|
-
function
|
|
546
|
+
function Da() {
|
|
538
547
|
return N({
|
|
539
|
-
url:
|
|
548
|
+
url: U("src/data/java-project-module.json")
|
|
540
549
|
});
|
|
541
550
|
}
|
|
542
|
-
function
|
|
551
|
+
function Pa() {
|
|
543
552
|
return N({
|
|
544
|
-
url:
|
|
553
|
+
url: U("src/data/java-project-api.json")
|
|
545
554
|
});
|
|
546
555
|
}
|
|
547
|
-
function
|
|
556
|
+
function De() {
|
|
548
557
|
return N({
|
|
549
|
-
url:
|
|
558
|
+
url: U("src/data/z-develop-config.json")
|
|
550
559
|
});
|
|
551
560
|
}
|
|
552
|
-
function
|
|
561
|
+
function La() {
|
|
553
562
|
return N({
|
|
554
|
-
url:
|
|
563
|
+
url: U("src/assets/tsconfig.browser.json")
|
|
555
564
|
});
|
|
556
565
|
}
|
|
557
|
-
function
|
|
566
|
+
function Oa() {
|
|
558
567
|
return N({
|
|
559
|
-
url:
|
|
568
|
+
url: U("src/assets/tsconfig.node.json")
|
|
560
569
|
});
|
|
561
570
|
}
|
|
562
|
-
function
|
|
571
|
+
function Ma() {
|
|
563
572
|
return N({
|
|
564
|
-
url:
|
|
573
|
+
url: U("src/assets/.prettierignore")
|
|
565
574
|
});
|
|
566
575
|
}
|
|
567
|
-
function
|
|
576
|
+
function za() {
|
|
568
577
|
return N({
|
|
569
|
-
url:
|
|
578
|
+
url: U("src/assets/.prettierrc.json")
|
|
570
579
|
});
|
|
571
580
|
}
|
|
572
|
-
function
|
|
581
|
+
function Fa() {
|
|
573
582
|
return N({
|
|
574
|
-
url:
|
|
583
|
+
url: U("src/assets/data.yaml")
|
|
575
584
|
});
|
|
576
585
|
}
|
|
577
|
-
function
|
|
586
|
+
function Ja() {
|
|
578
587
|
return N({
|
|
579
|
-
url:
|
|
588
|
+
url: U("src/assets/main.py")
|
|
580
589
|
});
|
|
581
590
|
}
|
|
582
|
-
function
|
|
591
|
+
function Ua() {
|
|
583
592
|
return N({
|
|
584
|
-
url:
|
|
593
|
+
url: U("src/assets/checkstyle.xml")
|
|
585
594
|
});
|
|
586
595
|
}
|
|
587
|
-
function
|
|
596
|
+
function lt() {
|
|
588
597
|
return N({
|
|
589
|
-
url:
|
|
598
|
+
url: U("src/data/project-group-chats.json")
|
|
590
599
|
});
|
|
591
600
|
}
|
|
592
|
-
function
|
|
601
|
+
function Ba() {
|
|
593
602
|
return N({
|
|
594
|
-
url: `${
|
|
603
|
+
url: `${J()}/user`
|
|
595
604
|
});
|
|
596
605
|
}
|
|
597
|
-
function
|
|
606
|
+
function _a() {
|
|
598
607
|
return N({
|
|
599
|
-
url: `${
|
|
608
|
+
url: `${J()}/groups`
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
function Ga(e) {
|
|
612
|
+
return N({
|
|
613
|
+
url: `${J()}/projects`,
|
|
600
614
|
method: "post",
|
|
601
615
|
data: e
|
|
602
616
|
});
|
|
603
617
|
}
|
|
604
|
-
function
|
|
618
|
+
function mt(e) {
|
|
605
619
|
return N({
|
|
606
|
-
url: `${
|
|
620
|
+
url: `${J()}/projects/${e}`
|
|
607
621
|
});
|
|
608
622
|
}
|
|
609
|
-
function
|
|
623
|
+
function Wa(e) {
|
|
610
624
|
return N({
|
|
611
|
-
url: `${
|
|
625
|
+
url: `${J()}/projects`,
|
|
612
626
|
data: {
|
|
613
627
|
search: e,
|
|
614
628
|
search_namespaces: !0
|
|
615
629
|
}
|
|
616
630
|
});
|
|
617
631
|
}
|
|
618
|
-
function
|
|
632
|
+
function Va(e) {
|
|
619
633
|
return N({
|
|
620
|
-
url: `${
|
|
634
|
+
url: `${J()}/projects/${e.id}/merge_requests`,
|
|
621
635
|
method: "post",
|
|
622
636
|
data: e
|
|
623
637
|
});
|
|
624
638
|
}
|
|
625
|
-
function
|
|
639
|
+
function qa(e) {
|
|
626
640
|
return N({
|
|
627
|
-
url: `${
|
|
641
|
+
url: `${J()}/projects/${e.id}/merge_requests/${e.iid}/merge`,
|
|
628
642
|
method: "put"
|
|
629
643
|
});
|
|
630
644
|
}
|
|
631
|
-
function
|
|
645
|
+
function Za(e) {
|
|
632
646
|
return N({
|
|
633
|
-
url: `${
|
|
647
|
+
url: `${J()}/projects/${e.id}/merge_requests/${e.iid}`,
|
|
634
648
|
method: "put",
|
|
635
649
|
data: e
|
|
636
650
|
});
|
|
637
651
|
}
|
|
638
|
-
function
|
|
652
|
+
function Ha(e) {
|
|
639
653
|
return N({
|
|
640
|
-
url: `${
|
|
654
|
+
url: `${J()}/projects/${e.id}/merge_requests/${e.iid}`,
|
|
641
655
|
method: "get"
|
|
642
656
|
});
|
|
643
657
|
}
|
|
644
|
-
function
|
|
658
|
+
function Ka(e) {
|
|
645
659
|
return N({
|
|
646
|
-
url: `${
|
|
660
|
+
url: `${J()}/projects/${e.id}/repository/branches`,
|
|
647
661
|
method: "post",
|
|
648
662
|
data: e
|
|
649
663
|
});
|
|
650
664
|
}
|
|
651
|
-
function
|
|
665
|
+
function Ya(e) {
|
|
652
666
|
return N({
|
|
653
|
-
url: `${
|
|
667
|
+
url: `${J()}/projects/${e}/repository/branches`
|
|
654
668
|
});
|
|
655
669
|
}
|
|
656
|
-
function
|
|
657
|
-
const e =
|
|
658
|
-
return
|
|
670
|
+
function Xa() {
|
|
671
|
+
const e = he("fe-groups.json");
|
|
672
|
+
return $(e) ? C.readJSONSync(e) : { groups: [] };
|
|
659
673
|
}
|
|
660
|
-
async function
|
|
661
|
-
const e = await
|
|
662
|
-
const n = e.find((
|
|
674
|
+
async function Qa() {
|
|
675
|
+
const e = await _a(), t = Xt.map((a) => {
|
|
676
|
+
const n = e.find((i) => i.name === a);
|
|
663
677
|
return n ? {
|
|
664
678
|
name: n.name,
|
|
665
679
|
id: n.id,
|
|
666
680
|
description: n.description
|
|
667
681
|
} : !1;
|
|
668
|
-
}).filter((
|
|
669
|
-
|
|
682
|
+
}).filter((a) => !!a);
|
|
683
|
+
C.writeJSONSync(he("fe-groups.json"), { groups: t }, { spaces: 2 });
|
|
684
|
+
}
|
|
685
|
+
async function j(e) {
|
|
686
|
+
const t = `${z("FEServerDomain")}/api`, a = await H({
|
|
687
|
+
url: t + e.url,
|
|
688
|
+
headers: {
|
|
689
|
+
"the-key-one": "z-develop",
|
|
690
|
+
"the-key-two": z("ZDevelopPassword")
|
|
691
|
+
},
|
|
692
|
+
data: e.data,
|
|
693
|
+
method: e.method || "post"
|
|
694
|
+
});
|
|
695
|
+
return a.code !== 0 && m(`${a.code}: ${a.message}`), a.data;
|
|
670
696
|
}
|
|
671
|
-
async function
|
|
672
|
-
const t = `${
|
|
697
|
+
async function ei(e) {
|
|
698
|
+
const t = `${z("FEServerDomain")}/api`;
|
|
699
|
+
return await H({
|
|
673
700
|
url: t + e.url,
|
|
674
701
|
headers: {
|
|
675
702
|
"the-key-one": "z-develop",
|
|
676
|
-
"the-key-two":
|
|
703
|
+
"the-key-two": z("ZDevelopPassword")
|
|
677
704
|
},
|
|
678
705
|
data: e.data,
|
|
679
706
|
method: e.method || "post"
|
|
680
707
|
});
|
|
681
|
-
return i.code !== 0 && m(`${i.code}: ${i.message}`), i.data;
|
|
682
708
|
}
|
|
683
|
-
function
|
|
684
|
-
return
|
|
709
|
+
function ti() {
|
|
710
|
+
return j({
|
|
685
711
|
url: "/user/list2"
|
|
686
712
|
});
|
|
687
713
|
}
|
|
688
|
-
function
|
|
689
|
-
return
|
|
714
|
+
function ai() {
|
|
715
|
+
return j({
|
|
690
716
|
url: "/zen/testcase/product/list"
|
|
691
717
|
});
|
|
692
718
|
}
|
|
693
|
-
function
|
|
694
|
-
return
|
|
719
|
+
function pt(e) {
|
|
720
|
+
return j({
|
|
695
721
|
url: "/zen/testcase/product/module/list",
|
|
696
722
|
data: {
|
|
697
723
|
product: e
|
|
698
724
|
}
|
|
699
725
|
});
|
|
700
726
|
}
|
|
701
|
-
function
|
|
702
|
-
return
|
|
727
|
+
function ii(e) {
|
|
728
|
+
return j({
|
|
703
729
|
url: "/zen/testcase/product/name",
|
|
704
730
|
data: {
|
|
705
731
|
product: e
|
|
706
732
|
}
|
|
707
733
|
});
|
|
708
734
|
}
|
|
709
|
-
function
|
|
710
|
-
return
|
|
735
|
+
function ni(e, t) {
|
|
736
|
+
return j({
|
|
711
737
|
url: "/zen/testcase/product/auto-case/list",
|
|
712
738
|
data: {
|
|
713
739
|
product: e,
|
|
@@ -715,193 +741,199 @@ function _i(e, t) {
|
|
|
715
741
|
}
|
|
716
742
|
});
|
|
717
743
|
}
|
|
718
|
-
function
|
|
719
|
-
return
|
|
744
|
+
function si(e) {
|
|
745
|
+
return j({
|
|
720
746
|
url: "/zen/testcase/step/list",
|
|
721
747
|
data: {
|
|
722
748
|
id: e
|
|
723
749
|
}
|
|
724
750
|
});
|
|
725
751
|
}
|
|
726
|
-
function
|
|
727
|
-
return
|
|
752
|
+
function ri(e) {
|
|
753
|
+
return j({
|
|
728
754
|
url: "/zen/testcase/module/create",
|
|
729
755
|
data: e
|
|
730
756
|
});
|
|
731
757
|
}
|
|
732
|
-
function
|
|
733
|
-
return
|
|
758
|
+
function oi(e) {
|
|
759
|
+
return j({
|
|
734
760
|
url: "/zen/testcase/create",
|
|
735
761
|
data: e
|
|
736
762
|
});
|
|
737
763
|
}
|
|
738
|
-
function
|
|
739
|
-
return
|
|
764
|
+
function ci(e) {
|
|
765
|
+
return j({
|
|
740
766
|
url: "/zen/testcase/step/create",
|
|
741
767
|
data: e
|
|
742
768
|
});
|
|
743
769
|
}
|
|
744
|
-
function
|
|
745
|
-
return
|
|
770
|
+
function ui(e) {
|
|
771
|
+
return j({
|
|
746
772
|
url: "/zen/testcase/modules/remove",
|
|
747
773
|
data: e
|
|
748
774
|
});
|
|
749
775
|
}
|
|
750
|
-
function
|
|
751
|
-
return
|
|
776
|
+
function li(e) {
|
|
777
|
+
return j({
|
|
752
778
|
url: "/zen/testcase/cases/remove",
|
|
753
779
|
data: e
|
|
754
780
|
});
|
|
755
781
|
}
|
|
756
|
-
function
|
|
757
|
-
return
|
|
782
|
+
function mi(e) {
|
|
783
|
+
return j({
|
|
758
784
|
url: "/zen/testcase/module/update/name",
|
|
759
785
|
data: e
|
|
760
786
|
});
|
|
761
787
|
}
|
|
762
|
-
function
|
|
763
|
-
return
|
|
788
|
+
function pi(e) {
|
|
789
|
+
return j({
|
|
764
790
|
url: "/zen/testcase/case/update/name",
|
|
765
791
|
data: e
|
|
766
792
|
});
|
|
767
793
|
}
|
|
768
|
-
function
|
|
769
|
-
return
|
|
794
|
+
function di(e) {
|
|
795
|
+
return j({
|
|
770
796
|
url: "/zen/testcase/case/update/priority",
|
|
771
797
|
data: e
|
|
772
798
|
});
|
|
773
799
|
}
|
|
774
|
-
function
|
|
775
|
-
return
|
|
800
|
+
function fi(e) {
|
|
801
|
+
return j({
|
|
776
802
|
url: "/zen/testcase/case/update/precondition",
|
|
777
803
|
data: e
|
|
778
804
|
});
|
|
779
805
|
}
|
|
780
|
-
function
|
|
781
|
-
return
|
|
806
|
+
function gi(e) {
|
|
807
|
+
return j({
|
|
782
808
|
url: "/zen/testcase/case/result/create",
|
|
783
809
|
data: e
|
|
784
810
|
});
|
|
785
811
|
}
|
|
786
|
-
function
|
|
787
|
-
return
|
|
812
|
+
function hi() {
|
|
813
|
+
return j({
|
|
788
814
|
url: "/zen/testcase/project/list"
|
|
789
815
|
});
|
|
790
816
|
}
|
|
791
|
-
function
|
|
792
|
-
return
|
|
817
|
+
function wi(e) {
|
|
818
|
+
return j({
|
|
793
819
|
url: "/zen/testcase/project/execution/list",
|
|
794
820
|
data: {
|
|
795
821
|
project: e
|
|
796
822
|
}
|
|
797
823
|
});
|
|
798
824
|
}
|
|
799
|
-
function
|
|
800
|
-
return
|
|
825
|
+
function yi(e) {
|
|
826
|
+
return j({
|
|
801
827
|
url: "/zen/testcase/execution/build/list",
|
|
802
828
|
data: {
|
|
803
829
|
id: e
|
|
804
830
|
}
|
|
805
831
|
});
|
|
806
832
|
}
|
|
807
|
-
function
|
|
808
|
-
return
|
|
833
|
+
function vi(e) {
|
|
834
|
+
return j({
|
|
809
835
|
url: "/common/ai/talk",
|
|
810
836
|
data: e
|
|
811
837
|
});
|
|
812
838
|
}
|
|
813
|
-
function
|
|
814
|
-
|
|
839
|
+
function $i(e) {
|
|
840
|
+
return ei({
|
|
841
|
+
url: "/common/notify/group/send",
|
|
842
|
+
data: e
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
function Ni(e, t) {
|
|
846
|
+
const a = [];
|
|
815
847
|
t.forEach((s) => {
|
|
816
|
-
e.includes(s.value) &&
|
|
848
|
+
e.includes(s.value) && a.push(s);
|
|
817
849
|
});
|
|
818
|
-
const n =
|
|
819
|
-
|
|
820
|
-
const o =
|
|
850
|
+
const n = ge("weWorkListCache"), i = n.map((s) => s.value);
|
|
851
|
+
a.forEach((s) => {
|
|
852
|
+
const o = i.indexOf(s.value);
|
|
821
853
|
o > -1 ? n[o].usageCount += 1 : n.push({
|
|
822
854
|
...s,
|
|
823
855
|
usageCount: 1
|
|
824
856
|
});
|
|
825
|
-
}),
|
|
857
|
+
}), me({
|
|
826
858
|
weWorkListCache: n.sort((s, o) => o.usageCount - s.usageCount)
|
|
827
|
-
}),
|
|
859
|
+
}), oe();
|
|
828
860
|
}
|
|
829
|
-
async function
|
|
830
|
-
const t = (await
|
|
831
|
-
name: `${s.nick} - ${
|
|
861
|
+
async function dt() {
|
|
862
|
+
const t = (await ti()).filter((s) => [1, 2, 3, 4, 5].includes(s.title)).map((s) => ({
|
|
863
|
+
name: `${s.nick} - ${Yt[s.title]}`,
|
|
832
864
|
value: s.weWorkUserId
|
|
833
|
-
})),
|
|
865
|
+
})), a = ge("weWorkListCache"), n = a.map((s) => s.value), i = [];
|
|
834
866
|
return t.forEach((s) => {
|
|
835
867
|
const o = n.indexOf(s.value);
|
|
836
|
-
|
|
868
|
+
i.push({
|
|
837
869
|
...s,
|
|
838
|
-
usageCount: o > -1 ?
|
|
870
|
+
usageCount: o > -1 ? a[o].usageCount : 0
|
|
839
871
|
});
|
|
840
|
-
}),
|
|
872
|
+
}), i.sort((s, o) => o.usageCount - s.usageCount);
|
|
841
873
|
}
|
|
842
|
-
async function
|
|
843
|
-
const n = await
|
|
844
|
-
let
|
|
874
|
+
async function ft(e, t, a) {
|
|
875
|
+
const n = await dt();
|
|
876
|
+
let i = await te({
|
|
845
877
|
message: e,
|
|
846
878
|
loop: !0,
|
|
847
879
|
pageSize: n.length || 5,
|
|
848
880
|
clearInputWhenSelected: !0,
|
|
849
|
-
multiple:
|
|
881
|
+
multiple: a,
|
|
850
882
|
options: (s) => s ? n.filter((o) => o.name.includes(s)) : n,
|
|
851
883
|
validate: t
|
|
852
884
|
});
|
|
853
|
-
return
|
|
885
|
+
return i = Array.isArray(i) ? i : [i], Ni(i, n), i;
|
|
854
886
|
}
|
|
855
|
-
async function
|
|
856
|
-
const { groups: n } = await
|
|
887
|
+
async function Ai(e, t, a) {
|
|
888
|
+
const { groups: n } = await lt(), i = n.map((o) => ({
|
|
857
889
|
name: o.name,
|
|
858
890
|
value: o.url
|
|
859
891
|
}));
|
|
860
|
-
let s = await
|
|
892
|
+
let s = await te({
|
|
861
893
|
message: e,
|
|
862
894
|
loop: !0,
|
|
863
|
-
pageSize:
|
|
895
|
+
pageSize: i.length || 5,
|
|
864
896
|
clearInputWhenSelected: !0,
|
|
865
|
-
multiple:
|
|
866
|
-
options: (o) => o ?
|
|
897
|
+
multiple: a,
|
|
898
|
+
options: (o) => o ? i.filter((r) => r.name.includes(o)) : i,
|
|
867
899
|
validate: t
|
|
868
900
|
});
|
|
869
901
|
return s = Array.isArray(s) ? s : [s], s;
|
|
870
902
|
}
|
|
871
|
-
async function
|
|
903
|
+
async function bi() {
|
|
872
904
|
try {
|
|
873
|
-
|
|
905
|
+
it() && (await Ze({
|
|
874
906
|
message: "系统中已存在z的配置文件,确认重新配置?"
|
|
875
|
-
}) ? L.rm("-rf",
|
|
876
|
-
const t = await
|
|
907
|
+
}) ? L.rm("-rf", Ae()) : process.exit(0)), await pe(he(), { recursive: !0 });
|
|
908
|
+
const t = await b({
|
|
877
909
|
message: "请选择岗位类型",
|
|
878
910
|
choices: [
|
|
879
911
|
{
|
|
880
912
|
name: "前端",
|
|
881
|
-
value:
|
|
913
|
+
value: ue.FRONT_END
|
|
882
914
|
},
|
|
883
915
|
{
|
|
884
916
|
name: "后端",
|
|
885
|
-
value:
|
|
917
|
+
value: ue.BACK_END
|
|
886
918
|
},
|
|
887
919
|
{
|
|
888
920
|
name: "测试",
|
|
889
|
-
value:
|
|
921
|
+
value: ue.QUALITY_ASSURANCE
|
|
890
922
|
}
|
|
891
923
|
]
|
|
892
924
|
});
|
|
893
|
-
let
|
|
925
|
+
let a = await B({
|
|
894
926
|
message: "请输入LDAP账号:"
|
|
895
927
|
});
|
|
896
|
-
|
|
897
|
-
let n = await
|
|
928
|
+
a = a.trim();
|
|
929
|
+
let n = await Lt({
|
|
898
930
|
message: "请输入LDAP密码:",
|
|
899
931
|
mask: !0
|
|
900
932
|
});
|
|
901
|
-
n = n.trim(), M("jobType", t), M("ldapAccount",
|
|
902
|
-
const
|
|
903
|
-
|
|
904
|
-
const s = await
|
|
933
|
+
n = n.trim(), M("jobType", t), M("ldapAccount", a), M("ldapPassword", n);
|
|
934
|
+
const i = await De();
|
|
935
|
+
je(i);
|
|
936
|
+
const s = await dt(), o = await ft("请选择你自己(用于企微通知):", (u) => u.length > 1 ? "只能选一个" : u.length < 1 ? "请选一个" : !0), { name: r, value: c } = s.find((u) => u.value === o[0]);
|
|
905
937
|
M({
|
|
906
938
|
weWorkName: r,
|
|
907
939
|
weWorkUserId: c
|
|
@@ -911,44 +943,44 @@ async function ra() {
|
|
|
911
943
|
}
|
|
912
944
|
const e = y("配置信息初始化中").start();
|
|
913
945
|
try {
|
|
914
|
-
const t = await
|
|
946
|
+
const t = await Ba();
|
|
915
947
|
M({
|
|
916
948
|
gitUserId: t.id,
|
|
917
949
|
gitName: t.name,
|
|
918
950
|
gitEnglishName: t.username,
|
|
919
951
|
gitEmail: t.email
|
|
920
|
-
}),
|
|
952
|
+
}), me("latestCheckVersionTimestamp", Date.now()), oe(), E("jobType") === ue.FRONT_END && await Qa(), e.succeed("配置信息初始化完成"), process.exit(0);
|
|
921
953
|
} catch (t) {
|
|
922
|
-
e.fail("配置信息初始化失败"),
|
|
954
|
+
e.fail("配置信息初始化失败"), le.isAxiosError(t) && m("请检查你的域名及令牌配置"), m(t);
|
|
923
955
|
}
|
|
924
956
|
}
|
|
925
|
-
async function
|
|
926
|
-
await
|
|
927
|
-
`, { mode: 493 }), await
|
|
928
|
-
z run commit-msg`, { mode: 493 }), await
|
|
957
|
+
async function ji() {
|
|
958
|
+
await P(Ne(), "", { mode: 493 }), await P(R(".gitignore"), `.commit-msg-tpl
|
|
959
|
+
`, { mode: 493 }), await P(R("commit-msg"), `#!/usr/bin/env sh
|
|
960
|
+
z run commit-msg`, { mode: 493 }), await P(R("pre-commit"), `#!/usr/bin/env sh
|
|
929
961
|
z run commit-files`, { mode: 493 });
|
|
930
|
-
const { language: e } =
|
|
931
|
-
if ([w.JAVASCRIPT, w.MARKDOWN].includes(e) && (await
|
|
932
|
-
|
|
933
|
-
`${JSON.stringify(await
|
|
962
|
+
const { language: e } = ie();
|
|
963
|
+
if ([w.JAVASCRIPT, w.MARKDOWN].includes(e) && (await P(
|
|
964
|
+
R(".prettierrc.json"),
|
|
965
|
+
`${JSON.stringify(await za(), null, 2)}
|
|
934
966
|
`,
|
|
935
967
|
{
|
|
936
968
|
mode: 493
|
|
937
969
|
}
|
|
938
|
-
), await
|
|
939
|
-
await
|
|
940
|
-
const t =
|
|
941
|
-
|
|
970
|
+
), await P(R(".prettierignore"), await Ma(), { mode: 493 }), await P(R("tsconfig.node.json"), await Oa(), { mode: 493 }), await P(R("tsconfig.browser.json"), await La(), { mode: 493 })), e === w.JAVA) {
|
|
971
|
+
await Ca(`${z("FECDNDomain")}/file/vgnlfbfHRF.jar`, R("checkstyle.jar")), await P(R("checkstyle.xml"), await Ua(), { mode: 493 });
|
|
972
|
+
const t = l.join("package.json");
|
|
973
|
+
$(t) || await P(t, JSON.stringify({ version: "0.0.1" }, null, 2), {
|
|
942
974
|
mode: 493
|
|
943
975
|
});
|
|
944
976
|
}
|
|
945
|
-
|
|
977
|
+
at();
|
|
946
978
|
}
|
|
947
|
-
async function
|
|
948
|
-
const
|
|
949
|
-
|
|
979
|
+
async function Si(e, t) {
|
|
980
|
+
const a = await d("git remote get-url --push origin");
|
|
981
|
+
a || m("获取项目远程git地址失败,请配置后重试");
|
|
950
982
|
let n = e;
|
|
951
|
-
n || (n = await
|
|
983
|
+
n || (n = await b({
|
|
952
984
|
message: "请选择项目语言",
|
|
953
985
|
choices: [
|
|
954
986
|
{
|
|
@@ -969,236 +1001,236 @@ async function ca(e, t) {
|
|
|
969
1001
|
}
|
|
970
1002
|
]
|
|
971
1003
|
}));
|
|
972
|
-
let
|
|
973
|
-
if (!
|
|
974
|
-
const s =
|
|
1004
|
+
let i = t;
|
|
1005
|
+
if (!i) {
|
|
1006
|
+
const s = Q(a), o = await mt(s);
|
|
975
1007
|
if (!o)
|
|
976
|
-
return m(`未找到项目,请确认项目${
|
|
977
|
-
|
|
1008
|
+
return m(`未找到项目,请确认项目${a}是否存在,或者当前账号权限`);
|
|
1009
|
+
i = o.namespace.full_path;
|
|
978
1010
|
}
|
|
979
|
-
|
|
1011
|
+
ct({
|
|
980
1012
|
language: n,
|
|
981
|
-
"lint-staged":
|
|
1013
|
+
"lint-staged": ga[n],
|
|
982
1014
|
repository: {
|
|
983
|
-
url:
|
|
984
|
-
group:
|
|
1015
|
+
url: a,
|
|
1016
|
+
group: i
|
|
985
1017
|
}
|
|
986
1018
|
});
|
|
987
1019
|
}
|
|
988
|
-
async function
|
|
989
|
-
e ? L.rm("-rf",
|
|
990
|
-
message: `当前项目中已存在配置文件夹${
|
|
991
|
-
}) ? L.rm("-rf",
|
|
992
|
-
const
|
|
993
|
-
await
|
|
1020
|
+
async function Pe(e, t) {
|
|
1021
|
+
e ? L.rm("-rf", X) : $(R()) && (await Ze({
|
|
1022
|
+
message: `当前项目中已存在配置文件夹${X},确认重新配置?`
|
|
1023
|
+
}) ? L.rm("-rf", X) : process.exit(0)), await pe(R(), { recursive: !0 }), await Si(e, t);
|
|
1024
|
+
const a = y("项目初始化中...").start();
|
|
1025
|
+
await ji(), a.succeed("项目初始化完成");
|
|
994
1026
|
}
|
|
995
|
-
async function
|
|
996
|
-
|
|
1027
|
+
async function ki() {
|
|
1028
|
+
$(R()) && $(Ne()) ? at() : await Pe(), process.exit(0);
|
|
997
1029
|
}
|
|
998
|
-
async function
|
|
999
|
-
t.projectLanguage && !Object.values(w).includes(t.projectLanguage) && m("项目语言不支持"), e ? (
|
|
1030
|
+
async function Ti(e, t) {
|
|
1031
|
+
t.projectLanguage && !Object.values(w).includes(t.projectLanguage) && m("项目语言不支持"), e ? (Z(), e === "." ? (await Pe(t.projectLanguage, void 0), process.exit(0)) : e === "prepare" ? await ki() : m("参数错误。执行 z init -h 查看帮助。")) : await bi();
|
|
1000
1032
|
}
|
|
1001
|
-
|
|
1002
|
-
async function
|
|
1033
|
+
D.command("init").alias("i").description("初始化工具配置、项目配置").argument("[type]", "非必填。不传为初始化全局配置;传 . 为初始化当前项目;传 prepare 为初始化GIT HOOKS").option("--project-language", `项目语言。可选值:${Object.values(w).join("/")} `).action((...e) => F(Ti, ...e));
|
|
1034
|
+
async function Ei(e, t) {
|
|
1003
1035
|
if (!e)
|
|
1004
1036
|
return "不能为空";
|
|
1005
1037
|
if (!/^[a-z0-9-]+$/.test(e))
|
|
1006
1038
|
return "格式为小写字母、中横线(可选)、数字(不推荐)。如apple, apple-tree";
|
|
1007
|
-
if (
|
|
1039
|
+
if (rt().includes(e))
|
|
1008
1040
|
return "当前目录下已存在同名文件夹,请先处理。";
|
|
1009
|
-
const
|
|
1010
|
-
return
|
|
1041
|
+
const i = (await Wa(e)).find((s) => s.path_with_namespace === `${t}/${e}`);
|
|
1042
|
+
return i ? `远程仓库中已存在同名项目(${i.http_url_to_repo}),请更名后重试` : !0;
|
|
1011
1043
|
}
|
|
1012
|
-
function
|
|
1044
|
+
function Ri(e) {
|
|
1013
1045
|
return e ? !0 : "不能为空";
|
|
1014
1046
|
}
|
|
1015
|
-
function
|
|
1047
|
+
function Ii(e) {
|
|
1016
1048
|
return e ? /^[a-zA-Z0-9.]+$/.test(e) ? !0 : "格式为大小写字母、数字、小数点,小驼峰命名。如userInfo、systemRouter3" : "不能为空";
|
|
1017
1049
|
}
|
|
1018
|
-
async function
|
|
1019
|
-
ae(),
|
|
1020
|
-
let t,
|
|
1021
|
-
e.branchType ? t = e.branchType : t = await
|
|
1050
|
+
async function Ci(e) {
|
|
1051
|
+
ae(), Z(), await be();
|
|
1052
|
+
let t, a;
|
|
1053
|
+
e.branchType ? t = e.branchType : t = await b({
|
|
1022
1054
|
message: "请选择创建分支的类型",
|
|
1023
1055
|
choices: [
|
|
1024
1056
|
{
|
|
1025
1057
|
name: "开发新功能(feat)",
|
|
1026
|
-
value:
|
|
1058
|
+
value: de.FEAT
|
|
1027
1059
|
},
|
|
1028
1060
|
{
|
|
1029
1061
|
name: "修复BUG(fix)",
|
|
1030
|
-
value:
|
|
1062
|
+
value: de.FIX
|
|
1031
1063
|
},
|
|
1032
1064
|
{
|
|
1033
1065
|
name: "重构/优化代码(refactor)",
|
|
1034
|
-
value:
|
|
1066
|
+
value: de.REFACTOR
|
|
1035
1067
|
}
|
|
1036
1068
|
]
|
|
1037
|
-
}), e.branchPurpose ?
|
|
1069
|
+
}), e.branchPurpose ? a = e.branchPurpose : (a = await B({
|
|
1038
1070
|
message: "请输入创建分支的目的(大小写字母、数字,小驼峰式命名。如userInfo)",
|
|
1039
|
-
validate:
|
|
1040
|
-
}),
|
|
1041
|
-
const n = `${t}_${
|
|
1042
|
-
await
|
|
1071
|
+
validate: Ii
|
|
1072
|
+
}), a = a.trim());
|
|
1073
|
+
const n = `${t}_${a}_${ot()}`;
|
|
1074
|
+
await d(`git fetch origin ${v.MASTER}`), await d(`git checkout -b ${n} origin/${v.MASTER}`), await d(`git push -u origin ${n}`), process.exit(0);
|
|
1043
1075
|
}
|
|
1044
|
-
const
|
|
1045
|
-
async function
|
|
1076
|
+
const gt = (e) => `${z("ZenTaoDomain")}${e}`;
|
|
1077
|
+
async function xi() {
|
|
1046
1078
|
const e = await $e({
|
|
1047
|
-
url:
|
|
1079
|
+
url: gt("/my-work-task.json?tid=mrrferp8"),
|
|
1048
1080
|
method: "get"
|
|
1049
1081
|
});
|
|
1050
|
-
return e?.tasks ? e.tasks.filter((t) => t.status !== "done").map(({ id: t, name:
|
|
1082
|
+
return e?.tasks ? e.tasks.filter((t) => t.status !== "done").map(({ id: t, name: a }) => ({
|
|
1051
1083
|
value: {
|
|
1052
|
-
name:
|
|
1084
|
+
name: a,
|
|
1053
1085
|
value: t
|
|
1054
1086
|
},
|
|
1055
|
-
name:
|
|
1087
|
+
name: a
|
|
1056
1088
|
})) : [];
|
|
1057
1089
|
}
|
|
1058
|
-
async function
|
|
1090
|
+
async function Di() {
|
|
1059
1091
|
const e = await $e({
|
|
1060
|
-
url:
|
|
1092
|
+
url: gt("/my-work-bug.json?tid=mrrferp8"),
|
|
1061
1093
|
method: "get"
|
|
1062
1094
|
});
|
|
1063
|
-
return e?.bugs ? Object.values(e.bugs).map(({ id: t, title:
|
|
1064
|
-
name:
|
|
1095
|
+
return e?.bugs ? Object.values(e.bugs).map(({ id: t, title: a }) => ({
|
|
1096
|
+
name: a,
|
|
1065
1097
|
value: {
|
|
1066
|
-
name:
|
|
1098
|
+
name: a,
|
|
1067
1099
|
value: t
|
|
1068
1100
|
}
|
|
1069
1101
|
})) : [];
|
|
1070
1102
|
}
|
|
1071
|
-
async function
|
|
1072
|
-
const t = await
|
|
1103
|
+
async function We(e) {
|
|
1104
|
+
const t = await d(`
|
|
1073
1105
|
git diff --name-only HEAD | while read file; do
|
|
1074
|
-
if [ -f "$file" ] && [ $(stat -f%z "$file") -lt ${
|
|
1106
|
+
if [ -f "$file" ] && [ $(stat -f%z "$file") -lt ${ta} ]; then
|
|
1075
1107
|
echo "$file"
|
|
1076
1108
|
fi
|
|
1077
1109
|
done | xargs git diff HEAD --
|
|
1078
1110
|
`);
|
|
1079
1111
|
t || m("git暂存区没有内容,请先git add添加文件到暂存区");
|
|
1080
|
-
const
|
|
1112
|
+
const a = await vi({
|
|
1081
1113
|
type: "commit-message-v2",
|
|
1082
1114
|
input: t
|
|
1083
1115
|
// modelName: "qwen-turbo",
|
|
1084
1116
|
});
|
|
1085
|
-
return e +
|
|
1117
|
+
return e + a;
|
|
1086
1118
|
}
|
|
1087
|
-
async function
|
|
1119
|
+
async function Ee(e, t, a) {
|
|
1088
1120
|
const n = y("🤖 生成提交信息中...").start();
|
|
1089
|
-
let
|
|
1090
|
-
if ([
|
|
1121
|
+
let i = "", s = !0;
|
|
1122
|
+
if ([S.FEAT, S.FIX, S.REFACTOR].includes(e)) {
|
|
1091
1123
|
const o = t.map((r) => r.value).join(",");
|
|
1092
|
-
if (
|
|
1124
|
+
if (a || (i = await We(`${e}(${o}): `)), !i) {
|
|
1093
1125
|
const r = t.map((c) => c.name).join(";");
|
|
1094
|
-
|
|
1126
|
+
i = `${e}(${o}): ${r}`, s = !1;
|
|
1095
1127
|
}
|
|
1096
1128
|
}
|
|
1097
|
-
e ===
|
|
1129
|
+
e === S.CHORE && (t ? i = `${e}: ${t}` : i = await We(`${e}: `)), await P(Ne(), i, "utf-8"), s || a ? n.succeed("提交信息已生成(↓),可以进行提交了!") : n.warn("AI生成提交信息失败,已使用默认模板(↓),可以进行提交了!"), console.log(A.yellow(i));
|
|
1098
1130
|
}
|
|
1099
|
-
async function
|
|
1100
|
-
const t = await
|
|
1131
|
+
async function Pi(e) {
|
|
1132
|
+
const t = await b({
|
|
1101
1133
|
message: "请选择你要创建的模板类型",
|
|
1102
1134
|
choices: [
|
|
1103
1135
|
{
|
|
1104
1136
|
name: "feat - 业务需求/功能开发/BUG修复",
|
|
1105
|
-
value:
|
|
1137
|
+
value: S.FEAT
|
|
1106
1138
|
},
|
|
1107
1139
|
{
|
|
1108
1140
|
name: "fix - bug修复",
|
|
1109
|
-
value:
|
|
1141
|
+
value: S.FIX
|
|
1110
1142
|
},
|
|
1111
1143
|
{
|
|
1112
1144
|
name: "refactor - 技术重构/性能优化/代码规范",
|
|
1113
|
-
value:
|
|
1145
|
+
value: S.REFACTOR
|
|
1114
1146
|
},
|
|
1115
1147
|
{
|
|
1116
1148
|
name: "chore - 其他",
|
|
1117
|
-
value:
|
|
1149
|
+
value: S.CHORE
|
|
1118
1150
|
}
|
|
1119
1151
|
]
|
|
1120
1152
|
});
|
|
1121
|
-
if ([
|
|
1122
|
-
const
|
|
1123
|
-
if (!
|
|
1153
|
+
if ([S.FEAT, S.REFACTOR].includes(t)) {
|
|
1154
|
+
const a = await xi();
|
|
1155
|
+
if (!a.length)
|
|
1124
1156
|
return V("🤷 暂无开发任务");
|
|
1125
|
-
const n = await
|
|
1157
|
+
const n = await ve({
|
|
1126
1158
|
message: "请关联开发任务(可多选):",
|
|
1127
|
-
validate: (
|
|
1128
|
-
choices:
|
|
1129
|
-
...
|
|
1130
|
-
name: `[${
|
|
1159
|
+
validate: (i) => i.length === 0 ? "请选择项" : !0,
|
|
1160
|
+
choices: a.map((i) => ({
|
|
1161
|
+
...i,
|
|
1162
|
+
name: `[${i.value.value}]: ${i.name}`
|
|
1131
1163
|
})),
|
|
1132
|
-
pageSize:
|
|
1164
|
+
pageSize: a.length
|
|
1133
1165
|
});
|
|
1134
|
-
await
|
|
1166
|
+
await Ee(S.FEAT, n, e);
|
|
1135
1167
|
}
|
|
1136
|
-
if (t ===
|
|
1137
|
-
const
|
|
1138
|
-
if (!
|
|
1168
|
+
if (t === S.FIX) {
|
|
1169
|
+
const a = await Di();
|
|
1170
|
+
if (!a.length)
|
|
1139
1171
|
return V("🤷 暂无BUG");
|
|
1140
|
-
const n = await
|
|
1172
|
+
const n = await ve({
|
|
1141
1173
|
message: "请关联Bug(可多选):",
|
|
1142
|
-
validate: (
|
|
1143
|
-
choices:
|
|
1144
|
-
...
|
|
1145
|
-
name: `[${
|
|
1174
|
+
validate: (i) => i.length === 0 ? "请选择项" : !0,
|
|
1175
|
+
choices: a.map((i) => ({
|
|
1176
|
+
...i,
|
|
1177
|
+
name: `[${i.value.value}]: ${i.name}`
|
|
1146
1178
|
})),
|
|
1147
|
-
pageSize:
|
|
1179
|
+
pageSize: a.length
|
|
1148
1180
|
});
|
|
1149
|
-
await
|
|
1181
|
+
await Ee(S.FIX, n, e);
|
|
1150
1182
|
}
|
|
1151
|
-
if (t ===
|
|
1152
|
-
let
|
|
1153
|
-
e && (
|
|
1183
|
+
if (t === S.CHORE) {
|
|
1184
|
+
let a = "";
|
|
1185
|
+
e && (a = await B({
|
|
1154
1186
|
message: "请输入commit msg:",
|
|
1155
1187
|
validate: (n) => n.length === 0 ? "请输入commit msg" : !0
|
|
1156
|
-
}),
|
|
1188
|
+
}), a = a.trim()), await Ee(S.CHORE, a);
|
|
1157
1189
|
}
|
|
1158
1190
|
process.exit(0);
|
|
1159
1191
|
}
|
|
1160
|
-
async function
|
|
1192
|
+
async function Li() {
|
|
1161
1193
|
try {
|
|
1162
1194
|
const e = {}, t = async () => {
|
|
1163
|
-
const
|
|
1164
|
-
const
|
|
1165
|
-
name: `${
|
|
1166
|
-
value:
|
|
1195
|
+
const O = rt(), { projects: se } = await xa(), K = se.map((ce) => {
|
|
1196
|
+
const Fe = {
|
|
1197
|
+
name: `${ce.name} [${ce.desc}]`,
|
|
1198
|
+
value: ce.name,
|
|
1167
1199
|
disabled: !1
|
|
1168
1200
|
};
|
|
1169
|
-
return
|
|
1170
|
-
}),
|
|
1201
|
+
return O.includes(ce.name) && (Fe.disabled = "目录下已存在同名文件夹"), Fe;
|
|
1202
|
+
}), St = await b({
|
|
1171
1203
|
message: "请选择一个项目模板",
|
|
1172
|
-
choices:
|
|
1173
|
-
}),
|
|
1174
|
-
e.tplName =
|
|
1175
|
-
},
|
|
1176
|
-
const { groups:
|
|
1204
|
+
choices: K
|
|
1205
|
+
}), Te = se.find((ce) => ce.name === St);
|
|
1206
|
+
e.tplName = Te.name, e.tplUrl = Te.url, e.tplLanguage = Te.language;
|
|
1207
|
+
}, a = async () => {
|
|
1208
|
+
const { groups: O } = Xa(), se = await b({
|
|
1177
1209
|
message: "请选择一个分组",
|
|
1178
|
-
choices:
|
|
1179
|
-
name: `${
|
|
1180
|
-
value:
|
|
1181
|
-
short:
|
|
1210
|
+
choices: O.map((K) => ({
|
|
1211
|
+
name: `${K.name} [${K.description}]`,
|
|
1212
|
+
value: K.id,
|
|
1213
|
+
short: K.name
|
|
1182
1214
|
}))
|
|
1183
1215
|
});
|
|
1184
1216
|
e.group = {
|
|
1185
|
-
id:
|
|
1186
|
-
name:
|
|
1217
|
+
id: se,
|
|
1218
|
+
name: O.find((K) => K.id === se)?.name
|
|
1187
1219
|
};
|
|
1188
1220
|
}, n = async () => {
|
|
1189
|
-
e.projectName = await
|
|
1221
|
+
e.projectName = await B({
|
|
1190
1222
|
message: "请输入项目名称",
|
|
1191
|
-
validate: (
|
|
1192
|
-
}), e.projectName = e.projectName.trim(), e.projectDesc = await
|
|
1223
|
+
validate: (O) => Ei(O, e.group?.name || "")
|
|
1224
|
+
}), e.projectName = e.projectName.trim(), e.projectDesc = await B({
|
|
1193
1225
|
message: "请输入项目描述",
|
|
1194
|
-
validate:
|
|
1226
|
+
validate: Ri
|
|
1195
1227
|
}), e.projectDesc = e.projectDesc.trim();
|
|
1196
1228
|
};
|
|
1197
|
-
await t(), await
|
|
1198
|
-
const
|
|
1199
|
-
await
|
|
1229
|
+
await t(), await a(), await n();
|
|
1230
|
+
const i = `${fe}/${e.group?.name}/${e.projectName}.git`, s = y("模版初始化中").start();
|
|
1231
|
+
await d(`git clone --depth=1 ${e.tplUrl}`), await qe(e.tplName, e.projectName), L.cd(e.projectName), L.rm("-rf", ".git"), await d(`git init --initial-branch=${v.MASTER}`), await d(`git remote add origin ${i}`), await d(`git config user.name ${E("gitName")}`), await d(`git config user.email ${E("gitEmail")}`);
|
|
1200
1232
|
const o = xe();
|
|
1201
|
-
|
|
1233
|
+
ka({
|
|
1202
1234
|
...o,
|
|
1203
1235
|
name: e.projectName,
|
|
1204
1236
|
description: e.projectDesc,
|
|
@@ -1206,52 +1238,52 @@ async function ya() {
|
|
|
1206
1238
|
...o.scripts,
|
|
1207
1239
|
prepare: "[ -n '$z' ] && z init prepare || echo 'Warning: z not exist at global'"
|
|
1208
1240
|
}
|
|
1209
|
-
}), await
|
|
1241
|
+
}), await C.writeFile(l.resolve("README.md"), fa(e.projectName, e.projectDesc)), s.succeed("模版初始化完成"), await Pe(e.tplLanguage, e.group?.name);
|
|
1210
1242
|
const r = y("依赖安装中").start();
|
|
1211
|
-
await
|
|
1243
|
+
await d("npm install --registry https://registry.npmmirror.com/"), r.succeed("依赖安装完成");
|
|
1212
1244
|
const c = y("项目推送中").start();
|
|
1213
|
-
await
|
|
1214
|
-
const u = await
|
|
1245
|
+
await d('git add . && git commit -m "chore: 项目初始化"'), await d("git tag v0.0.1");
|
|
1246
|
+
const u = await Ga({
|
|
1215
1247
|
name: e.projectName,
|
|
1216
1248
|
description: e.projectDesc,
|
|
1217
1249
|
path: e.projectName,
|
|
1218
1250
|
visibility: "private",
|
|
1219
1251
|
namespace_id: e.group?.id
|
|
1220
1252
|
});
|
|
1221
|
-
await
|
|
1222
|
-
const
|
|
1223
|
-
|
|
1224
|
-
(
|
|
1253
|
+
await d(`git push -u origin ${v.MASTER}`), await d(`git push origin HEAD:${v.MASTER} --tags`), c.succeed(`项目已推送到远程,地址: ${A.blue(i)}`);
|
|
1254
|
+
const p = y("初始化分支中").start(), g = `feat_init_${ot()}`, f = [v.DEV, v.TEST, v.RELEASE, g], h = await Promise.allSettled(
|
|
1255
|
+
f.map(
|
|
1256
|
+
(O) => Ka({
|
|
1225
1257
|
id: u.id,
|
|
1226
|
-
branch:
|
|
1227
|
-
ref:
|
|
1258
|
+
branch: O,
|
|
1259
|
+
ref: v.MASTER
|
|
1228
1260
|
})
|
|
1229
1261
|
)
|
|
1230
|
-
),
|
|
1231
|
-
h.forEach(({ status:
|
|
1232
|
-
|
|
1233
|
-
}), await
|
|
1234
|
-
const
|
|
1235
|
-
console.log(`输入 ${
|
|
1262
|
+
), T = [];
|
|
1263
|
+
h.forEach(({ status: O }, se) => {
|
|
1264
|
+
O === "fulfilled" && T.push(f[se]);
|
|
1265
|
+
}), await d("git pull"), T.includes(g) ? (await d(`git checkout -b ${g} origin/${g}`), p.succeed(`项目已切换到初始分支: ${A.blue(g)}`)) : p.warn("开发分支检出失败!项目当前在主分支,请自行检出开发分支。");
|
|
1266
|
+
const ne = `cd ${e.projectName} && z start`;
|
|
1267
|
+
console.log(`输入 ${A.green(ne)} 开始开发吧~`), process.exit(0);
|
|
1236
1268
|
} catch (e) {
|
|
1237
1269
|
m(e);
|
|
1238
1270
|
}
|
|
1239
1271
|
}
|
|
1240
|
-
async function
|
|
1241
|
-
let
|
|
1272
|
+
async function Oi(e, t) {
|
|
1273
|
+
let a;
|
|
1242
1274
|
e ? [
|
|
1243
1275
|
"project",
|
|
1244
1276
|
"pr"
|
|
1245
1277
|
/* ProjectAbbr */
|
|
1246
|
-
].includes(e) ?
|
|
1278
|
+
].includes(e) ? a = "project" : [
|
|
1247
1279
|
"branch",
|
|
1248
1280
|
"b"
|
|
1249
1281
|
/* BranchAbbr */
|
|
1250
|
-
].includes(e) ?
|
|
1282
|
+
].includes(e) ? a = "branch" : [
|
|
1251
1283
|
"commit-msg",
|
|
1252
1284
|
"cm"
|
|
1253
1285
|
/* CommitMsgAbbr */
|
|
1254
|
-
].includes(e) ?
|
|
1286
|
+
].includes(e) ? a = "commit-msg" : m("参数输入错误") : a = await b({
|
|
1255
1287
|
message: "请选择你要创建的类型",
|
|
1256
1288
|
choices: [
|
|
1257
1289
|
{
|
|
@@ -1270,22 +1302,22 @@ async function $a(e, t) {
|
|
|
1270
1302
|
/* Project */
|
|
1271
1303
|
}
|
|
1272
1304
|
]
|
|
1273
|
-
}),
|
|
1305
|
+
}), a === "project" ? await Li() : (ae(), Z(), a === "branch" ? await Ci(t) : a === "commit-msg" && (await d("git status -s") ? await Pi(t.commitMessageCloseAi) : m("没有要变动的文件,无法生成提交信息")));
|
|
1274
1306
|
}
|
|
1275
|
-
|
|
1276
|
-
function
|
|
1277
|
-
return
|
|
1278
|
-
url: `${
|
|
1307
|
+
D.command("create").alias("c").description("创建项目/分支/提交信息").argument("[type]", "可选值为project|pr, branch|b, commit-msg|cm").option("--branch-type <type>", `分支类型。可选值:${Object.values(de).join(", ")}`).option("--branch-purpose <purpose>", "创建分支的目的").option("--commit-message-close-ai", "创建提交信息时,是否关闭AI生成").action((...e) => F(Oi, ...e));
|
|
1308
|
+
function Mi(e) {
|
|
1309
|
+
return ut({
|
|
1310
|
+
url: `${z("K8sDomain")}/kapis/clusters/youshou-local/devops.kubesphere.io/v1alpha3/namespaces/${e.groupName}/pipelines/${e.projectName}/pipelineruns?branch=${e.branchName}`,
|
|
1279
1311
|
method: "post",
|
|
1280
1312
|
data: e.params
|
|
1281
1313
|
});
|
|
1282
1314
|
}
|
|
1283
|
-
async function
|
|
1284
|
-
const t = y("部署任务创建中").start(), { targetBranch:
|
|
1315
|
+
async function zi(e) {
|
|
1316
|
+
const t = y("部署任务创建中").start(), { targetBranch: a, notify: n, projectName: i } = e, s = n ? [.../* @__PURE__ */ new Set([E("weWorkUserId"), ...n])] : [E("weWorkUserId")];
|
|
1285
1317
|
try {
|
|
1286
|
-
const { metadata: o, spec: r } = await
|
|
1287
|
-
projectName:
|
|
1288
|
-
branchName:
|
|
1318
|
+
const { metadata: o, spec: r } = await Mi({
|
|
1319
|
+
projectName: i,
|
|
1320
|
+
branchName: a,
|
|
1289
1321
|
groupName: e.groupName,
|
|
1290
1322
|
params: {
|
|
1291
1323
|
parameters: [
|
|
@@ -1299,228 +1331,228 @@ async function Na(e) {
|
|
|
1299
1331
|
}
|
|
1300
1332
|
]
|
|
1301
1333
|
}
|
|
1302
|
-
}), c = `${
|
|
1303
|
-
t.succeed("部署任务创建完成"), console.log(`如有需要,可在k8s中查看 ${
|
|
1334
|
+
}), c = `${z("K8SWebDomain")}/youshou-local/clusters/youshou-local/devops/${o.namespace}/pipelines/${r.pipelineRef.name}/branch/${r.scm.refName}/run/${o.name}/task-status`;
|
|
1335
|
+
t.succeed("部署任务创建完成"), console.log(`如有需要,可在k8s中查看 ${A.blue(c)}`), process.exit(0);
|
|
1304
1336
|
} catch (o) {
|
|
1305
1337
|
t.fail("部署任务创建失败"), m(o);
|
|
1306
1338
|
}
|
|
1307
1339
|
}
|
|
1308
|
-
function
|
|
1309
|
-
const
|
|
1310
|
-
if (
|
|
1311
|
-
const
|
|
1312
|
-
|
|
1340
|
+
function Fi(e, t) {
|
|
1341
|
+
const a = xe();
|
|
1342
|
+
if (ie()?.repository?.url || m(".z/project.json中缺少repository.url"), t === W.H5) {
|
|
1343
|
+
const i = `build:${e}`;
|
|
1344
|
+
a?.scripts[i] || m(`项目package.json文件scripts不存在命令${i}。`);
|
|
1313
1345
|
}
|
|
1314
|
-
t === W.NPM && (
|
|
1346
|
+
t === W.NPM && (a?.scripts.build || m("项目package.json文件scripts不存在命令build。")), t === W.SERVER && (a?.scripts.build || m("项目package.json文件scripts不存在命令build。"));
|
|
1315
1347
|
}
|
|
1316
|
-
async function
|
|
1317
|
-
ae(),
|
|
1318
|
-
let
|
|
1319
|
-
const
|
|
1320
|
-
if (
|
|
1348
|
+
async function ht(e, t) {
|
|
1349
|
+
ae(), Z();
|
|
1350
|
+
let a = e, n = t.platform;
|
|
1351
|
+
const i = ie();
|
|
1352
|
+
if (i.language === w.JAVA && (n = W.SERVER), a && !Object.values(v).includes(a) && m("仅支持发布指定环境分支"), n && !Object.values(W).includes(n) && m("发布平台错误"), n || (n = await b({
|
|
1321
1353
|
message: "请选择平台",
|
|
1322
|
-
choices:
|
|
1323
|
-
})), n === W.NPM && (
|
|
1324
|
-
const u = await
|
|
1354
|
+
choices: Kt
|
|
1355
|
+
})), n === W.NPM && (a = v.MASTER), !a) {
|
|
1356
|
+
const u = await b({
|
|
1325
1357
|
message: "请选择部署环境",
|
|
1326
|
-
choices:
|
|
1358
|
+
choices: Qe
|
|
1327
1359
|
});
|
|
1328
|
-
|
|
1360
|
+
a = pa(u);
|
|
1329
1361
|
}
|
|
1330
1362
|
let s = "";
|
|
1331
|
-
|
|
1363
|
+
i.language === w.JAVASCRIPT && (s = Qt);
|
|
1332
1364
|
let o = "";
|
|
1333
|
-
if (
|
|
1365
|
+
if (i.language === w.JAVASCRIPT) {
|
|
1334
1366
|
const u = xe();
|
|
1335
1367
|
u.name.startsWith("@") && u.name.includes("/") ? o = u.name.split("/").pop() || "" : o = u.name;
|
|
1336
1368
|
}
|
|
1337
|
-
if (
|
|
1338
|
-
const { projects: u } = await
|
|
1339
|
-
(
|
|
1369
|
+
if (i.language === w.JAVA) {
|
|
1370
|
+
const { projects: u } = await Da(), p = u.find(
|
|
1371
|
+
(g) => Q(g.url) === Q(i.repository.url)
|
|
1340
1372
|
);
|
|
1341
|
-
if (!
|
|
1373
|
+
if (!p)
|
|
1342
1374
|
m("未找到项目对应的模块信息");
|
|
1343
1375
|
else {
|
|
1344
|
-
s =
|
|
1345
|
-
const
|
|
1346
|
-
name: `${
|
|
1347
|
-
value:
|
|
1376
|
+
s = p["k8s-group-name"];
|
|
1377
|
+
const g = p.modules.map(({ name: f, desc: h }) => ({
|
|
1378
|
+
name: `${f} (${h})`,
|
|
1379
|
+
value: f
|
|
1348
1380
|
}));
|
|
1349
1381
|
if (t.module) {
|
|
1350
|
-
const
|
|
1351
|
-
|
|
1382
|
+
const f = g.find((h) => h.value === t.module);
|
|
1383
|
+
f && (o = f.value);
|
|
1352
1384
|
}
|
|
1353
|
-
o = await
|
|
1385
|
+
o = await b({
|
|
1354
1386
|
message: "请选择部署模块",
|
|
1355
|
-
choices:
|
|
1387
|
+
choices: g
|
|
1356
1388
|
});
|
|
1357
1389
|
}
|
|
1358
1390
|
}
|
|
1359
1391
|
let r = [];
|
|
1360
|
-
t.skipSelectionNotification || (r = await
|
|
1392
|
+
t.skipSelectionNotification || (r = await ft("请选择部署成功要通知的人员:", () => !0, !0));
|
|
1361
1393
|
let c = [];
|
|
1362
|
-
if (t.skipGroupNotification || (c = await
|
|
1363
|
-
const u =
|
|
1364
|
-
|
|
1394
|
+
if (t.skipGroupNotification || (c = await Ai("请选择部署成功要通知的群组:", () => !0, !0)), i.language === w.JAVASCRIPT) {
|
|
1395
|
+
const u = ma(a);
|
|
1396
|
+
Fi(u, n);
|
|
1365
1397
|
}
|
|
1366
|
-
await
|
|
1398
|
+
await zi({
|
|
1367
1399
|
projectName: o,
|
|
1368
1400
|
groupName: s,
|
|
1369
|
-
targetBranch:
|
|
1401
|
+
targetBranch: a,
|
|
1370
1402
|
notify: r,
|
|
1371
1403
|
notifyGroup: c
|
|
1372
1404
|
});
|
|
1373
1405
|
}
|
|
1374
|
-
async function
|
|
1375
|
-
const
|
|
1406
|
+
async function wt(e, t, a, n) {
|
|
1407
|
+
const i = y(`分支合并中,${e} -> ${t}`).start();
|
|
1376
1408
|
let s = 0;
|
|
1377
1409
|
try {
|
|
1378
|
-
const { iid: r } = await
|
|
1410
|
+
const { iid: r } = await Va({
|
|
1379
1411
|
title: `${e} -> ${t} by z-develop`,
|
|
1380
|
-
id:
|
|
1412
|
+
id: a.id,
|
|
1381
1413
|
source_branch: e,
|
|
1382
1414
|
target_branch: t,
|
|
1383
1415
|
// 合到主分支上的分支需要在合并完成后被移除
|
|
1384
|
-
remove_source_branch: n ? !1 :
|
|
1416
|
+
remove_source_branch: n ? !1 : v.MASTER === t
|
|
1385
1417
|
});
|
|
1386
1418
|
s = r;
|
|
1387
1419
|
} catch (r) {
|
|
1388
|
-
|
|
1420
|
+
le.isAxiosError(r) && r?.response?.status === 409 && m(`存在重复的合并请求,前往查看${a.mergeRequestUrl}`), m(r);
|
|
1389
1421
|
}
|
|
1390
1422
|
const o = async () => {
|
|
1391
1423
|
try {
|
|
1392
1424
|
await new Promise((r) => {
|
|
1393
1425
|
setTimeout(r, 5e3);
|
|
1394
|
-
}), await
|
|
1395
|
-
id:
|
|
1426
|
+
}), await qa({
|
|
1427
|
+
id: a.id,
|
|
1396
1428
|
iid: s
|
|
1397
|
-
}),
|
|
1429
|
+
}), i.succeed(`分支${e}已合并到分支${t}`);
|
|
1398
1430
|
} catch (r) {
|
|
1399
|
-
|
|
1431
|
+
le.isAxiosError(r) || m(r);
|
|
1400
1432
|
const c = r?.response?.status;
|
|
1401
1433
|
if (c === 406)
|
|
1402
1434
|
return await o();
|
|
1403
|
-
if (await
|
|
1404
|
-
id:
|
|
1435
|
+
if (await Za({
|
|
1436
|
+
id: a.id,
|
|
1405
1437
|
iid: s,
|
|
1406
1438
|
state_event: "close"
|
|
1407
1439
|
}), c === 405) {
|
|
1408
|
-
const u = await
|
|
1409
|
-
id:
|
|
1440
|
+
const u = await Ha({
|
|
1441
|
+
id: a.id,
|
|
1410
1442
|
iid: s
|
|
1411
1443
|
});
|
|
1412
1444
|
if (u.merge_status === "cannot_be_merged" && u.diff_refs.base_sha === u.diff_refs.head_sha) {
|
|
1413
|
-
|
|
1445
|
+
i.warn("MR已关闭。判定为空的合并请求(没有新内容),可继续进行部署");
|
|
1414
1446
|
return;
|
|
1415
1447
|
}
|
|
1416
1448
|
}
|
|
1417
|
-
|
|
1449
|
+
i.fail("合并过程中出现冲突,MR已关闭。建议在本地完成合并。"), process.exit(1);
|
|
1418
1450
|
}
|
|
1419
1451
|
};
|
|
1420
1452
|
await o();
|
|
1421
1453
|
}
|
|
1422
|
-
async function
|
|
1423
|
-
const
|
|
1424
|
-
`git log ${n}...${
|
|
1454
|
+
async function Ji(e, t) {
|
|
1455
|
+
const a = `origin/${e.sourceBranch}`, n = await d(`git log -b origin/${v.MASTER} -1 --format=%H`), i = await d(`git log -b origin/${e.sourceBranch} -1 --format=%H`), s = await d(
|
|
1456
|
+
`git log ${n}...${i} -b ${a}`
|
|
1425
1457
|
);
|
|
1426
|
-
if (s || m(`分支${e.sourceBranch}上不存在新的commit,不需要合并。`), await
|
|
1427
|
-
`git branch --contains ${n} -r ${
|
|
1428
|
-
) || (console.log(
|
|
1458
|
+
if (s || m(`分支${e.sourceBranch}上不存在新的commit,不需要合并。`), await d(
|
|
1459
|
+
`git branch --contains ${n} -r ${a}`
|
|
1460
|
+
) || (console.log(A.yellow("注意:当前分支上不存在远程主分支最新代码,将在自动合入后继续。")), await wt(v.MASTER, e.sourceBranch, e)), t === v.MASTER) {
|
|
1429
1461
|
const r = s.split(`
|
|
1430
|
-
`).filter((
|
|
1431
|
-
`git log ${n}...${c} -b origin/${
|
|
1462
|
+
`).filter((g) => g), c = await d(`git log -b origin/${k.TEST} -1 --format=%H`), p = (await d(
|
|
1463
|
+
`git log ${n}...${c} -b origin/${k.TEST}`
|
|
1432
1464
|
)).split(`
|
|
1433
|
-
`).filter((
|
|
1434
|
-
|
|
1465
|
+
`).filter((g) => g);
|
|
1466
|
+
la(p, r) || m("请先在测试环境发布要部署的代码");
|
|
1435
1467
|
}
|
|
1436
1468
|
}
|
|
1437
|
-
async function
|
|
1438
|
-
ae(),
|
|
1439
|
-
const
|
|
1440
|
-
Object.values(
|
|
1441
|
-
const
|
|
1469
|
+
async function Ui(e, t) {
|
|
1470
|
+
ae(), Z(), await be();
|
|
1471
|
+
const a = await Ta();
|
|
1472
|
+
Object.values(v).includes(a.sourceBranch) && m(`当前分支${a.sourceBranch}不可作为源分支合并到目标分支。`);
|
|
1473
|
+
const i = (await Ya(a.id)).filter((c) => ![a.sourceBranch].includes(c.name)).map((c) => {
|
|
1442
1474
|
let u = c.name;
|
|
1443
|
-
return Object.values(
|
|
1475
|
+
return Object.values(v).includes(u) && (u = A.bold.blue(u)), {
|
|
1444
1476
|
name: u,
|
|
1445
1477
|
value: c.name
|
|
1446
1478
|
};
|
|
1447
1479
|
});
|
|
1448
1480
|
let s;
|
|
1449
|
-
e && !
|
|
1481
|
+
e && !i.filter((c) => c.value === e).length && m(`未找到目标分支${e}`), e ? s = e : s = await b({
|
|
1450
1482
|
message: "请选择要合并到的目标分支:",
|
|
1451
|
-
choices:
|
|
1452
|
-
});
|
|
1453
|
-
const o = y(`本地分支${
|
|
1454
|
-
if (await
|
|
1455
|
-
o.text = `存在远程分支origin/${
|
|
1456
|
-
const c = await
|
|
1457
|
-
await
|
|
1458
|
-
`远程分支origin/${
|
|
1483
|
+
choices: i
|
|
1484
|
+
});
|
|
1485
|
+
const o = y(`本地分支${a.sourceBranch}检测中`).start();
|
|
1486
|
+
if (await d(`git ls-remote --heads origin ${a.sourceBranch}`)) {
|
|
1487
|
+
o.text = `存在远程分支origin/${a.sourceBranch}`, await d("git fetch");
|
|
1488
|
+
const c = await d(`git rev-parse ${a.sourceBranch}`), u = await d(`git rev-parse origin/${a.sourceBranch}`);
|
|
1489
|
+
await d(`git merge-base ${u} HEAD`) === u ? (await d(`git push -u origin ${a.sourceBranch}`), o.succeed(`本地分支${a.sourceBranch}已推送到远程分支origin/${a.sourceBranch}`)) : await d(`git merge-base ${c} ${u}`) === c ? (await d("git pull"), o.succeed(`本地分支${a.sourceBranch}已更新`)) : (o.fail(
|
|
1490
|
+
`远程分支origin/${a.sourceBranch}和本地分支${a.sourceBranch}都有新的提交,请手动合并后再试。`
|
|
1459
1491
|
), process.exit(1));
|
|
1460
1492
|
} else
|
|
1461
|
-
await
|
|
1462
|
-
await
|
|
1463
|
-
`${
|
|
1464
|
-
)), Object.values(
|
|
1493
|
+
await d(`git push -u origin ${a.sourceBranch}`), o.succeed(`本地分支${a.sourceBranch}已推送到远程分支origin/${a.sourceBranch}`);
|
|
1494
|
+
await Ji(a, s), await wt(a.sourceBranch, s, a, t.keepBranchAfterMergeMaster), v.MASTER === s && !t.keepBranchAfterMergeMaster && (await d(`git checkout ${v.MASTER}`), await d(`git pull origin ${v.MASTER}`), await d(`git branch -d ${a.sourceBranch}`), V(
|
|
1495
|
+
`${a.sourceBranch}分支已移除,当前已切换到最新的${v.MASTER}。如需继续开发,请检出新分支(z c b)。`
|
|
1496
|
+
)), Object.values(v).includes(s) && await ht(s, {
|
|
1465
1497
|
platform: t.deployPlatform,
|
|
1466
1498
|
skipSelectionNotification: t.deploySkipSelectionNotification,
|
|
1467
1499
|
skipGroupNotification: t.skipGroupNotification
|
|
1468
1500
|
});
|
|
1469
1501
|
}
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
async function
|
|
1502
|
+
D.command("merge").alias("m").description("合并当前分支到指定远程分支,并部署。").argument("[branch]", "目标分支名称").option("--deploy-platform <platform>", `合并成功后要部署的平台。可选值:${Object.values(W).join("/")}`).option("--deploy-skip-selection-notification", "部署时,是否跳过选择部署通知人环节").option("--skip-group-notification", "是否跳过选择部署通知群聊环节").option("--keep-branch-after-merge-master", "在合并到主分支之后,是否保留分支。默认否").action((...e) => F(Ui, ...e));
|
|
1503
|
+
D.command("deploy").alias("d").description("部署到指定环境").argument("[branchName]", `部署环境。可选值:${Object.values(v).join("/")}`).option("--platform <platform>", `部署平台。可选值:${Object.values(W).join("/")}`).option("--module <module>", "部署模块。Java项目适用,填入要部署的模块名称").option("--skip-selection-notification", "是否跳过选择部署通知人环节").option("--skip-group-notification", "是否跳过选择部署通知群聊环节").action((...e) => F(ht, ...e));
|
|
1504
|
+
async function Bi() {
|
|
1473
1505
|
try {
|
|
1474
|
-
await
|
|
1506
|
+
await d("java -jar ./.z/checkstyle.jar -c ./.z/checkstyle.xml .", {
|
|
1475
1507
|
silent: !1
|
|
1476
1508
|
}), V("checkstyle执行完毕"), process.exit(0);
|
|
1477
1509
|
} catch {
|
|
1478
1510
|
m("checkstyle执行出错"), process.exit(1);
|
|
1479
1511
|
}
|
|
1480
1512
|
}
|
|
1481
|
-
async function
|
|
1482
|
-
|
|
1513
|
+
async function _i() {
|
|
1514
|
+
$(l.resolve("node_modules", ".bin", "markdownlint")) || m("该项目未安装markdownlint,请安装后重试");
|
|
1483
1515
|
const e = y("markdownlint执行中...").start();
|
|
1484
1516
|
try {
|
|
1485
|
-
await
|
|
1517
|
+
await d('npx markdownlint "**/*.md" --fix', {
|
|
1486
1518
|
silent: !1
|
|
1487
1519
|
}), e.succeed("markdownlint执行成功"), process.exit(0);
|
|
1488
1520
|
} catch {
|
|
1489
1521
|
e.fail("markdownlint校验出错"), process.exit(1);
|
|
1490
1522
|
}
|
|
1491
1523
|
}
|
|
1492
|
-
function
|
|
1493
|
-
const e =
|
|
1524
|
+
function Gi() {
|
|
1525
|
+
const e = ie();
|
|
1494
1526
|
if (e["lint-staged"])
|
|
1495
1527
|
return e["lint-staged"];
|
|
1496
1528
|
throw new Error("未找到lint配置");
|
|
1497
1529
|
}
|
|
1498
|
-
async function
|
|
1530
|
+
async function Wi() {
|
|
1499
1531
|
const e = y("代码风格检测中...").start();
|
|
1500
|
-
await
|
|
1532
|
+
await Ot({
|
|
1501
1533
|
concurrent: 4,
|
|
1502
1534
|
debug: !1,
|
|
1503
|
-
config:
|
|
1535
|
+
config: Gi(),
|
|
1504
1536
|
quiet: !0,
|
|
1505
1537
|
relative: !0
|
|
1506
1538
|
}) ? (e.succeed("代码风格检测通过!"), process.exit(0)) : (e.fail("代码风格检测未通过!"), process.exit(1));
|
|
1507
1539
|
}
|
|
1508
|
-
function
|
|
1509
|
-
if (e.includes("Merge") && e.includes("# Conflicts:") ||
|
|
1540
|
+
function Vi(e) {
|
|
1541
|
+
if (e.includes("Merge") && e.includes("# Conflicts:") || Mt.valid(e))
|
|
1510
1542
|
return !0;
|
|
1511
1543
|
const t = e.split(": ");
|
|
1512
1544
|
if (t.length === 1)
|
|
1513
1545
|
return "body前缺少「: 」";
|
|
1514
|
-
const
|
|
1515
|
-
return /^(feat|fix|refactor)/.test(
|
|
1546
|
+
const a = t[0];
|
|
1547
|
+
return /^(feat|fix|refactor)/.test(a) ? /\(\d+(?:,\d+)*\)/.test(a) ? !0 : "ID缺少或者格式不正确。" : /^(chore|ci)/.test(a) ? [S.CHORE, S.CI].includes(a) ? !0 : "chore/ci类型无需填写ID。" : S.Break === a ? !0 : "不存在的提交类型。";
|
|
1516
1548
|
}
|
|
1517
|
-
async function
|
|
1518
|
-
const e = await
|
|
1519
|
-
|
|
1549
|
+
async function qi() {
|
|
1550
|
+
const e = await Ie(l.resolve(".git", "COMMIT_EDITMSG"), "utf-8"), t = y("提交信息格式校验中...").start(), a = Vi(e);
|
|
1551
|
+
a === !0 ? (t.succeed("提交信息格式校验通过"), process.exit(0)) : (t.fail(`提交信息格式校验失败。${a}`), process.exit(1));
|
|
1520
1552
|
}
|
|
1521
|
-
async function
|
|
1553
|
+
async function Zi() {
|
|
1522
1554
|
await be();
|
|
1523
|
-
const e = await
|
|
1555
|
+
const e = await zt({
|
|
1524
1556
|
// 分组,展示仓库链接
|
|
1525
1557
|
format: ["group", "repo"],
|
|
1526
1558
|
// 交互式弹窗
|
|
@@ -1532,28 +1564,28 @@ async function xa() {
|
|
|
1532
1564
|
});
|
|
1533
1565
|
if (e && Object.keys(e).length) {
|
|
1534
1566
|
V("升级完成 🎉");
|
|
1535
|
-
const t = Object.entries(e).map(([
|
|
1536
|
-
await
|
|
1567
|
+
const t = Object.entries(e).map(([a, n]) => `${a}@${n}`).join("; ");
|
|
1568
|
+
await d(`git add . && git commit -m "chore: 依赖升级。${t}"`);
|
|
1537
1569
|
}
|
|
1538
1570
|
process.exit(0);
|
|
1539
1571
|
}
|
|
1540
|
-
async function
|
|
1541
|
-
|
|
1572
|
+
async function Hi(e) {
|
|
1573
|
+
$(l.resolve("node_modules", ".bin", "eslint")) || m("该项目未安装eslint,请安装后重试");
|
|
1542
1574
|
const t = y("eslint执行中...").start();
|
|
1543
1575
|
try {
|
|
1544
|
-
let
|
|
1545
|
-
process.platform === "win32" && (
|
|
1576
|
+
let a = "npx eslint '**/*.{vue,js,jsx,cjs,mjs,ts,tsx,cts,mts}' --fix";
|
|
1577
|
+
process.platform === "win32" && (a = 'npx eslint "**/*.{vue,js,jsx,cjs,mjs,ts,tsx,cts,mts}" --fix'), e.quiet && (a += " --quiet"), e.maxWarnings && !isNaN(Number(e.maxWarnings)) ? a += ` --max-warnings ${Number(e.maxWarnings)}` : a += " --max-warnings 100", await d(a, {
|
|
1546
1578
|
silent: !1
|
|
1547
1579
|
}), t.succeed("eslint执行成功"), process.exit(0);
|
|
1548
1580
|
} catch {
|
|
1549
1581
|
t.fail("eslint校验出错"), process.exit(1);
|
|
1550
1582
|
}
|
|
1551
1583
|
}
|
|
1552
|
-
async function
|
|
1553
|
-
|
|
1584
|
+
async function Ki() {
|
|
1585
|
+
$(l.resolve("node_modules", ".bin", "prettier")) || m("该项目未安装prettier,请安装后重试");
|
|
1554
1586
|
const e = y("prettier执行中...").start();
|
|
1555
1587
|
try {
|
|
1556
|
-
await
|
|
1588
|
+
await d(
|
|
1557
1589
|
"npx prettier --write . --config .z/.prettierrc.json --ignore-path .z/.prettierignore --ignore-unknown --no-error-on-unmatched-pattern",
|
|
1558
1590
|
{
|
|
1559
1591
|
silent: !1
|
|
@@ -1563,12 +1595,12 @@ async function Da() {
|
|
|
1563
1595
|
e.fail("prettier校验出错"), process.exit(1);
|
|
1564
1596
|
}
|
|
1565
1597
|
}
|
|
1566
|
-
function
|
|
1567
|
-
|
|
1598
|
+
function Yi() {
|
|
1599
|
+
$(l.resolve("./node_modules/.bin/vue-tsc")) || m("请先安装vue-tsc。推荐命令: npm i -D vue-tsc"), ua("npx vue-tsc --build"), process.exit(0);
|
|
1568
1600
|
}
|
|
1569
|
-
async function
|
|
1570
|
-
ae(),
|
|
1571
|
-
const
|
|
1601
|
+
async function Xi(e, t) {
|
|
1602
|
+
ae(), Z();
|
|
1603
|
+
const a = ie();
|
|
1572
1604
|
let n;
|
|
1573
1605
|
if (e)
|
|
1574
1606
|
[
|
|
@@ -1605,18 +1637,18 @@ async function Oa(e, t) {
|
|
|
1605
1637
|
/* MarkdownLintAbbr */
|
|
1606
1638
|
].includes(e) ? n = "markdown-lint" : m("参数输入错误");
|
|
1607
1639
|
else {
|
|
1608
|
-
const
|
|
1640
|
+
const i = [
|
|
1609
1641
|
{
|
|
1610
1642
|
name: "执行 prettier",
|
|
1611
1643
|
value: "prettier"
|
|
1612
1644
|
/* Prettier */
|
|
1613
1645
|
}
|
|
1614
1646
|
];
|
|
1615
|
-
|
|
1647
|
+
a.language === w.JAVA && i.push({
|
|
1616
1648
|
name: "执行 check-style",
|
|
1617
1649
|
value: "checkstyle"
|
|
1618
1650
|
/* CheckStyle */
|
|
1619
|
-
}),
|
|
1651
|
+
}), a.language === w.JAVASCRIPT && i.push(
|
|
1620
1652
|
{
|
|
1621
1653
|
name: "执行 eslint",
|
|
1622
1654
|
value: "eslint"
|
|
@@ -1632,7 +1664,7 @@ async function Oa(e, t) {
|
|
|
1632
1664
|
value: "dependency-check"
|
|
1633
1665
|
/* DependencyCheck */
|
|
1634
1666
|
}
|
|
1635
|
-
),
|
|
1667
|
+
), a.language === w.MARKDOWN && i.push(
|
|
1636
1668
|
{
|
|
1637
1669
|
name: "执行markdown-lint",
|
|
1638
1670
|
value: "markdown-lint"
|
|
@@ -1653,26 +1685,26 @@ async function Oa(e, t) {
|
|
|
1653
1685
|
value: "dependency-check"
|
|
1654
1686
|
/* DependencyCheck */
|
|
1655
1687
|
}
|
|
1656
|
-
), n = await
|
|
1688
|
+
), n = await b({
|
|
1657
1689
|
message: "请选择你要执行的操作",
|
|
1658
|
-
choices:
|
|
1690
|
+
choices: i
|
|
1659
1691
|
});
|
|
1660
1692
|
}
|
|
1661
|
-
n === "commit-msg" ? await
|
|
1693
|
+
n === "commit-msg" ? await qi() : n === "commit-files" ? await Wi() : n === "prettier" ? await Ki() : n === "eslint" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? await Hi(t) : n === "type-check" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? Yi() : n === "dependency-check" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? await Zi() : n === "checkstyle" && a.language === w.JAVA ? await Bi() : n === "markdown-lint" && a.language === w.MARKDOWN && await _i();
|
|
1662
1694
|
}
|
|
1663
|
-
|
|
1695
|
+
D.command("run").alias("r").description("执行 eslint / prettier / type-check / dependency-check / checkstyle / markdown-lint。").argument(
|
|
1664
1696
|
"[type]",
|
|
1665
1697
|
"非必填。可选值为commit-msg|cm, commit-files|cf, prettier|p, eslint|e, type-check|tc, dependency-check|dc, checkstyle|cs, markdown-lint|ml。"
|
|
1666
|
-
).option("--quiet", "eslint只打印error").option("--max-warnings [VALUE]", "eslint结果warn超过多少个会异常退出,默认为100", parseInt).action((...e) => F(
|
|
1667
|
-
async function
|
|
1698
|
+
).option("--quiet", "eslint只打印error").option("--max-warnings [VALUE]", "eslint结果warn超过多少个会异常退出,默认为100", parseInt).action((...e) => F(Xi, ...e));
|
|
1699
|
+
async function yt(e = "latest") {
|
|
1668
1700
|
const t = y("安装中...").start();
|
|
1669
|
-
await
|
|
1670
|
-
const
|
|
1671
|
-
|
|
1701
|
+
await d(`npm i -g ${re.name}@${e} --registry https://registry.npmmirror.com/`), t.text = "本地配置更新中...", me("latestCheckVersionTimestamp", Date.now()), me("version", e);
|
|
1702
|
+
const a = await De();
|
|
1703
|
+
je(a), oe(), t.succeed(`升级完成,当前版本${e}`), process.exit(0);
|
|
1672
1704
|
}
|
|
1673
|
-
|
|
1674
|
-
const Le = /Thumbs\.db|\.git|DS_Store|idea/,
|
|
1675
|
-
function
|
|
1705
|
+
D.command("update").alias("u").description("升级").argument("[version]", "版本号", "latest").action((...e) => F(yt, ...e));
|
|
1706
|
+
const Le = /Thumbs\.db|\.git|DS_Store|idea/, vt = "testcase";
|
|
1707
|
+
function $t(e) {
|
|
1676
1708
|
const t = e.match(/^(.*[^[])?\[(\d+)]$/);
|
|
1677
1709
|
if (t && !e.startsWith("["))
|
|
1678
1710
|
return {
|
|
@@ -1680,46 +1712,46 @@ function mt(e) {
|
|
|
1680
1712
|
id: t[2],
|
|
1681
1713
|
displayName: t[1]?.trim() || ""
|
|
1682
1714
|
};
|
|
1683
|
-
const
|
|
1684
|
-
return
|
|
1715
|
+
const a = e.match(/^\[(\d+)](.+)$/);
|
|
1716
|
+
return a ? {
|
|
1685
1717
|
type: "case",
|
|
1686
|
-
id:
|
|
1687
|
-
displayName:
|
|
1718
|
+
id: a[1],
|
|
1719
|
+
displayName: a[2]?.trim() || ""
|
|
1688
1720
|
} : {
|
|
1689
1721
|
type: "directory",
|
|
1690
1722
|
id: void 0,
|
|
1691
1723
|
displayName: e
|
|
1692
1724
|
};
|
|
1693
1725
|
}
|
|
1694
|
-
async function
|
|
1695
|
-
const { exclude:
|
|
1696
|
-
async function
|
|
1697
|
-
const o =
|
|
1698
|
-
if ((await
|
|
1726
|
+
async function ee(e, t = {}) {
|
|
1727
|
+
const { exclude: a = Le } = t, n = [];
|
|
1728
|
+
async function i(s) {
|
|
1729
|
+
const o = l.basename(s);
|
|
1730
|
+
if ((await Ct(s)).isFile())
|
|
1699
1731
|
return null;
|
|
1700
|
-
const c = await
|
|
1701
|
-
c.filter((
|
|
1702
|
-
)).filter(Boolean), { type:
|
|
1732
|
+
const c = await Ce(s, { withFileTypes: !0 }), u = (await Promise.all(
|
|
1733
|
+
c.filter((T) => T.isDirectory() && !a.test(T.name)).map((T) => i(l.join(s, T.name)))
|
|
1734
|
+
)).filter(Boolean), { type: p, id: g, displayName: f } = $t(o), h = {
|
|
1703
1735
|
name: o,
|
|
1704
|
-
id:
|
|
1705
|
-
displayName:
|
|
1736
|
+
id: g,
|
|
1737
|
+
displayName: f,
|
|
1706
1738
|
path: s,
|
|
1707
|
-
type:
|
|
1739
|
+
type: p,
|
|
1708
1740
|
children: u
|
|
1709
1741
|
};
|
|
1710
|
-
return (t.hasRoot ||
|
|
1742
|
+
return (t.hasRoot || l.resolve(e) !== s) && n.push(h), h;
|
|
1711
1743
|
}
|
|
1712
|
-
return await
|
|
1744
|
+
return await i(l.resolve(e)), n;
|
|
1713
1745
|
}
|
|
1714
|
-
async function
|
|
1715
|
-
const { exclude:
|
|
1746
|
+
async function Nt(e, t = {}) {
|
|
1747
|
+
const { exclude: a = Le } = t;
|
|
1716
1748
|
try {
|
|
1717
|
-
const n = await
|
|
1749
|
+
const n = await Ce(l.resolve(e), { withFileTypes: !0 });
|
|
1718
1750
|
return await Promise.all(
|
|
1719
|
-
n.filter((
|
|
1720
|
-
const s =
|
|
1751
|
+
n.filter((i) => i.isDirectory() && !a.test(i.name)).map((i) => {
|
|
1752
|
+
const s = l.join(e, i.name), { type: o, id: r, displayName: c } = $t(i.name);
|
|
1721
1753
|
return {
|
|
1722
|
-
name:
|
|
1754
|
+
name: i.name,
|
|
1723
1755
|
id: r,
|
|
1724
1756
|
displayName: c,
|
|
1725
1757
|
path: s,
|
|
@@ -1731,41 +1763,41 @@ async function pt(e, t = {}) {
|
|
|
1731
1763
|
return m(`读取目录失败: ${e} : ${n}`), [];
|
|
1732
1764
|
}
|
|
1733
1765
|
}
|
|
1734
|
-
function q(e, t,
|
|
1766
|
+
function q(e, t, a) {
|
|
1735
1767
|
switch (e) {
|
|
1736
1768
|
case "module":
|
|
1737
|
-
return
|
|
1769
|
+
return a ? `${t}[${a}]` : t;
|
|
1738
1770
|
case "case":
|
|
1739
|
-
return
|
|
1771
|
+
return a ? `[${a}]${t}` : t;
|
|
1740
1772
|
default:
|
|
1741
1773
|
return t;
|
|
1742
1774
|
}
|
|
1743
1775
|
}
|
|
1744
|
-
async function
|
|
1776
|
+
async function we(e, t, a, n) {
|
|
1745
1777
|
try {
|
|
1746
|
-
const
|
|
1747
|
-
if (
|
|
1778
|
+
const i = l.basename(e), s = q(a, t, n);
|
|
1779
|
+
if (i === s)
|
|
1748
1780
|
return !0;
|
|
1749
|
-
const o =
|
|
1750
|
-
return await
|
|
1751
|
-
} catch (
|
|
1752
|
-
return m(`重命名文件夹失败: ${e} -> ${t}。${
|
|
1781
|
+
const o = l.dirname(e), r = l.join(o, s);
|
|
1782
|
+
return await da(e) ? await qe(e, r) : (await d(`git mv "${e}" "${r}"`), await d("git add .")), !0;
|
|
1783
|
+
} catch (i) {
|
|
1784
|
+
return m(`重命名文件夹失败: ${e} -> ${t}。${i}`), !1;
|
|
1753
1785
|
}
|
|
1754
1786
|
}
|
|
1755
|
-
async function
|
|
1756
|
-
const { exclude: n = Le } =
|
|
1757
|
-
async function
|
|
1787
|
+
async function Qi(e, t, a = {}) {
|
|
1788
|
+
const { exclude: n = Le } = a;
|
|
1789
|
+
async function i(s, o) {
|
|
1758
1790
|
if (!s || s.length === 0) return;
|
|
1759
|
-
const r = await
|
|
1791
|
+
const r = await Nt(o, { exclude: n });
|
|
1760
1792
|
for (const c of s) {
|
|
1761
|
-
const u = String(c.value),
|
|
1762
|
-
let
|
|
1763
|
-
|
|
1793
|
+
const u = String(c.value), p = q("module", c.label, u), g = r.find((h) => h.id === u);
|
|
1794
|
+
let f = g?.path || l.join(o, p);
|
|
1795
|
+
g ? g.displayName !== c.label && await we(g.path, c.label, "module", u) && (f = l.join(o, p)) : (await pe(f, { recursive: !0 }), await d(`git add "${f}"`)), c.children && c.children.length > 0 && await i(c.children, f);
|
|
1764
1796
|
}
|
|
1765
1797
|
}
|
|
1766
|
-
await
|
|
1798
|
+
await i(e, l.resolve(t));
|
|
1767
1799
|
}
|
|
1768
|
-
async function
|
|
1800
|
+
async function At(e) {
|
|
1769
1801
|
const t = {
|
|
1770
1802
|
id: 0,
|
|
1771
1803
|
name: "",
|
|
@@ -1774,167 +1806,167 @@ async function dt(e) {
|
|
|
1774
1806
|
if (e)
|
|
1775
1807
|
Number.isNaN(Number(e)) && m("请输入正确的产品ID"), t.id = Number(e);
|
|
1776
1808
|
else {
|
|
1777
|
-
const
|
|
1778
|
-
t.id = await
|
|
1809
|
+
const a = await ai();
|
|
1810
|
+
t.id = await b({
|
|
1779
1811
|
message: "请选择产品",
|
|
1780
|
-
choices:
|
|
1812
|
+
choices: a.map((n) => ({
|
|
1781
1813
|
name: `${n.label}[${n.value}]`,
|
|
1782
1814
|
value: n.value
|
|
1783
1815
|
}))
|
|
1784
1816
|
});
|
|
1785
1817
|
}
|
|
1786
|
-
return t.name = await
|
|
1818
|
+
return t.name = await ii(t.id), t.path = l.join(vt, q("module", t.name, String(t.id))), t;
|
|
1787
1819
|
}
|
|
1788
1820
|
async function Oe(e) {
|
|
1789
|
-
return (await
|
|
1821
|
+
return (await Nt(vt)).find((a) => Number(a.id) === e.id);
|
|
1790
1822
|
}
|
|
1791
|
-
async function
|
|
1792
|
-
const
|
|
1823
|
+
async function bt(e, t) {
|
|
1824
|
+
const a = {
|
|
1793
1825
|
precondition: e.precondition,
|
|
1794
1826
|
priority: e.pri,
|
|
1795
1827
|
steps: []
|
|
1796
1828
|
};
|
|
1797
|
-
|
|
1829
|
+
a.steps = await si(e.id), C.writeJSONSync(t, a, {
|
|
1798
1830
|
spaces: 2
|
|
1799
1831
|
});
|
|
1800
1832
|
}
|
|
1801
|
-
async function
|
|
1802
|
-
await
|
|
1833
|
+
async function jt(e, t) {
|
|
1834
|
+
await pe(t, {
|
|
1803
1835
|
recursive: !0
|
|
1804
|
-
}), await
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
),
|
|
1808
|
-
|
|
1809
|
-
|
|
1836
|
+
}), await bt(e, l.join(t, "config.json")), C.ensureFileSync(l.join(t, "data.yaml")), await P(
|
|
1837
|
+
l.join(t, "data.yaml"),
|
|
1838
|
+
$(l.resolve(X, "data.yaml")) ? await Ie(l.resolve(X, "data.yaml")) : await Fa()
|
|
1839
|
+
), C.ensureFileSync(l.join(t, "main.py")), await P(
|
|
1840
|
+
l.join(t, "main.py"),
|
|
1841
|
+
$(l.resolve(X, "main.py")) ? await Ie(l.resolve(X, "main.py")) : await Ja()
|
|
1810
1842
|
);
|
|
1811
1843
|
}
|
|
1812
|
-
function
|
|
1844
|
+
function Me(e) {
|
|
1813
1845
|
if (e) {
|
|
1814
|
-
const t = e.split(",").map((
|
|
1815
|
-
const n = Number(
|
|
1846
|
+
const t = e.split(",").map((a) => a.trim()).filter((a) => {
|
|
1847
|
+
const n = Number(a);
|
|
1816
1848
|
return Number.isInteger(n) && n > 0;
|
|
1817
|
-
}).map((
|
|
1849
|
+
}).map((a) => Number(a));
|
|
1818
1850
|
return t.length === 0 ? (m('未找到有效的ID,请输入格式如 "1,2,3,4" 的正整数ID'), []) : t;
|
|
1819
1851
|
}
|
|
1820
1852
|
return [];
|
|
1821
1853
|
}
|
|
1822
|
-
async function
|
|
1823
|
-
ae(),
|
|
1824
|
-
let
|
|
1825
|
-
t ? ([
|
|
1854
|
+
async function Se(e, t) {
|
|
1855
|
+
ae(), Z(), await be();
|
|
1856
|
+
let a;
|
|
1857
|
+
t ? ([I.MODULE, I.CASE].includes(t) || m(`不支持的参数${t}。参数值应为 ${I.MODULE} 或者 ${I.CASE}。`), a = t) : a = await b({
|
|
1826
1858
|
message: `请选择要${e}的数据类型`,
|
|
1827
|
-
choices:
|
|
1859
|
+
choices: ea
|
|
1828
1860
|
});
|
|
1829
|
-
const n =
|
|
1861
|
+
const n = a === I.MODULE ? "模块" : I.CASE === a ? "用例" : "";
|
|
1830
1862
|
return {
|
|
1831
|
-
type:
|
|
1863
|
+
type: a,
|
|
1832
1864
|
typeStr: n
|
|
1833
1865
|
};
|
|
1834
1866
|
}
|
|
1835
|
-
async function
|
|
1836
|
-
const t = await
|
|
1837
|
-
return
|
|
1867
|
+
async function ke(e) {
|
|
1868
|
+
const t = await At(e), a = await Oe(t);
|
|
1869
|
+
return a || m(`本地未找到产品【${t.name}[${t.id}]】`), {
|
|
1838
1870
|
product: t,
|
|
1839
|
-
localProduct:
|
|
1871
|
+
localProduct: a
|
|
1840
1872
|
};
|
|
1841
1873
|
}
|
|
1842
|
-
async function
|
|
1874
|
+
async function en(e, t, a) {
|
|
1843
1875
|
e.text = "查找本地产品目录...", await Oe(t) || m(`本地未找到产品【${t.name}[${t.id}]】`), e.text = "解析ID参数...";
|
|
1844
|
-
const
|
|
1845
|
-
let s = await
|
|
1876
|
+
const i = Me(a);
|
|
1877
|
+
let s = await ee(t.path);
|
|
1846
1878
|
e.text = "获取远程用例列表...";
|
|
1847
|
-
const o = await
|
|
1879
|
+
const o = await ni(t.id, i);
|
|
1848
1880
|
e.text = "本地用例同步中...";
|
|
1849
1881
|
for (const r of o) {
|
|
1850
1882
|
let c;
|
|
1851
|
-
if (r.module === 0 ? c =
|
|
1883
|
+
if (r.module === 0 ? c = l.resolve(t.path) : c = s.find((p) => Number(p.id) === r.module)?.path || "", !c)
|
|
1852
1884
|
return m(`用例${r.title}[${r.id}]未找到所属模块(${r.module}),请先拉取模块`);
|
|
1853
|
-
const u = s.find(({ id:
|
|
1885
|
+
const u = s.find(({ id: p }) => r.id === Number(p));
|
|
1854
1886
|
if (u)
|
|
1855
|
-
u.displayName !== r.title && await
|
|
1887
|
+
u.displayName !== r.title && await we(u.path, r.title, u.type, u.id) && V(`重命名成功: ${u.displayName} -> ${r.title}`), s = await ee(t.path), r.module === 0 ? c = l.resolve(t.path) : c = s.find((p) => Number(p.id) === r.module)?.path || "", await bt(
|
|
1856
1888
|
r,
|
|
1857
|
-
|
|
1889
|
+
l.join(c, q("case", r.title, String(r.id)), "config.json")
|
|
1858
1890
|
);
|
|
1859
1891
|
else {
|
|
1860
|
-
const
|
|
1861
|
-
await
|
|
1892
|
+
const p = l.join(c, q("case", r.title, String(r.id)));
|
|
1893
|
+
await jt(r, p);
|
|
1862
1894
|
}
|
|
1863
1895
|
}
|
|
1864
1896
|
}
|
|
1865
|
-
async function
|
|
1897
|
+
async function tn(e, t) {
|
|
1866
1898
|
e.text = "本地产品目录查找中...";
|
|
1867
|
-
const
|
|
1868
|
-
|
|
1869
|
-
const n = await
|
|
1870
|
-
e.text = "本地同步模块中...", await
|
|
1871
|
-
}
|
|
1872
|
-
async function
|
|
1873
|
-
const { type:
|
|
1874
|
-
if (
|
|
1899
|
+
const a = await Oe(t);
|
|
1900
|
+
a ? (e.text = "找到产品目录。开始重命名...", a.displayName !== t.name && await we(a.path, t.name, a.type, a.id) && (e.text = `重命名成功: ${a.displayName} -> ${t.name}`)) : (e.text = "未找到。开始创建产品目录...", await pe(t.path, { recursive: !0 }), await d("git add .")), e.text = "获取远程模块列表...";
|
|
1901
|
+
const n = await pt(t.id);
|
|
1902
|
+
e.text = "本地同步模块中...", await Qi(n || [], t.path);
|
|
1903
|
+
}
|
|
1904
|
+
async function an(e, t) {
|
|
1905
|
+
const { type: a, typeStr: n } = await Se("拉取", e), i = await At(t.productId), s = y(`${n}同步中...`).start();
|
|
1906
|
+
if (I.MODULE === a && await tn(s, i), I.CASE === a && await en(s, i, t.caseIds), s.succeed(`${n}同步完成 🎉`), !t.disableAutoCommit && await d("git status -s")) {
|
|
1875
1907
|
const o = y("代码提交中...").start();
|
|
1876
1908
|
try {
|
|
1877
|
-
await
|
|
1909
|
+
await d(`git add . && git commit -m "chore: 同步禅道${n}数据"`), o.succeed("代码已提交 ✅");
|
|
1878
1910
|
} catch (r) {
|
|
1879
1911
|
o.fail(`提交失败,${r}`), process.exit(1);
|
|
1880
1912
|
}
|
|
1881
1913
|
}
|
|
1882
1914
|
}
|
|
1883
|
-
|
|
1884
|
-
async function
|
|
1885
|
-
let n = await
|
|
1915
|
+
D.command("qa-pull").alias("qp").description("将禅道中的模块或者用例同步到本地").argument("[type]", "可选值为module/case").option("--product-id <productId>", "指定产品ID").option("--case-ids <caseIds>", "type=case时,可传指定用例ID(可传N个,逗号隔开);不传则为产品下全部用例").option("--disable-auto-commit", "是否跳过自动将修改结果提交。").action((...e) => F(an, ...e));
|
|
1916
|
+
async function nn(e, t, a) {
|
|
1917
|
+
let n = await B({
|
|
1886
1918
|
message: "请输入你要创建的用例的前置条件(可不填)"
|
|
1887
1919
|
});
|
|
1888
1920
|
n = n.trim();
|
|
1889
|
-
const
|
|
1890
|
-
|
|
1891
|
-
const s = await
|
|
1921
|
+
const i = y(`用例【${a}】开始创建...`).start();
|
|
1922
|
+
i.text = "远程用例创建中...";
|
|
1923
|
+
const s = await oi({
|
|
1892
1924
|
product: Number(e.id),
|
|
1893
1925
|
// 如果父模块是产品根目录,parent=0
|
|
1894
|
-
module:
|
|
1895
|
-
title:
|
|
1926
|
+
module: l.resolve(e?.path) === t?.path ? 0 : Number(t?.id || 0),
|
|
1927
|
+
title: a,
|
|
1896
1928
|
type: "interface",
|
|
1897
|
-
openedBy:
|
|
1929
|
+
openedBy: E("ldapAccount"),
|
|
1898
1930
|
precondition: n || ""
|
|
1899
1931
|
});
|
|
1900
|
-
|
|
1932
|
+
i.text = "远程用例步骤创建中...", await ci({
|
|
1901
1933
|
case: s,
|
|
1902
1934
|
type: "step",
|
|
1903
1935
|
desc: "按照预期执行",
|
|
1904
1936
|
expect: "正常执行,符合预期"
|
|
1905
|
-
}),
|
|
1906
|
-
const o =
|
|
1907
|
-
return
|
|
1937
|
+
}), i.text = "本地用例创建中...";
|
|
1938
|
+
const o = l.join(t.path, q("case", a, String(s)));
|
|
1939
|
+
return $(o) ? V(`${o}已存在,请检查是否对应,本地不再创建。`) : (await jt(
|
|
1908
1940
|
{
|
|
1909
1941
|
id: s,
|
|
1910
1942
|
pri: 3,
|
|
1911
1943
|
precondition: n
|
|
1912
1944
|
},
|
|
1913
1945
|
o
|
|
1914
|
-
),
|
|
1946
|
+
), i.succeed(`用例【[${o}】创建完成 🎉`), o);
|
|
1915
1947
|
}
|
|
1916
|
-
async function
|
|
1917
|
-
const n = y(`模块【${
|
|
1948
|
+
async function sn(e, t, a) {
|
|
1949
|
+
const n = y(`模块【${a}】开始创建...`).start();
|
|
1918
1950
|
n.text = "远程模块创建中...";
|
|
1919
|
-
const
|
|
1951
|
+
const i = await ri({
|
|
1920
1952
|
root: Number(e.id),
|
|
1921
|
-
name:
|
|
1953
|
+
name: a,
|
|
1922
1954
|
// 如果父模块是产品根目录,parent=0
|
|
1923
|
-
parent:
|
|
1955
|
+
parent: l.resolve(e?.path) === t?.path ? 0 : Number(t?.id || 0)
|
|
1924
1956
|
});
|
|
1925
1957
|
n.text = "本地模块创建中...";
|
|
1926
|
-
const s =
|
|
1927
|
-
if (
|
|
1958
|
+
const s = l.join(t.path, q("module", a, String(i)));
|
|
1959
|
+
if ($(s))
|
|
1928
1960
|
return V(`${s}已存在,请检查是否对应,本地不再创建。`);
|
|
1929
|
-
await
|
|
1961
|
+
await pe(s, {
|
|
1930
1962
|
recursive: !0
|
|
1931
1963
|
}), n.succeed(`模块【${s}】创建完成 🎉`);
|
|
1932
1964
|
}
|
|
1933
|
-
function
|
|
1965
|
+
function rn(e) {
|
|
1934
1966
|
function t(n) {
|
|
1935
1967
|
if (!n.children || n.children.length === 0) return;
|
|
1936
|
-
const
|
|
1937
|
-
|
|
1968
|
+
const i = n.children[0];
|
|
1969
|
+
i && i.label === n.label && i.value === n.value && (!i.children || i.children.length === 0) || n.children.unshift({
|
|
1938
1970
|
value: n.value,
|
|
1939
1971
|
label: n.label,
|
|
1940
1972
|
type: n.type,
|
|
@@ -1942,56 +1974,56 @@ function _a(e) {
|
|
|
1942
1974
|
tempTitle: "当前层级"
|
|
1943
1975
|
});
|
|
1944
1976
|
}
|
|
1945
|
-
async function
|
|
1946
|
-
const s =
|
|
1977
|
+
async function a(n, i = []) {
|
|
1978
|
+
const s = i.length ? `请选择层级(当前:${i.join(" / ")})` : "请选择层级", o = await b({
|
|
1947
1979
|
message: s,
|
|
1948
1980
|
choices: n.map((r) => ({
|
|
1949
1981
|
name: `${r.tempTitle ? r.tempTitle : r.label} ${r.children?.length ? "(有子级)" : ""}`,
|
|
1950
1982
|
value: r
|
|
1951
1983
|
}))
|
|
1952
1984
|
});
|
|
1953
|
-
return o?.children?.length ? (t(o),
|
|
1985
|
+
return o?.children?.length ? (t(o), a(o.children, [...i, o.label])) : o;
|
|
1954
1986
|
}
|
|
1955
|
-
return
|
|
1987
|
+
return a(e);
|
|
1956
1988
|
}
|
|
1957
|
-
async function
|
|
1958
|
-
const { type:
|
|
1959
|
-
if (!
|
|
1989
|
+
async function on(e, t) {
|
|
1990
|
+
const { type: a, typeStr: n } = await Se("创建", e), { product: i, localProduct: s } = await ke(t.productId), o = await pt(i.id), r = await rn(o), c = q("module", r.label, String(r.value)), p = (await ee(i.path, { hasRoot: !0 })).find((h) => h.name === c);
|
|
1991
|
+
if (!p?.path || !$(p.path))
|
|
1960
1992
|
return m(`本地不存在${c}模块`);
|
|
1961
|
-
let
|
|
1993
|
+
let g = await B({
|
|
1962
1994
|
message: `请输入你要创建的${n}名称`,
|
|
1963
1995
|
required: !0,
|
|
1964
1996
|
validate: (h) => h.length > 0 && h.length < 255
|
|
1965
1997
|
});
|
|
1966
|
-
|
|
1967
|
-
let
|
|
1968
|
-
if (
|
|
1998
|
+
g = g.trim();
|
|
1999
|
+
let f = "";
|
|
2000
|
+
if (I.MODULE === a && await sn(s, p, g), I.CASE === a && (f = await nn(s, p, g)), !t.disableAutoCommit && I.CASE === a) {
|
|
1969
2001
|
const h = y("代码提交中...").start();
|
|
1970
2002
|
try {
|
|
1971
|
-
await
|
|
1972
|
-
} catch (
|
|
1973
|
-
h.fail(`提交失败,${
|
|
2003
|
+
await d(`git add . && git commit -m "chore: 创建了用例${l.basename(f)}"`), h.succeed("代码已提交 ✅");
|
|
2004
|
+
} catch (T) {
|
|
2005
|
+
h.fail(`提交失败,${T}`), process.exit(1);
|
|
1974
2006
|
}
|
|
1975
2007
|
}
|
|
1976
2008
|
}
|
|
1977
|
-
|
|
1978
|
-
async function
|
|
1979
|
-
const n = (await
|
|
1980
|
-
let
|
|
2009
|
+
D.command("qa-create").alias("qc").description("创建模块或者用例").argument("[type]", "可选值为module/case").option("--product-id <productId>", "指定产品ID").option("--disable-auto-commit", "是否跳过自动将修改结果提交。").action((...e) => F(on, ...e));
|
|
2010
|
+
async function cn(e, t) {
|
|
2011
|
+
const n = (await ee(e.path)).filter((r) => r.type === "case");
|
|
2012
|
+
let i = [];
|
|
1981
2013
|
if (t.length)
|
|
1982
|
-
|
|
2014
|
+
i = n.filter((r) => t.includes(Number(r.id))).map((r) => ({
|
|
1983
2015
|
id: Number(r.id),
|
|
1984
2016
|
path: r.path
|
|
1985
|
-
})),
|
|
2017
|
+
})), i.length || m(`未找到对应用例,请确认输入的用例ID(${t.join(", ")})是否正确`);
|
|
1986
2018
|
else {
|
|
1987
2019
|
const r = n.map((c) => ({
|
|
1988
2020
|
value: {
|
|
1989
2021
|
id: Number(c.id),
|
|
1990
2022
|
path: c.path
|
|
1991
2023
|
},
|
|
1992
|
-
name: c.path.replace(
|
|
2024
|
+
name: c.path.replace(l.resolve(e.path), "")
|
|
1993
2025
|
}));
|
|
1994
|
-
|
|
2026
|
+
i = await te({
|
|
1995
2027
|
message: "选择要删除的用例",
|
|
1996
2028
|
pageSize: 100,
|
|
1997
2029
|
loop: !1,
|
|
@@ -2001,32 +2033,32 @@ async function Ga(e, t) {
|
|
|
2001
2033
|
}
|
|
2002
2034
|
});
|
|
2003
2035
|
}
|
|
2004
|
-
const s = y("远程用例删除中...").start(), o =
|
|
2005
|
-
await
|
|
2036
|
+
const s = y("远程用例删除中...").start(), o = i.map((r) => r.id);
|
|
2037
|
+
await li({
|
|
2006
2038
|
product: Number(e.id),
|
|
2007
2039
|
caseIds: o
|
|
2008
2040
|
}), s.text = "本地用例删除中...";
|
|
2009
|
-
for (const r of
|
|
2010
|
-
|
|
2041
|
+
for (const r of i)
|
|
2042
|
+
$(r.path) && L.rm("-rf", r.path);
|
|
2011
2043
|
return s.succeed("用例删除完成"), o;
|
|
2012
2044
|
}
|
|
2013
|
-
async function
|
|
2014
|
-
const n = (await
|
|
2015
|
-
let
|
|
2045
|
+
async function un(e, t) {
|
|
2046
|
+
const n = (await ee(e.path)).filter((r) => r.type === "module");
|
|
2047
|
+
let i = [];
|
|
2016
2048
|
if (t.length)
|
|
2017
|
-
|
|
2049
|
+
i = n.filter((r) => t.includes(Number(r.id))).map((r) => ({
|
|
2018
2050
|
id: Number(r.id),
|
|
2019
2051
|
path: r.path
|
|
2020
|
-
})),
|
|
2052
|
+
})), i.length || m(`未找到对应模块,请确认输入的模块ID(${t.join(", ")})是否正确`);
|
|
2021
2053
|
else {
|
|
2022
2054
|
const r = n.map((c) => ({
|
|
2023
2055
|
value: {
|
|
2024
2056
|
id: Number(c.id),
|
|
2025
2057
|
path: c.path
|
|
2026
2058
|
},
|
|
2027
|
-
name: c.path.replace(
|
|
2059
|
+
name: c.path.replace(l.resolve(e.path), "")
|
|
2028
2060
|
}));
|
|
2029
|
-
|
|
2061
|
+
i = await te({
|
|
2030
2062
|
message: "选择要删除的模块",
|
|
2031
2063
|
pageSize: 100,
|
|
2032
2064
|
loop: !1,
|
|
@@ -2036,120 +2068,120 @@ async function Wa(e, t) {
|
|
|
2036
2068
|
}
|
|
2037
2069
|
});
|
|
2038
2070
|
}
|
|
2039
|
-
|
|
2040
|
-
const s = y("远程模块删除中...").start(), o =
|
|
2041
|
-
await
|
|
2071
|
+
i = i.sort((r, c) => r.path.localeCompare(c.path));
|
|
2072
|
+
const s = y("远程模块删除中...").start(), o = i.map((r) => r.id);
|
|
2073
|
+
await ui({
|
|
2042
2074
|
product: Number(e.id),
|
|
2043
2075
|
moduleIds: o
|
|
2044
2076
|
}), s.text = "本地模块删除中...";
|
|
2045
|
-
for (const r of
|
|
2046
|
-
|
|
2077
|
+
for (const r of i)
|
|
2078
|
+
$(r.path) && L.rm("-rf", r.path);
|
|
2047
2079
|
return s.succeed("模块删除完成"), o;
|
|
2048
2080
|
}
|
|
2049
|
-
async function
|
|
2050
|
-
const { type:
|
|
2081
|
+
async function ln(e, t) {
|
|
2082
|
+
const { type: a, typeStr: n } = await Se("删除", e), { localProduct: i } = await ke(t.productId), s = Me(t.targetIds);
|
|
2051
2083
|
let o = [];
|
|
2052
|
-
if (
|
|
2084
|
+
if (I.MODULE === a ? o = await un(i, s) : I.CASE === a && (o = await cn(i, s)), !t.disableAutoCommit && await d("git status -s")) {
|
|
2053
2085
|
const r = y("代码提交中...").start();
|
|
2054
2086
|
try {
|
|
2055
|
-
await
|
|
2087
|
+
await d(`git add . && git commit -m 'chore: 删除了一些${n}(${o.join(", ")})'`), r.succeed("代码已提交 ✅");
|
|
2056
2088
|
} catch (c) {
|
|
2057
2089
|
r.fail(`提交失败,${c}`), process.exit(1);
|
|
2058
2090
|
}
|
|
2059
2091
|
}
|
|
2060
2092
|
}
|
|
2061
|
-
|
|
2062
|
-
async function
|
|
2063
|
-
const n = (await
|
|
2064
|
-
let
|
|
2093
|
+
D.command("qa-remove").alias("qr").description("删除模块或者用例").argument("[type]", "可选值为module/case").option("--product-id <productId>", "指定产品ID").option("--target-ids <targetIds>", "可传指定目标(用例/模块)ID。可传N个,逗号隔开").option("--disable-auto-commit", "是否跳过自动将修改结果提交。").action((...e) => F(ln, ...e));
|
|
2094
|
+
async function mn(e, t) {
|
|
2095
|
+
const n = (await ee(e.path)).filter((f) => f.type === "case");
|
|
2096
|
+
let i;
|
|
2065
2097
|
if (t.targetId) {
|
|
2066
|
-
if (
|
|
2098
|
+
if (i = n.find((f) => Number(f.id) === Number(t.targetId)), !i)
|
|
2067
2099
|
return m(`未找到对应用例,请确认输入的用例ID(${t.targetId})是否正确`);
|
|
2068
2100
|
} else {
|
|
2069
|
-
const
|
|
2101
|
+
const f = n.map((h) => ({
|
|
2070
2102
|
value: {
|
|
2071
2103
|
id: Number(h.id),
|
|
2072
2104
|
path: h.path,
|
|
2073
2105
|
displayName: h.displayName
|
|
2074
2106
|
},
|
|
2075
|
-
name: h.path.replace(
|
|
2107
|
+
name: h.path.replace(l.resolve(e.path), "")
|
|
2076
2108
|
}));
|
|
2077
|
-
[
|
|
2109
|
+
[i] = await te({
|
|
2078
2110
|
message: "选择要更新的用例",
|
|
2079
2111
|
pageSize: 100,
|
|
2080
2112
|
loop: !1,
|
|
2081
2113
|
multiple: void 0,
|
|
2082
|
-
options: (h) => h ?
|
|
2114
|
+
options: (h) => h ? f.filter((T) => T.name.includes(h)) : f,
|
|
2083
2115
|
validate(h) {
|
|
2084
2116
|
return h.length > 1 ? "只能选一个" : h.length < 1 ? "请选一个" : !0;
|
|
2085
2117
|
}
|
|
2086
2118
|
});
|
|
2087
2119
|
}
|
|
2088
|
-
let s = await
|
|
2120
|
+
let s = await B({
|
|
2089
2121
|
message: "修改用例名称",
|
|
2090
|
-
default:
|
|
2122
|
+
default: i.displayName,
|
|
2091
2123
|
required: !0,
|
|
2092
|
-
validate: (
|
|
2124
|
+
validate: (f) => f.length > 0 && f.length < 255,
|
|
2093
2125
|
prefill: "editable"
|
|
2094
2126
|
});
|
|
2095
2127
|
s = s.trim();
|
|
2096
2128
|
const o = y("用例重命名中...").start();
|
|
2097
|
-
s !==
|
|
2098
|
-
id: Number(
|
|
2129
|
+
s !== i.displayName ? (await pi({
|
|
2130
|
+
id: Number(i.id),
|
|
2099
2131
|
name: s
|
|
2100
|
-
}), await
|
|
2101
|
-
let r =
|
|
2102
|
-
t.casePriority ? Number.isInteger(t.casePriority) && Number(t.casePriority) > 0 && Number(t.casePriority) < 6 ? c = Number(t.casePriority) : c = await
|
|
2132
|
+
}), await we(i.path, s, "case", String(i.id)) && o.succeed(`用例重命名成功: ${i.displayName} -> ${s}`), i.displayName = s, i.path = l.join(l.dirname(i.path), q("case", s, String(i.id)))) : o.succeed("用例名称无变动");
|
|
2133
|
+
let r = C.readJsonSync(l.join(i.path, "config.json")), c;
|
|
2134
|
+
t.casePriority ? Number.isInteger(t.casePriority) && Number(t.casePriority) > 0 && Number(t.casePriority) < 6 ? c = Number(t.casePriority) : c = await Be({
|
|
2103
2135
|
message: "修改用例优先级",
|
|
2104
2136
|
min: 1,
|
|
2105
2137
|
max: 5,
|
|
2106
2138
|
required: !0,
|
|
2107
2139
|
default: r.priority,
|
|
2108
|
-
validate: (
|
|
2109
|
-
}) : c = await
|
|
2140
|
+
validate: (f) => f > 0 && f < 6
|
|
2141
|
+
}) : c = await Be({
|
|
2110
2142
|
message: "修改用例优先级",
|
|
2111
2143
|
min: 1,
|
|
2112
2144
|
max: 5,
|
|
2113
2145
|
required: !0,
|
|
2114
2146
|
default: r.priority,
|
|
2115
|
-
validate: (
|
|
2147
|
+
validate: (f) => f > 0 && f < 6
|
|
2116
2148
|
});
|
|
2117
2149
|
const u = y("用例优先级设置中...").start();
|
|
2118
|
-
c !== r.priority ? (await
|
|
2119
|
-
id: Number(
|
|
2150
|
+
c !== r.priority ? (await di({
|
|
2151
|
+
id: Number(i.id),
|
|
2120
2152
|
priority: c
|
|
2121
|
-
}),
|
|
2122
|
-
|
|
2153
|
+
}), C.writeJSONSync(
|
|
2154
|
+
l.join(i.path, "config.json"),
|
|
2123
2155
|
{
|
|
2124
2156
|
...r,
|
|
2125
2157
|
priority: c
|
|
2126
2158
|
},
|
|
2127
2159
|
{ spaces: 2 }
|
|
2128
|
-
), u.succeed(`用例优先级修改成功:${r.priority} -> ${c}`)) : u.succeed("用例优先级无变动"), r =
|
|
2129
|
-
let
|
|
2130
|
-
t.casePrecondition ?
|
|
2160
|
+
), u.succeed(`用例优先级修改成功:${r.priority} -> ${c}`)) : u.succeed("用例优先级无变动"), r = C.readJsonSync(l.join(i.path, "config.json"));
|
|
2161
|
+
let p;
|
|
2162
|
+
t.casePrecondition ? p = t.casePrecondition : (p = await B({
|
|
2131
2163
|
message: "修改用例前置条件",
|
|
2132
2164
|
default: r.precondition,
|
|
2133
2165
|
prefill: "editable"
|
|
2134
|
-
}),
|
|
2135
|
-
const
|
|
2136
|
-
return
|
|
2137
|
-
id: Number(
|
|
2138
|
-
precondition:
|
|
2139
|
-
}),
|
|
2140
|
-
|
|
2166
|
+
}), p = p.trim());
|
|
2167
|
+
const g = y("用例前置条件设置中...").start();
|
|
2168
|
+
return p !== r.precondition ? (await fi({
|
|
2169
|
+
id: Number(i.id),
|
|
2170
|
+
precondition: p
|
|
2171
|
+
}), C.writeJSONSync(
|
|
2172
|
+
l.join(i.path, "config.json"),
|
|
2141
2173
|
{
|
|
2142
2174
|
...r,
|
|
2143
|
-
precondition:
|
|
2175
|
+
precondition: p
|
|
2144
2176
|
},
|
|
2145
2177
|
{ spaces: 2 }
|
|
2146
|
-
),
|
|
2178
|
+
), g.succeed(`用例前置条件修改成功:${r.precondition} -> ${p}`)) : g.succeed("用例前置条件无变动"), i.id;
|
|
2147
2179
|
}
|
|
2148
|
-
async function
|
|
2149
|
-
const n = (await
|
|
2150
|
-
let
|
|
2180
|
+
async function pn(e, t) {
|
|
2181
|
+
const n = (await ee(e.path)).filter((r) => r.type === "module");
|
|
2182
|
+
let i;
|
|
2151
2183
|
if (t.targetId) {
|
|
2152
|
-
if (
|
|
2184
|
+
if (i = n.find((r) => Number(r.id) === Number(t.targetId)), !i)
|
|
2153
2185
|
return m(`未找到对应模块,请确认输入的模块ID(${t.targetId})是否正确`);
|
|
2154
2186
|
} else {
|
|
2155
2187
|
const r = n.map((c) => ({
|
|
@@ -2158,9 +2190,9 @@ async function Ha(e, t) {
|
|
|
2158
2190
|
path: c.path,
|
|
2159
2191
|
displayName: c.displayName
|
|
2160
2192
|
},
|
|
2161
|
-
name: c.path.replace(
|
|
2193
|
+
name: c.path.replace(l.resolve(e.path), "")
|
|
2162
2194
|
}));
|
|
2163
|
-
[
|
|
2195
|
+
[i] = await te({
|
|
2164
2196
|
message: "选择要更新的模块",
|
|
2165
2197
|
pageSize: 100,
|
|
2166
2198
|
loop: !1,
|
|
@@ -2171,182 +2203,387 @@ async function Ha(e, t) {
|
|
|
2171
2203
|
}
|
|
2172
2204
|
});
|
|
2173
2205
|
}
|
|
2174
|
-
let s = await
|
|
2206
|
+
let s = await B({
|
|
2175
2207
|
message: "修改模块名称",
|
|
2176
|
-
default:
|
|
2208
|
+
default: i.displayName,
|
|
2177
2209
|
required: !0,
|
|
2178
2210
|
validate: (r) => r.length > 0 && r.length < 255,
|
|
2179
2211
|
prefill: "editable"
|
|
2180
2212
|
});
|
|
2181
2213
|
s = s.trim();
|
|
2182
2214
|
const o = y("模块重命名中...").start();
|
|
2183
|
-
return s !==
|
|
2184
|
-
id: Number(
|
|
2215
|
+
return s !== i.displayName ? (await mi({
|
|
2216
|
+
id: Number(i.id),
|
|
2185
2217
|
name: s
|
|
2186
|
-
}), await
|
|
2218
|
+
}), await we(i.path, s, "module", String(i.id)) && o.succeed(`模块重命名成功: ${i.displayName} -> ${s}`)) : o.succeed("模块名称无变动"), i.id;
|
|
2187
2219
|
}
|
|
2188
|
-
async function
|
|
2189
|
-
const { type:
|
|
2220
|
+
async function dn(e, t) {
|
|
2221
|
+
const { type: a, typeStr: n } = await Se("修改", e), { localProduct: i } = await ke(t.productId);
|
|
2190
2222
|
let s;
|
|
2191
|
-
if (
|
|
2223
|
+
if (I.MODULE === a ? s = await pn(i, t) : I.CASE === a && (s = await mn(i, t)), !t.disableAutoCommit && await d("git status -s")) {
|
|
2192
2224
|
const o = y("代码提交中...").start();
|
|
2193
2225
|
try {
|
|
2194
|
-
await
|
|
2226
|
+
await d(`git add . && git commit -m 'chore: 修改了一个${n}(${s})'`), o.succeed("代码已提交 ✅");
|
|
2195
2227
|
} catch (r) {
|
|
2196
2228
|
o.fail(`提交失败,${r}`), process.exit(1);
|
|
2197
2229
|
}
|
|
2198
2230
|
}
|
|
2199
2231
|
}
|
|
2200
|
-
|
|
2201
|
-
async function
|
|
2232
|
+
D.command("qa-update").alias("qu").description("修改模块或者用例").argument("[type]", "可选值为module/case").option("--product-id <productId>", "指定产品ID").option("--target-id <targetId>", "可传指定目标(用例/模块)ID").option("--target-name <targetName>", "可传指定目标(用例/模块)修改后的名称").option("--case-priority <casePriority>", "如果是用例,指定修改后的优先级").option("--case-precondition <casePrecondition>", "如果是用例,指定修改后的前置条件").option("--disable-auto-commit", "是否跳过自动将修改结果提交。").action((...e) => F(dn, ...e));
|
|
2233
|
+
async function fn(e, t) {
|
|
2202
2234
|
if (!e.length)
|
|
2203
2235
|
return [];
|
|
2204
|
-
const
|
|
2205
|
-
(
|
|
2236
|
+
const a = Ft(20), n = e.map(
|
|
2237
|
+
(i) => a(async () => {
|
|
2206
2238
|
try {
|
|
2207
|
-
const s = t.env || "production", o = await
|
|
2239
|
+
const s = t.env || "production", o = await d(`python ${i.path}/main.py --env ${s}`);
|
|
2208
2240
|
try {
|
|
2209
|
-
|
|
2241
|
+
i.result = JSON.parse(o);
|
|
2210
2242
|
} catch {
|
|
2211
|
-
m(`用例${
|
|
2243
|
+
m(`用例${i.displayName}[${i.id}]返回格式错误:${o}`);
|
|
2212
2244
|
}
|
|
2213
2245
|
} catch (s) {
|
|
2214
2246
|
const o = s instanceof Error ? s.message : String(s);
|
|
2215
|
-
m(`用例${
|
|
2247
|
+
m(`用例${i.displayName}[${i.id}]执行失败: ${o}`);
|
|
2216
2248
|
}
|
|
2217
2249
|
})
|
|
2218
2250
|
);
|
|
2219
2251
|
return await Promise.all(n), e;
|
|
2220
2252
|
}
|
|
2221
|
-
async function
|
|
2222
|
-
ae(),
|
|
2223
|
-
const { localProduct: t } = await
|
|
2224
|
-
let
|
|
2225
|
-
const
|
|
2253
|
+
async function gn(e) {
|
|
2254
|
+
ae(), Z();
|
|
2255
|
+
const { localProduct: t } = await ke(e.productId);
|
|
2256
|
+
let a = [];
|
|
2257
|
+
const i = (await ee(t.path)).filter((c) => c.type === "case");
|
|
2226
2258
|
if (e.all)
|
|
2227
|
-
|
|
2259
|
+
a = i.map((c) => ({
|
|
2228
2260
|
id: Number(c.id),
|
|
2229
2261
|
path: c.path,
|
|
2230
2262
|
displayName: c.displayName
|
|
2231
2263
|
}));
|
|
2232
2264
|
else {
|
|
2233
|
-
const c =
|
|
2265
|
+
const c = Me(e.caseIds);
|
|
2234
2266
|
if (c.length)
|
|
2235
|
-
|
|
2267
|
+
a = i.filter((u) => c.includes(Number(u.id))).map((u) => ({
|
|
2236
2268
|
id: Number(u.id),
|
|
2237
2269
|
path: u.path,
|
|
2238
2270
|
displayName: u.displayName
|
|
2239
2271
|
}));
|
|
2240
2272
|
else {
|
|
2241
|
-
const u =
|
|
2273
|
+
const u = i.map((p) => ({
|
|
2242
2274
|
value: {
|
|
2243
|
-
id: Number(
|
|
2244
|
-
path:
|
|
2245
|
-
displayName:
|
|
2275
|
+
id: Number(p.id),
|
|
2276
|
+
path: p.path,
|
|
2277
|
+
displayName: p.displayName
|
|
2246
2278
|
},
|
|
2247
|
-
name:
|
|
2279
|
+
name: p.path.replace(l.resolve(t.path), "")
|
|
2248
2280
|
}));
|
|
2249
|
-
|
|
2281
|
+
a = await te({
|
|
2250
2282
|
message: "选择要执行的用例",
|
|
2251
2283
|
pageSize: 100,
|
|
2252
2284
|
loop: !1,
|
|
2253
|
-
options: (
|
|
2254
|
-
validate(
|
|
2255
|
-
return
|
|
2285
|
+
options: (p) => p ? u.filter((g) => g.name.includes(p)) : u,
|
|
2286
|
+
validate(p) {
|
|
2287
|
+
return p.length === 0 ? "至少选择一项" : !0;
|
|
2256
2288
|
}
|
|
2257
2289
|
});
|
|
2258
2290
|
}
|
|
2259
2291
|
}
|
|
2260
|
-
const s = y("用例执行中...").start(), r = (await
|
|
2292
|
+
const s = y("用例执行中...").start(), r = (await fn(a, e)).filter((c) => c.result.length);
|
|
2261
2293
|
if (r.length === 0)
|
|
2262
2294
|
s.succeed("所有用例执行通过 🎉");
|
|
2263
2295
|
else {
|
|
2264
2296
|
if (e.processStep === "1")
|
|
2265
2297
|
return V("执行报告如下:"), console.log(JSON.stringify(r, null, 2)), process.exit(0);
|
|
2266
|
-
const c = r.reduce((
|
|
2298
|
+
const c = r.reduce((g, f) => g + f.result.length, 0);
|
|
2267
2299
|
s.warn(`【${r.length}】个用例执行出错,【${c}】个BUG将创建。`);
|
|
2268
2300
|
let u = 0;
|
|
2269
2301
|
if (e.executionId)
|
|
2270
2302
|
Number.isNaN(Number(e.executionId)) && m(`executionId ${e.executionId}不是正整数`), u = Number(e.executionId);
|
|
2271
2303
|
else {
|
|
2272
|
-
const
|
|
2304
|
+
const g = await hi(), f = await b({
|
|
2273
2305
|
message: "请选择用例执行出错后,BUG所属的项目",
|
|
2274
|
-
choices:
|
|
2275
|
-
}), h = await
|
|
2276
|
-
u = await
|
|
2306
|
+
choices: g.map(({ id: T, name: ne }) => ({ name: ne, value: T }))
|
|
2307
|
+
}), h = await wi(f);
|
|
2308
|
+
u = await b({
|
|
2277
2309
|
message: "请选择用例执行出错后,BUG所属的执行",
|
|
2278
|
-
choices: h.map(({ id:
|
|
2310
|
+
choices: h.map(({ id: T, name: ne }) => ({ name: ne, value: T }))
|
|
2279
2311
|
});
|
|
2280
2312
|
}
|
|
2281
|
-
let
|
|
2313
|
+
let p;
|
|
2282
2314
|
if (e.buildId)
|
|
2283
|
-
|
|
2315
|
+
p = e.buildId;
|
|
2284
2316
|
else {
|
|
2285
|
-
const
|
|
2286
|
-
if (
|
|
2287
|
-
const
|
|
2317
|
+
const g = await yi(Number(u));
|
|
2318
|
+
if (g.length) {
|
|
2319
|
+
const f = await ve({
|
|
2288
2320
|
message: "请选择BUG关联的构建版本(可多选;非必选,默认主干)",
|
|
2289
2321
|
required: !1,
|
|
2290
|
-
choices:
|
|
2322
|
+
choices: g.map(({ id: h, name: T, date: ne, builder: O }) => ({
|
|
2291
2323
|
value: h,
|
|
2292
|
-
name: `${
|
|
2324
|
+
name: `${T} ${O} ${ne}`
|
|
2293
2325
|
}))
|
|
2294
2326
|
});
|
|
2295
|
-
|
|
2327
|
+
f.length ? p = f.join(",") : p = "";
|
|
2296
2328
|
} else
|
|
2297
|
-
s.warn("当前执行下没有构建,使用默认【主干】"),
|
|
2329
|
+
s.warn("当前执行下没有构建,使用默认【主干】"), p = "";
|
|
2298
2330
|
}
|
|
2299
2331
|
s.start("上传中...");
|
|
2300
|
-
for (const
|
|
2301
|
-
await
|
|
2302
|
-
caseId:
|
|
2332
|
+
for (const g of r)
|
|
2333
|
+
await gi({
|
|
2334
|
+
caseId: g.id,
|
|
2303
2335
|
caseResult: "fail",
|
|
2304
|
-
stepResults:
|
|
2305
|
-
runner:
|
|
2336
|
+
stepResults: g.result,
|
|
2337
|
+
runner: E("ldapAccount"),
|
|
2306
2338
|
executionId: u,
|
|
2307
|
-
openedBuild:
|
|
2339
|
+
openedBuild: p
|
|
2308
2340
|
});
|
|
2309
2341
|
s.succeed(
|
|
2310
|
-
`用例执行完成。查看相关BUG(${
|
|
2342
|
+
`用例执行完成。查看相关BUG(${z("ZenTaoDomain")}/zentao/execution-bug-${u}.html}) `
|
|
2311
2343
|
);
|
|
2312
2344
|
}
|
|
2313
2345
|
}
|
|
2314
|
-
|
|
2315
|
-
|
|
2346
|
+
D.command("qa-exec").alias("qe").description("执行用例").option("--product-id <productId>", "指定产品ID").option("--case-ids <caseIds>", "可传指定用例ID。可传N个,逗号隔开").option("--all", "执行产品下所有用例").option("--concurrency <concurrency>", "最多并行执行脚本数。默认20").option("--process-step <step>", "不传默认2。 1. 仅在本地返回执行报告; 2. 执行出错的结果提交到禅道用例并提交BUG。").option("--env <env>", "环境变量,会作为参数传递给执行脚本。默认production").option("--execution-id <executionId>", "提bug时,要关联的禅道执行ID").option("--build-id <buildId>", "提bug时,要关联的禅道执行构建ID。默认主干(trunk)").action((...e) => F(gn, ...e));
|
|
2347
|
+
const Ve = (e) => {
|
|
2348
|
+
const t = e.trim();
|
|
2349
|
+
if (!t)
|
|
2350
|
+
return "请输入生成目录";
|
|
2351
|
+
if (t.includes("\0"))
|
|
2352
|
+
return "路径格式不合法";
|
|
2353
|
+
if (l.isAbsolute(t))
|
|
2354
|
+
return "只允许输入相对路径";
|
|
2355
|
+
const a = l.normalize(t);
|
|
2356
|
+
return !a || a === "." || a === ".." ? "请输入有效的目录路径" : a.startsWith(`..${l.sep}`) ? "路径不能跳出当前项目" : !0;
|
|
2357
|
+
}, hn = async () => {
|
|
2358
|
+
const { projects: e } = await Pa(), t = ie();
|
|
2359
|
+
if (t.serverProjectURL) {
|
|
2360
|
+
const n = e.find(
|
|
2361
|
+
(i) => nt(i.url, t.serverProjectURL)
|
|
2362
|
+
);
|
|
2363
|
+
if (n)
|
|
2364
|
+
return {
|
|
2365
|
+
projectId: decodeURIComponent(Q(t.serverProjectURL)),
|
|
2366
|
+
moduleList: n.modules || []
|
|
2367
|
+
};
|
|
2368
|
+
}
|
|
2369
|
+
const a = await b({
|
|
2370
|
+
message: "请选择本项目对应的服务端项目",
|
|
2371
|
+
choices: e.map((n) => ({
|
|
2372
|
+
name: `${n.name}(${n.url})`,
|
|
2373
|
+
value: n.url
|
|
2374
|
+
}))
|
|
2375
|
+
});
|
|
2376
|
+
return ct({ ...t, serverProjectURL: a }), {
|
|
2377
|
+
projectId: decodeURIComponent(Q(a)),
|
|
2378
|
+
moduleList: e.find((n) => n.url === a)?.modules || []
|
|
2379
|
+
};
|
|
2380
|
+
}, wn = async (e) => {
|
|
2381
|
+
if (e) {
|
|
2382
|
+
if (["all", "single"].includes(e))
|
|
2383
|
+
return e;
|
|
2384
|
+
m("type值错误");
|
|
2385
|
+
} else
|
|
2386
|
+
return await b({
|
|
2387
|
+
message: "请选择生成API的范围",
|
|
2388
|
+
choices: [
|
|
2389
|
+
{
|
|
2390
|
+
name: "所有接口",
|
|
2391
|
+
value: "all"
|
|
2392
|
+
},
|
|
2393
|
+
{
|
|
2394
|
+
name: "单个接口",
|
|
2395
|
+
value: "single"
|
|
2396
|
+
}
|
|
2397
|
+
]
|
|
2398
|
+
});
|
|
2399
|
+
}, yn = async (e, t) => {
|
|
2400
|
+
if (e)
|
|
2401
|
+
return e.split(",").filter((a) => t.map((n) => n.name).includes(a.trim()));
|
|
2402
|
+
{
|
|
2403
|
+
const a = await ve({
|
|
2404
|
+
message: "请选择对应的后端服务,不选默认全部",
|
|
2405
|
+
choices: t.map((n) => ({
|
|
2406
|
+
name: `${n.name}(${n.desc})`,
|
|
2407
|
+
value: n.name
|
|
2408
|
+
})),
|
|
2409
|
+
required: !1,
|
|
2410
|
+
pageSize: 10,
|
|
2411
|
+
loop: !0
|
|
2412
|
+
});
|
|
2413
|
+
return a?.length ? a : t.map((n) => n.name);
|
|
2414
|
+
}
|
|
2415
|
+
}, vn = async (e) => e && [k.DEV, k.TEST, k.RELEASE, k.PROD].includes(e.trim()) ? e : await b({
|
|
2416
|
+
message: "请选择对应的环境",
|
|
2417
|
+
// 去掉prod 环境
|
|
2418
|
+
choices: Qe.filter((t) => t.value !== k.PROD)
|
|
2419
|
+
}), ze = (e) => {
|
|
2420
|
+
const t = /^https?:\/\/[^/]+\/api\/([^/]+)\/v3\//;
|
|
2421
|
+
return e.match(t)?.[1];
|
|
2422
|
+
}, $n = async (e) => {
|
|
2423
|
+
try {
|
|
2424
|
+
const t = await H({
|
|
2425
|
+
url: e,
|
|
2426
|
+
method: "get"
|
|
2427
|
+
}), a = ze(e);
|
|
2428
|
+
return a && (t.paths = Object.fromEntries(
|
|
2429
|
+
Object.entries(t.paths).map(([n, i]) => [`/${a}${n}`, i])
|
|
2430
|
+
)), Ut(t);
|
|
2431
|
+
} catch (t) {
|
|
2432
|
+
throw m(`Error fetching Swagger JSON: ${t.message}`), t;
|
|
2433
|
+
}
|
|
2434
|
+
}, Re = (e) => {
|
|
2435
|
+
const t = (a) => {
|
|
2436
|
+
const { reason: n, url: i } = a;
|
|
2437
|
+
return `## ${ze(i)}服务接口文档校验失败
|
|
2438
|
+
${n.message}`;
|
|
2439
|
+
};
|
|
2440
|
+
return `# 服务端接口文档校验失败
|
|
2441
|
+
${e.map(t).join(`
|
|
2442
|
+
`)}`;
|
|
2443
|
+
}, Nn = async (e, t, a) => {
|
|
2444
|
+
const n = e.filter((i) => t.includes(i.name)).map((i) => i.swagger);
|
|
2445
|
+
if (n.length) {
|
|
2446
|
+
const i = n.flatMap((s) => {
|
|
2447
|
+
const o = s.find((r) => r.env === a);
|
|
2448
|
+
return o ? [o.url] : [];
|
|
2449
|
+
});
|
|
2450
|
+
if (i.length) {
|
|
2451
|
+
const s = y("API数据请求中...").start(), o = await Promise.allSettled(i.map($n)), r = o.flatMap(
|
|
2452
|
+
(c, u) => c.status === "rejected" ? [{ reason: c.reason, url: i[u] }] : []
|
|
2453
|
+
);
|
|
2454
|
+
if (r.length) {
|
|
2455
|
+
const c = ie(), { groups: u } = await lt(), p = u.find(
|
|
2456
|
+
(g) => g.projects.some((f) => nt(f, c.serverProjectURL))
|
|
2457
|
+
);
|
|
2458
|
+
if (p) {
|
|
2459
|
+
const { code: g, message: f } = await $i({
|
|
2460
|
+
content: Re(r),
|
|
2461
|
+
webhooks: [p.url]
|
|
2462
|
+
});
|
|
2463
|
+
g !== 0 && (s.fail(`发送消息到企微群组失败: ${A.red(f)}`), s.text = A.red(Re(r)), s.start(), process.exit(1));
|
|
2464
|
+
} else
|
|
2465
|
+
s.fail("未找到对应的项目群聊组!"), s.fail(Re(r));
|
|
2466
|
+
s.fail("API数据解析失败"), process.exit(1);
|
|
2467
|
+
} else
|
|
2468
|
+
return s.succeed("API数据请求成功"), o.flatMap((c, u) => c.status === "fulfilled" ? [{ serverName: ze(i[u]), swaggerJson: c.value }] : []);
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
throw new Error("Failed to fetch Swagger JSON");
|
|
2472
|
+
}, An = async (e) => {
|
|
2473
|
+
const t = [];
|
|
2474
|
+
for (const a of e) {
|
|
2475
|
+
const { apis: n } = await Bt(a);
|
|
2476
|
+
t.push(...n.map((i) => ({ name: i.path, value: i.path })));
|
|
2477
|
+
}
|
|
2478
|
+
return te({
|
|
2479
|
+
message: "请选择需要生成的API",
|
|
2480
|
+
options: (a) => a ? t.filter((n) => n.name.includes(a)) : t,
|
|
2481
|
+
pageSize: 20,
|
|
2482
|
+
loop: !0,
|
|
2483
|
+
clearInputWhenSelected: !0,
|
|
2484
|
+
multiple: !0,
|
|
2485
|
+
validate: (a) => a.length ? !0 : "至少选择一个API",
|
|
2486
|
+
filter: !0
|
|
2487
|
+
});
|
|
2488
|
+
}, bn = async (e, t) => {
|
|
2489
|
+
const a = y("API 开始生成...").start();
|
|
2490
|
+
try {
|
|
2491
|
+
a.stop();
|
|
2492
|
+
for (const { swaggerJson: n, serverName: i } of e) {
|
|
2493
|
+
if (!t.some((o) => o.startsWith(`/${i}`)))
|
|
2494
|
+
continue;
|
|
2495
|
+
const s = await _t({ swaggerJson: n, merge: !0, controller: t });
|
|
2496
|
+
console.log(Gt(s, { language: "typescript", ignoreIllegals: !0 }));
|
|
2497
|
+
}
|
|
2498
|
+
a.start().succeed("API 生成成功");
|
|
2499
|
+
} catch (n) {
|
|
2500
|
+
a.fail(`API 生成失败: ${n.message}`);
|
|
2501
|
+
}
|
|
2502
|
+
}, jn = (e) => {
|
|
2503
|
+
if (e) {
|
|
2504
|
+
const t = Ve(e);
|
|
2505
|
+
return t !== !0 && m(t), e;
|
|
2506
|
+
}
|
|
2507
|
+
return B({
|
|
2508
|
+
message: "请输入 API 输出目录,默认为 src/services",
|
|
2509
|
+
default: "src/services",
|
|
2510
|
+
validate: Ve
|
|
2511
|
+
});
|
|
2512
|
+
}, Sn = new He({
|
|
2513
|
+
fix: !0
|
|
2514
|
+
}), kn = async (e) => {
|
|
2515
|
+
const t = await Sn.lintFiles(e);
|
|
2516
|
+
await He.outputFixes(t);
|
|
2517
|
+
for (const a of e) {
|
|
2518
|
+
const n = l.resolve(a), i = Wt(n, "utf-8"), s = await Vt.format(i, {
|
|
2519
|
+
filepath: n
|
|
2520
|
+
});
|
|
2521
|
+
It(n, s);
|
|
2522
|
+
}
|
|
2523
|
+
}, Tn = async (e, t, a) => {
|
|
2524
|
+
const n = e.map((i) => i.swaggerJson);
|
|
2525
|
+
if (t === "single") {
|
|
2526
|
+
const i = await An(n);
|
|
2527
|
+
await bn(e, i);
|
|
2528
|
+
} else {
|
|
2529
|
+
const i = y("API 开始生成...").start(), s = await Jt(
|
|
2530
|
+
n.map((u) => ({
|
|
2531
|
+
swaggerJson: u
|
|
2532
|
+
}))
|
|
2533
|
+
);
|
|
2534
|
+
i.stop();
|
|
2535
|
+
const o = await jn(a), r = l.resolve(o);
|
|
2536
|
+
Je.mkdirSync(r, { recursive: !0 });
|
|
2537
|
+
const c = [];
|
|
2538
|
+
i.start(), i.text = "API 生成中...";
|
|
2539
|
+
for (const u of s) {
|
|
2540
|
+
const { path: p, content: g } = u, f = l.resolve(r, p);
|
|
2541
|
+
c.push(f), Je.writeFileSync(f, g);
|
|
2542
|
+
}
|
|
2543
|
+
i.text = "开始格式化代码", await kn(c), i.text = "代码格式化完成", i.succeed(`API 已生成到 ${o} 目录下`);
|
|
2544
|
+
}
|
|
2545
|
+
};
|
|
2546
|
+
async function En(e, t) {
|
|
2547
|
+
ae(), Z();
|
|
2548
|
+
const { moduleList: a } = await hn(), { module: n, env: i, dir: s } = t, o = await yn(n, a), r = await vn(i), c = await Nn(a, o, r), u = await wn(e);
|
|
2549
|
+
await Tn(c, u, s), process.exit(0);
|
|
2550
|
+
}
|
|
2551
|
+
D.command("api").alias("a").description("选择对应的服务端项目,获取接口并转成ts接口代码及类型").argument("[type]", "可选值为service单个服务, controller单个controller, single单个接口").option("--module [module]", "模块名称。多个使用逗号隔开").option("--env [env]", "指定环境。dev/test/release").option("--controller-name [controllerName]", "controller名称").option("--api-name [apiName]", "api名称").action((...e) => F(En, ...e));
|
|
2552
|
+
function Rn() {
|
|
2316
2553
|
process.on("unhandledRejection", (e) => {
|
|
2317
2554
|
}), process.on("uncaughtException", (e) => {
|
|
2318
2555
|
}), L.config.fatal = !0, L.config.silent = !0, L.config.verbose = !1;
|
|
2319
2556
|
}
|
|
2320
|
-
async function
|
|
2321
|
-
const e =
|
|
2557
|
+
async function In() {
|
|
2558
|
+
const e = ge("latestCheckVersionTimestamp"), t = ge("versionCheckDuring");
|
|
2322
2559
|
if (Date.now() - Number(e) > Number(t) * 24 * 3600 * 1e3) {
|
|
2323
|
-
const
|
|
2324
|
-
|
|
2560
|
+
const a = await De();
|
|
2561
|
+
je(a);
|
|
2325
2562
|
let n;
|
|
2326
2563
|
try {
|
|
2327
|
-
const
|
|
2328
|
-
setTimeout(() => o(
|
|
2564
|
+
const i = "TIME_OUT", s = new Promise((o) => {
|
|
2565
|
+
setTimeout(() => o(i), 3e3);
|
|
2329
2566
|
});
|
|
2330
2567
|
n = await Promise.race([
|
|
2331
2568
|
s,
|
|
2332
|
-
|
|
2333
|
-
]), n !==
|
|
2334
|
-
} catch (
|
|
2335
|
-
console.log("升级出错!请重试,或者手动升级"), m(
|
|
2569
|
+
d(`npm view ${re.name} version --registry https://registry.npmmirror.com/`)
|
|
2570
|
+
]), n !== i && n !== re.version && (console.log(`${A.blue(re.name)}本地版本为${re.version},低于线上版本${n},开始升级`), await yt(n)), me("latestCheckVersionTimestamp", Date.now()), oe();
|
|
2571
|
+
} catch (i) {
|
|
2572
|
+
console.log("升级出错!请重试,或者手动升级"), m(i);
|
|
2336
2573
|
}
|
|
2337
2574
|
}
|
|
2338
2575
|
}
|
|
2339
|
-
async function
|
|
2340
|
-
const e =
|
|
2576
|
+
async function Cn() {
|
|
2577
|
+
const e = qt(process.argv.slice(2));
|
|
2341
2578
|
if (!(e.h || e.help || e.v || e.version) && !(["init", "i"].includes(e._[0]) && ![".", "prepare"].includes(e._[1])))
|
|
2342
|
-
if (
|
|
2343
|
-
const t =
|
|
2344
|
-
M(t.profile),
|
|
2579
|
+
if (it()) {
|
|
2580
|
+
const t = C.readJSONSync(Ae());
|
|
2581
|
+
M(t.profile), me(t.main), je(t.constants), await In();
|
|
2345
2582
|
} else
|
|
2346
|
-
m(`请先初始化z-develop(执行 z i)。更多见${
|
|
2583
|
+
m(`请先初始化z-develop(执行 z i)。更多见${et}`);
|
|
2347
2584
|
}
|
|
2348
|
-
async function
|
|
2349
|
-
|
|
2585
|
+
async function xn() {
|
|
2586
|
+
Rn(), await Cn();
|
|
2350
2587
|
}
|
|
2351
|
-
|
|
2352
|
-
|
|
2588
|
+
D.name("z-develop").alias("z").description(`z-develop, 开发流程管理工具。了解更多: ${A.blue(et)}`).usage("<command> [options]").hook("preAction", xn).version(re.version, "-v, --version", "当前版本号").helpOption("-h, --help", "帮助").showHelpAfterError("可以使用z -h查看帮助。");
|
|
2589
|
+
D.parse();
|