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