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