cli-z-develop 0.14.7 → 0.14.9
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 +608 -598
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { program as P } from "commander";
|
|
2
|
-
import
|
|
2
|
+
import Tt from "node:child_process";
|
|
3
3
|
import * as Ue from "node:fs";
|
|
4
4
|
import { existsSync as A, readdirSync as Rt, lstatSync as It, createWriteStream as Ct, writeFileSync as xt } from "node:fs";
|
|
5
5
|
import { readdir as xe, mkdir as pe, writeFile as D, stat as He, rename as Ke, readFile as Re } from "node:fs/promises";
|
|
@@ -25,23 +25,23 @@ import { readFileSync as Vt } from "fs";
|
|
|
25
25
|
import qt from "prettier";
|
|
26
26
|
import Zt from "minimist";
|
|
27
27
|
const Qe = "dev", et = "test", tt = "release", Ht = "production", Kt = "master";
|
|
28
|
-
var
|
|
29
|
-
const
|
|
28
|
+
var E = /* @__PURE__ */ ((e) => (e[e.DEV = Qe] = "DEV", e[e.TEST = et] = "TEST", e[e.RELEASE = tt] = "RELEASE", e[e.PROD = Ht] = "PROD", e))(E || {}), $ = /* @__PURE__ */ ((e) => (e[e.DEV = Qe] = "DEV", e[e.TEST = et] = "TEST", e[e.RELEASE = tt] = "RELEASE", e[e.MASTER = Kt] = "MASTER", e))($ || {}), V = /* @__PURE__ */ ((e) => (e.H5 = "h5", e.NPM = "npm", e.SERVER = "server", e))(V || {});
|
|
29
|
+
const at = [
|
|
30
30
|
{
|
|
31
|
-
name: `开发环境 - ${
|
|
32
|
-
value:
|
|
31
|
+
name: `开发环境 - ${E.DEV}`,
|
|
32
|
+
value: E.DEV
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
|
-
name: `测试环境 - ${
|
|
36
|
-
value:
|
|
35
|
+
name: `测试环境 - ${E.TEST}`,
|
|
36
|
+
value: E.TEST
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
|
-
name: `预发环境 - ${
|
|
40
|
-
value:
|
|
39
|
+
name: `预发环境 - ${E.RELEASE}`,
|
|
40
|
+
value: E.RELEASE
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
|
-
name: `正式环境 - ${
|
|
44
|
-
value:
|
|
43
|
+
name: `正式环境 - ${E.PROD}`,
|
|
44
|
+
value: E.PROD
|
|
45
45
|
}
|
|
46
46
|
], Xt = [
|
|
47
47
|
{
|
|
@@ -73,9 +73,9 @@ const Yt = {
|
|
|
73
73
|
9: "其他"
|
|
74
74
|
}, fe = "http://git.cxlqd.com", Qt = ["fe-biz", "fe-base", "fe-tpl", "fe-component", "fe-demo"];
|
|
75
75
|
var S = /* @__PURE__ */ ((e) => (e.FEAT = "feat", e.FIX = "fix", e.REFACTOR = "refactor", e.CHORE = "chore", e.CI = "ci", e.Break = "BREAKING CHANGE", e))(S || {});
|
|
76
|
-
const
|
|
76
|
+
const ea = "fe-biz7tvsd", it = "https://hxhtbr8t8uy.feishu.cn/wiki/LWW5wAQFPiXkmRkKcjOcyDDknLg";
|
|
77
77
|
var R = /* @__PURE__ */ ((e) => (e.MODULE = "module", e.CASE = "case", e))(R || {});
|
|
78
|
-
const
|
|
78
|
+
const ta = [
|
|
79
79
|
{
|
|
80
80
|
name: "模块",
|
|
81
81
|
value: "module"
|
|
@@ -86,101 +86,101 @@ const ti = [
|
|
|
86
86
|
value: "case"
|
|
87
87
|
/* CASE */
|
|
88
88
|
}
|
|
89
|
-
],
|
|
90
|
-
function
|
|
89
|
+
], aa = 150 * 1024, Ie = ",", ia = ".z", na = "develop-config.json", Q = ".z", sa = ".commit-msg-tpl", ra = "project.json";
|
|
90
|
+
function T(e = "") {
|
|
91
91
|
return m.join(Q, e);
|
|
92
92
|
}
|
|
93
93
|
function nt() {
|
|
94
|
-
return
|
|
94
|
+
return T(ra);
|
|
95
95
|
}
|
|
96
96
|
function Ne() {
|
|
97
|
-
return
|
|
97
|
+
return T(sa);
|
|
98
98
|
}
|
|
99
99
|
function st() {
|
|
100
|
-
Be.spawnSync("git", ["config", "core.hooksPath",
|
|
100
|
+
Be.spawnSync("git", ["config", "core.hooksPath", T()]), Be.spawnSync("git", ["config", "commit.template", Ne()]);
|
|
101
101
|
}
|
|
102
102
|
function he(e = "") {
|
|
103
|
-
return m.resolve(Lt.homedir(),
|
|
103
|
+
return m.resolve(Lt.homedir(), ia, e);
|
|
104
104
|
}
|
|
105
105
|
function Ae() {
|
|
106
|
-
return he(
|
|
106
|
+
return he(na);
|
|
107
107
|
}
|
|
108
|
-
function
|
|
108
|
+
function oa() {
|
|
109
109
|
return A(he());
|
|
110
110
|
}
|
|
111
111
|
function rt() {
|
|
112
|
-
return
|
|
112
|
+
return oa() && A(Ae());
|
|
113
113
|
}
|
|
114
114
|
function ee(e, t = !0) {
|
|
115
|
-
let
|
|
116
|
-
const n =
|
|
115
|
+
let a = e.trim();
|
|
116
|
+
const n = a.match(/^git@([^:]+):(.+)$/);
|
|
117
117
|
if (n)
|
|
118
|
-
|
|
118
|
+
a = n[2];
|
|
119
119
|
else {
|
|
120
120
|
const s = fe.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
121
|
-
|
|
121
|
+
a = a.replace(/^https?:\/\//, ""), a.startsWith(`${s}/`) ? a = a.slice(s.length + 1) : a = a.replace(`${fe.replace(/\/$/, "")}/`, "");
|
|
122
122
|
}
|
|
123
|
-
const
|
|
124
|
-
return t ? encodeURIComponent(
|
|
123
|
+
const i = a.replace(/\.git$/, "");
|
|
124
|
+
return t ? encodeURIComponent(i) : i;
|
|
125
125
|
}
|
|
126
126
|
function ot(e, t) {
|
|
127
127
|
return ee(e) === ee(t);
|
|
128
128
|
}
|
|
129
|
-
const { red: _e, green:
|
|
129
|
+
const { red: _e, green: ca, blue: cs, magenta: ua, yellow: la } = N;
|
|
130
130
|
function ye(...e) {
|
|
131
131
|
}
|
|
132
132
|
function We(...e) {
|
|
133
|
-
console.log(
|
|
133
|
+
console.log(la(...e));
|
|
134
134
|
}
|
|
135
135
|
function q(...e) {
|
|
136
|
-
console.log(
|
|
136
|
+
console.log(ca(...e));
|
|
137
137
|
}
|
|
138
138
|
function ct(e) {
|
|
139
139
|
e instanceof Error && (e.name === "ExitPromptError" || e.message.includes("User force closed the prompt with")) && (console.log(), console.log(N.cyan(" 👋 下次见~")), console.log(), process.exit(1));
|
|
140
140
|
}
|
|
141
141
|
function p(e, t = !1) {
|
|
142
142
|
ct(e);
|
|
143
|
-
let
|
|
144
|
-
e instanceof Error ? (
|
|
143
|
+
let a = e;
|
|
144
|
+
e instanceof Error ? (a = e.message, le.isAxiosError(e) && (a = `请求失败:${e.message}`), console.log(_e(a)), console.log(ua(e.stack))) : console.log(_e(e)), t || process.exit(1);
|
|
145
145
|
}
|
|
146
146
|
function Ve(e) {
|
|
147
147
|
return A(e) ? It(e).isDirectory() : !1;
|
|
148
148
|
}
|
|
149
149
|
function ut(e = process.cwd()) {
|
|
150
|
-
return Ve(e) ? Rt(e).filter((
|
|
150
|
+
return Ve(e) ? Rt(e).filter((a) => Ve(m.resolve(e, a))) : [];
|
|
151
151
|
}
|
|
152
152
|
async function d(e, t = {
|
|
153
153
|
removeTailLinkBreak: !0,
|
|
154
154
|
silent: !0
|
|
155
155
|
}) {
|
|
156
|
-
let
|
|
156
|
+
let a = await new Promise((n, i) => {
|
|
157
157
|
try {
|
|
158
158
|
const s = L.exec(e, {
|
|
159
159
|
silent: t.silent
|
|
160
160
|
});
|
|
161
161
|
n(s);
|
|
162
162
|
} catch (s) {
|
|
163
|
-
|
|
163
|
+
i(s);
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
|
-
return
|
|
166
|
+
return a = a.toString(), t.removeTailLinkBreak && (a = a.replace(/\n$/, "")), a;
|
|
167
167
|
}
|
|
168
|
-
function
|
|
169
|
-
|
|
168
|
+
function ma(e) {
|
|
169
|
+
Tt.execSync(e, {
|
|
170
170
|
stdio: "inherit"
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
function lt() {
|
|
174
174
|
return Dt(Date.now()).format("YYMMDD");
|
|
175
175
|
}
|
|
176
|
-
function
|
|
177
|
-
for (const
|
|
178
|
-
if (!e.includes(
|
|
176
|
+
function pa(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
|
-
A(
|
|
182
|
+
function ae() {
|
|
183
|
+
A(T()) || p("当前不在项目根目录。请切换到项目根目录");
|
|
184
184
|
}
|
|
185
185
|
function K() {
|
|
186
186
|
A(m.resolve(".git")) || p("当前不是git项目根目录,请先执行git init,或切换到根目录");
|
|
@@ -188,23 +188,23 @@ function K() {
|
|
|
188
188
|
async function be() {
|
|
189
189
|
await d("git status -s") !== "" && p("请先提交代码变动,再进行操作");
|
|
190
190
|
}
|
|
191
|
-
function
|
|
192
|
-
return e === $.MASTER ?
|
|
191
|
+
function da(e) {
|
|
192
|
+
return e === $.MASTER ? E.PROD : e;
|
|
193
193
|
}
|
|
194
|
-
function
|
|
195
|
-
return e ===
|
|
194
|
+
function fa(e) {
|
|
195
|
+
return e === E.PROD ? $.MASTER : e;
|
|
196
196
|
}
|
|
197
197
|
async function M(e, ...t) {
|
|
198
198
|
try {
|
|
199
199
|
await e(...t);
|
|
200
|
-
} catch (
|
|
201
|
-
throw ct(
|
|
200
|
+
} catch (a) {
|
|
201
|
+
throw ct(a), a;
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
async function
|
|
204
|
+
async function ga(e) {
|
|
205
205
|
return (await xe(e)).length === 0;
|
|
206
206
|
}
|
|
207
|
-
function
|
|
207
|
+
function ha(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 wa = {
|
|
265
265
|
[w.JAVA]: {
|
|
266
266
|
"**/*.{java}": "java -jar ./.z/checkstyle.jar -c ./.z/checkstyle.xml"
|
|
267
267
|
},
|
|
@@ -279,17 +279,17 @@ const wi = {
|
|
|
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:
|
|
282
|
+
}, ya = "cli-z-develop", va = "0.14.9", $a = "技术团队开发流程管理工具", Na = "dist/index.js", Aa = { z: "bin/z.js", "z-develop": "bin/z.js" }, ba = { 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" }, ja = "module", Sa = "z", ka = { "@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" }, Ea = { "@inquirer/prompts": "^8.4.1", "@lonely9/api-generate": "^0.2.8", 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: ya,
|
|
284
|
+
version: va,
|
|
285
|
+
description: $a,
|
|
286
|
+
main: Na,
|
|
287
|
+
bin: Aa,
|
|
288
|
+
scripts: ba,
|
|
289
|
+
type: ja,
|
|
290
|
+
author: Sa,
|
|
291
|
+
devDependencies: ka,
|
|
292
|
+
dependencies: Ea
|
|
293
293
|
}, x = {
|
|
294
294
|
// 个人数据
|
|
295
295
|
profile: {
|
|
@@ -340,7 +340,7 @@ function Pe() {
|
|
|
340
340
|
const e = m.join("package.json");
|
|
341
341
|
return A(e) || p(`当前目录(${L.pwd()})不存在${e}文件,请在项目根目录执行该命令。`), _ = I.readJsonSync(e), _;
|
|
342
342
|
}
|
|
343
|
-
function
|
|
343
|
+
function ie() {
|
|
344
344
|
if (W)
|
|
345
345
|
return W;
|
|
346
346
|
const e = nt();
|
|
@@ -354,7 +354,7 @@ function mt(e) {
|
|
|
354
354
|
...e
|
|
355
355
|
} : W = e, I.writeJSONSync(nt(), W, { spaces: 2 });
|
|
356
356
|
}
|
|
357
|
-
function
|
|
357
|
+
function Ta(e) {
|
|
358
358
|
_ ? _ = {
|
|
359
359
|
..._,
|
|
360
360
|
...e
|
|
@@ -367,11 +367,11 @@ const Y = {
|
|
|
367
367
|
sourceBranch: "",
|
|
368
368
|
mergeRequestUrl: ""
|
|
369
369
|
};
|
|
370
|
-
async function
|
|
370
|
+
async function Ra() {
|
|
371
371
|
if (!Y.id)
|
|
372
372
|
try {
|
|
373
|
-
const e =
|
|
374
|
-
Y.id =
|
|
373
|
+
const e = ie(), t = ee(e.repository.url), a = await dt(t);
|
|
374
|
+
Y.id = a.id, Y.path = t, Y.group = a.namespace.full_path, Y.mergeRequestUrl = `${a.web_url}/merge_requests`;
|
|
375
375
|
} catch (e) {
|
|
376
376
|
p(e);
|
|
377
377
|
}
|
|
@@ -409,23 +409,23 @@ function me(e, t) {
|
|
|
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
|
-
ye(N.magenta(s.method.toUpperCase()), N.yellow(s.url), JSON.stringify(s.headers)), ye(N.gray(JSON.stringify(s[
|
|
421
|
+
ye(N.magenta(s.method.toUpperCase()), N.yellow(s.url), JSON.stringify(s.headers)), ye(N.gray(JSON.stringify(s[i], null, 2)));
|
|
422
422
|
const o = await le(s);
|
|
423
423
|
return ye(N.green("Response"), N.grey(JSON.stringify(o.data, null, 2))), Promise.resolve(o.data);
|
|
424
424
|
} catch (s) {
|
|
425
425
|
return s instanceof Pt && ye(N.red("Error"), N.grey(JSON.stringify(s?.response?.data))), Promise.reject(s);
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
|
-
async function
|
|
428
|
+
async function Ia() {
|
|
429
429
|
const e = C("gitToken");
|
|
430
430
|
if (e)
|
|
431
431
|
return e;
|
|
@@ -438,19 +438,19 @@ async function Ii() {
|
|
|
438
438
|
username: C("ldapAccount"),
|
|
439
439
|
password: C("ldapPassword")
|
|
440
440
|
}
|
|
441
|
-
}),
|
|
442
|
-
return J("gitToken",
|
|
441
|
+
}), a = `Bearer ${t}`;
|
|
442
|
+
return J("gitToken", a), oe(), a;
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
445
|
async function b(e) {
|
|
446
446
|
return ne({
|
|
447
447
|
...e,
|
|
448
448
|
headers: {
|
|
449
|
-
Authorization: await
|
|
449
|
+
Authorization: await Ia()
|
|
450
450
|
}
|
|
451
451
|
});
|
|
452
452
|
}
|
|
453
|
-
async function
|
|
453
|
+
async function Ca() {
|
|
454
454
|
const e = C("zenTaoToken");
|
|
455
455
|
if (e)
|
|
456
456
|
return e;
|
|
@@ -470,30 +470,30 @@ async function $e(e) {
|
|
|
470
470
|
const t = await ne({
|
|
471
471
|
...e,
|
|
472
472
|
headers: {
|
|
473
|
-
Token: await
|
|
473
|
+
Token: await Ca()
|
|
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
482
|
return t.error === "Unauthorized" || t.data.indexOf("<script>") < 0 ? (J("zenTaoToken", ""), $e({
|
|
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 === "用户登录" ? (J("zenTaoToken", ""), $e({
|
|
490
490
|
...e
|
|
491
|
-
})) :
|
|
491
|
+
})) : i;
|
|
492
492
|
} else
|
|
493
493
|
return {};
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
|
-
async function
|
|
496
|
+
async function xa() {
|
|
497
497
|
const e = C("k8sToken");
|
|
498
498
|
if (e)
|
|
499
499
|
return e;
|
|
@@ -508,13 +508,13 @@ async function xi() {
|
|
|
508
508
|
username: C("ldapAccount"),
|
|
509
509
|
password: C("ldapPassword")
|
|
510
510
|
}
|
|
511
|
-
}),
|
|
512
|
-
return J("k8sToken",
|
|
511
|
+
}), a = `Bearer ${t}`;
|
|
512
|
+
return J("k8sToken", a), oe(), a;
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
|
-
async function
|
|
515
|
+
async function Pa(e, t) {
|
|
516
516
|
try {
|
|
517
|
-
const
|
|
517
|
+
const a = Ct(t, { mode: 493 });
|
|
518
518
|
return (await le({
|
|
519
519
|
method: "get",
|
|
520
520
|
url: e,
|
|
@@ -522,25 +522,25 @@ async function Pi(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
532
|
const z = () => `${fe}/api/v4`, F = (e) => `${z()}/projects/100/repository/files/${encodeURIComponent(e)}/raw?ref=master`;
|
|
533
|
-
function
|
|
533
|
+
function Da() {
|
|
534
534
|
return b({
|
|
535
535
|
url: F("src/data/template-projects.json")
|
|
536
536
|
});
|
|
537
537
|
}
|
|
538
|
-
function
|
|
538
|
+
function La() {
|
|
539
539
|
return b({
|
|
540
540
|
url: F("src/data/java-project-module.json")
|
|
541
541
|
});
|
|
542
542
|
}
|
|
543
|
-
function
|
|
543
|
+
function Oa() {
|
|
544
544
|
return b({
|
|
545
545
|
url: F("src/data/java-project-api.json")
|
|
546
546
|
});
|
|
@@ -550,37 +550,37 @@ function De() {
|
|
|
550
550
|
url: F("src/data/z-develop-config.json")
|
|
551
551
|
});
|
|
552
552
|
}
|
|
553
|
-
function
|
|
553
|
+
function Ma() {
|
|
554
554
|
return b({
|
|
555
555
|
url: F("src/assets/tsconfig.browser.json")
|
|
556
556
|
});
|
|
557
557
|
}
|
|
558
|
-
function
|
|
558
|
+
function za() {
|
|
559
559
|
return b({
|
|
560
560
|
url: F("src/assets/tsconfig.node.json")
|
|
561
561
|
});
|
|
562
562
|
}
|
|
563
|
-
function
|
|
563
|
+
function Fa() {
|
|
564
564
|
return b({
|
|
565
565
|
url: F("src/assets/.prettierignore")
|
|
566
566
|
});
|
|
567
567
|
}
|
|
568
|
-
function
|
|
568
|
+
function Ja() {
|
|
569
569
|
return b({
|
|
570
570
|
url: F("src/assets/.prettierrc.json")
|
|
571
571
|
});
|
|
572
572
|
}
|
|
573
|
-
function
|
|
573
|
+
function Ua() {
|
|
574
574
|
return b({
|
|
575
575
|
url: F("src/assets/data.yaml")
|
|
576
576
|
});
|
|
577
577
|
}
|
|
578
|
-
function
|
|
578
|
+
function Ba() {
|
|
579
579
|
return b({
|
|
580
580
|
url: F("src/assets/main.py")
|
|
581
581
|
});
|
|
582
582
|
}
|
|
583
|
-
function
|
|
583
|
+
function Ga() {
|
|
584
584
|
return b({
|
|
585
585
|
url: F("src/assets/checkstyle.xml")
|
|
586
586
|
});
|
|
@@ -590,17 +590,17 @@ function pt() {
|
|
|
590
590
|
url: F("src/data/project-group-chats.json")
|
|
591
591
|
});
|
|
592
592
|
}
|
|
593
|
-
function
|
|
593
|
+
function _a() {
|
|
594
594
|
return b({
|
|
595
595
|
url: `${z()}/user`
|
|
596
596
|
});
|
|
597
597
|
}
|
|
598
|
-
function
|
|
598
|
+
function Wa() {
|
|
599
599
|
return b({
|
|
600
600
|
url: `${z()}/groups`
|
|
601
601
|
});
|
|
602
602
|
}
|
|
603
|
-
function
|
|
603
|
+
function Va(e) {
|
|
604
604
|
return b({
|
|
605
605
|
url: `${z()}/projects`,
|
|
606
606
|
method: "post",
|
|
@@ -612,7 +612,7 @@ function dt(e) {
|
|
|
612
612
|
url: `${z()}/projects/${e}`
|
|
613
613
|
});
|
|
614
614
|
}
|
|
615
|
-
function
|
|
615
|
+
function qa(e) {
|
|
616
616
|
return b({
|
|
617
617
|
url: `${z()}/projects`,
|
|
618
618
|
data: {
|
|
@@ -621,61 +621,61 @@ function qi(e) {
|
|
|
621
621
|
}
|
|
622
622
|
});
|
|
623
623
|
}
|
|
624
|
-
function
|
|
624
|
+
function Za(e) {
|
|
625
625
|
return b({
|
|
626
626
|
url: `${z()}/projects/${e.id}/merge_requests`,
|
|
627
627
|
method: "post",
|
|
628
628
|
data: e
|
|
629
629
|
});
|
|
630
630
|
}
|
|
631
|
-
function
|
|
631
|
+
function Ha(e) {
|
|
632
632
|
return b({
|
|
633
633
|
url: `${z()}/projects/${e.id}/merge_requests/${e.iid}/merge`,
|
|
634
634
|
method: "put"
|
|
635
635
|
});
|
|
636
636
|
}
|
|
637
|
-
function
|
|
637
|
+
function Ka(e) {
|
|
638
638
|
return b({
|
|
639
639
|
url: `${z()}/projects/${e.id}/merge_requests/${e.iid}`,
|
|
640
640
|
method: "put",
|
|
641
641
|
data: e
|
|
642
642
|
});
|
|
643
643
|
}
|
|
644
|
-
function
|
|
644
|
+
function Xa(e) {
|
|
645
645
|
return b({
|
|
646
646
|
url: `${z()}/projects/${e.id}/merge_requests/${e.iid}`,
|
|
647
647
|
method: "get"
|
|
648
648
|
});
|
|
649
649
|
}
|
|
650
|
-
function
|
|
650
|
+
function Ya(e) {
|
|
651
651
|
return b({
|
|
652
652
|
url: `${z()}/projects/${e.id}/repository/branches`,
|
|
653
653
|
method: "post",
|
|
654
654
|
data: e
|
|
655
655
|
});
|
|
656
656
|
}
|
|
657
|
-
function
|
|
657
|
+
function Qa(e) {
|
|
658
658
|
return b({
|
|
659
659
|
url: `${z()}/projects/${e}/repository/branches`
|
|
660
660
|
});
|
|
661
661
|
}
|
|
662
|
-
function
|
|
662
|
+
function ei() {
|
|
663
663
|
const e = he("fe-groups.json");
|
|
664
664
|
return A(e) ? I.readJSONSync(e) : { groups: [] };
|
|
665
665
|
}
|
|
666
|
-
async function
|
|
667
|
-
const e = await
|
|
668
|
-
const n = e.find((
|
|
666
|
+
async function ti() {
|
|
667
|
+
const e = await Wa(), t = Qt.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((
|
|
674
|
+
}).filter((a) => !!a);
|
|
675
675
|
I.writeJSONSync(he("fe-groups.json"), { groups: t }, { spaces: 2 });
|
|
676
676
|
}
|
|
677
677
|
async function j(e) {
|
|
678
|
-
const t = `${B("FEServerDomain")}/api`,
|
|
678
|
+
const t = `${B("FEServerDomain")}/api`, a = await ne({
|
|
679
679
|
url: t + e.url,
|
|
680
680
|
headers: {
|
|
681
681
|
"the-key-one": "z-develop",
|
|
@@ -684,9 +684,9 @@ async function j(e) {
|
|
|
684
684
|
data: e.data,
|
|
685
685
|
method: e.method || "post"
|
|
686
686
|
});
|
|
687
|
-
return
|
|
687
|
+
return a.code !== 0 && p(`${a.code}: ${a.message}`), a.data;
|
|
688
688
|
}
|
|
689
|
-
async function
|
|
689
|
+
async function ai(e) {
|
|
690
690
|
const t = `${B("FEServerDomain")}/api`;
|
|
691
691
|
return await ne({
|
|
692
692
|
url: t + e.url,
|
|
@@ -698,12 +698,12 @@ async function ia(e) {
|
|
|
698
698
|
method: e.method || "post"
|
|
699
699
|
});
|
|
700
700
|
}
|
|
701
|
-
function
|
|
701
|
+
function ii() {
|
|
702
702
|
return j({
|
|
703
703
|
url: "/user/list2"
|
|
704
704
|
});
|
|
705
705
|
}
|
|
706
|
-
function
|
|
706
|
+
function ni() {
|
|
707
707
|
return j({
|
|
708
708
|
url: "/zen/testcase/product/list"
|
|
709
709
|
});
|
|
@@ -716,7 +716,7 @@ function ft(e) {
|
|
|
716
716
|
}
|
|
717
717
|
});
|
|
718
718
|
}
|
|
719
|
-
function
|
|
719
|
+
function si(e) {
|
|
720
720
|
return j({
|
|
721
721
|
url: "/zen/testcase/product/name",
|
|
722
722
|
data: {
|
|
@@ -724,7 +724,7 @@ function sa(e) {
|
|
|
724
724
|
}
|
|
725
725
|
});
|
|
726
726
|
}
|
|
727
|
-
function
|
|
727
|
+
function ri(e, t) {
|
|
728
728
|
return j({
|
|
729
729
|
url: "/zen/testcase/product/auto-case/list",
|
|
730
730
|
data: {
|
|
@@ -733,7 +733,7 @@ function ra(e, t) {
|
|
|
733
733
|
}
|
|
734
734
|
});
|
|
735
735
|
}
|
|
736
|
-
function
|
|
736
|
+
function oi(e) {
|
|
737
737
|
return j({
|
|
738
738
|
url: "/zen/testcase/step/list",
|
|
739
739
|
data: {
|
|
@@ -741,72 +741,72 @@ function oa(e) {
|
|
|
741
741
|
}
|
|
742
742
|
});
|
|
743
743
|
}
|
|
744
|
-
function
|
|
744
|
+
function ci(e) {
|
|
745
745
|
return j({
|
|
746
746
|
url: "/zen/testcase/module/create",
|
|
747
747
|
data: e
|
|
748
748
|
});
|
|
749
749
|
}
|
|
750
|
-
function
|
|
750
|
+
function ui(e) {
|
|
751
751
|
return j({
|
|
752
752
|
url: "/zen/testcase/create",
|
|
753
753
|
data: e
|
|
754
754
|
});
|
|
755
755
|
}
|
|
756
|
-
function
|
|
756
|
+
function li(e) {
|
|
757
757
|
return j({
|
|
758
758
|
url: "/zen/testcase/step/create",
|
|
759
759
|
data: e
|
|
760
760
|
});
|
|
761
761
|
}
|
|
762
|
-
function
|
|
762
|
+
function mi(e) {
|
|
763
763
|
return j({
|
|
764
764
|
url: "/zen/testcase/modules/remove",
|
|
765
765
|
data: e
|
|
766
766
|
});
|
|
767
767
|
}
|
|
768
|
-
function
|
|
768
|
+
function pi(e) {
|
|
769
769
|
return j({
|
|
770
770
|
url: "/zen/testcase/cases/remove",
|
|
771
771
|
data: e
|
|
772
772
|
});
|
|
773
773
|
}
|
|
774
|
-
function
|
|
774
|
+
function di(e) {
|
|
775
775
|
return j({
|
|
776
776
|
url: "/zen/testcase/module/update/name",
|
|
777
777
|
data: e
|
|
778
778
|
});
|
|
779
779
|
}
|
|
780
|
-
function
|
|
780
|
+
function fi(e) {
|
|
781
781
|
return j({
|
|
782
782
|
url: "/zen/testcase/case/update/name",
|
|
783
783
|
data: e
|
|
784
784
|
});
|
|
785
785
|
}
|
|
786
|
-
function
|
|
786
|
+
function gi(e) {
|
|
787
787
|
return j({
|
|
788
788
|
url: "/zen/testcase/case/update/priority",
|
|
789
789
|
data: e
|
|
790
790
|
});
|
|
791
791
|
}
|
|
792
|
-
function
|
|
792
|
+
function hi(e) {
|
|
793
793
|
return j({
|
|
794
794
|
url: "/zen/testcase/case/update/precondition",
|
|
795
795
|
data: e
|
|
796
796
|
});
|
|
797
797
|
}
|
|
798
|
-
function
|
|
798
|
+
function wi(e) {
|
|
799
799
|
return j({
|
|
800
800
|
url: "/zen/testcase/case/result/create",
|
|
801
801
|
data: e
|
|
802
802
|
});
|
|
803
803
|
}
|
|
804
|
-
function
|
|
804
|
+
function yi() {
|
|
805
805
|
return j({
|
|
806
806
|
url: "/zen/testcase/project/list"
|
|
807
807
|
});
|
|
808
808
|
}
|
|
809
|
-
function
|
|
809
|
+
function vi(e) {
|
|
810
810
|
return j({
|
|
811
811
|
url: "/zen/testcase/project/execution/list",
|
|
812
812
|
data: {
|
|
@@ -814,7 +814,7 @@ function va(e) {
|
|
|
814
814
|
}
|
|
815
815
|
});
|
|
816
816
|
}
|
|
817
|
-
function $
|
|
817
|
+
function $i(e) {
|
|
818
818
|
return j({
|
|
819
819
|
url: "/zen/testcase/execution/build/list",
|
|
820
820
|
data: {
|
|
@@ -822,32 +822,32 @@ function $a(e) {
|
|
|
822
822
|
}
|
|
823
823
|
});
|
|
824
824
|
}
|
|
825
|
-
function
|
|
825
|
+
function Ni(e) {
|
|
826
826
|
return j({
|
|
827
827
|
url: "/common/ai/talk",
|
|
828
828
|
data: e
|
|
829
829
|
});
|
|
830
830
|
}
|
|
831
|
-
function
|
|
832
|
-
return
|
|
831
|
+
function Ai(e) {
|
|
832
|
+
return ai({
|
|
833
833
|
url: "/common/notify/group/send",
|
|
834
834
|
data: e
|
|
835
835
|
});
|
|
836
836
|
}
|
|
837
|
-
function
|
|
837
|
+
function bi(e) {
|
|
838
838
|
return j({
|
|
839
839
|
url: "/deploy/create/chain",
|
|
840
840
|
data: e
|
|
841
841
|
});
|
|
842
842
|
}
|
|
843
|
-
function
|
|
844
|
-
const
|
|
843
|
+
function ji(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 = ge("weWorkListCache"),
|
|
849
|
-
|
|
850
|
-
const o =
|
|
848
|
+
const n = ge("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
|
|
@@ -857,48 +857,48 @@ function ja(e, t) {
|
|
|
857
857
|
}), oe();
|
|
858
858
|
}
|
|
859
859
|
async function gt() {
|
|
860
|
-
const t = (await
|
|
860
|
+
const t = (await ii()).filter((s) => [1, 2, 3, 4, 5].includes(s.title)).map((s) => ({
|
|
861
861
|
name: `${s.nick} - ${Yt[s.title]}`,
|
|
862
862
|
value: s.weWorkUserId
|
|
863
|
-
})),
|
|
863
|
+
})), a = ge("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 ht(e, t,
|
|
872
|
+
async function ht(e, t, a) {
|
|
873
873
|
const n = await gt();
|
|
874
|
-
let
|
|
874
|
+
let i = await H({
|
|
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], ji(i, n), i;
|
|
884
884
|
}
|
|
885
|
-
async function
|
|
886
|
-
const { groups: n } = await pt(),
|
|
885
|
+
async function Si(e, t, a) {
|
|
886
|
+
const { groups: n } = await pt(), i = n.map((o) => ({
|
|
887
887
|
name: o.name,
|
|
888
888
|
value: o.url
|
|
889
889
|
}));
|
|
890
890
|
let s = await H({
|
|
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 ki() {
|
|
902
902
|
try {
|
|
903
903
|
rt() && (await Xe({
|
|
904
904
|
message: "系统中已存在z的配置文件,确认重新配置?"
|
|
@@ -920,17 +920,17 @@ async function ka() {
|
|
|
920
920
|
}
|
|
921
921
|
]
|
|
922
922
|
});
|
|
923
|
-
let
|
|
923
|
+
let a = await U({
|
|
924
924
|
message: "请输入LDAP账号:"
|
|
925
925
|
});
|
|
926
|
-
|
|
926
|
+
a = a.trim();
|
|
927
927
|
let n = await Ot({
|
|
928
928
|
message: "请输入LDAP密码:",
|
|
929
929
|
mask: !0
|
|
930
930
|
});
|
|
931
|
-
n = n.trim(), J("jobType", t), J("ldapAccount",
|
|
932
|
-
const
|
|
933
|
-
je(
|
|
931
|
+
n = n.trim(), J("jobType", t), J("ldapAccount", a), J("ldapPassword", n);
|
|
932
|
+
const i = await De();
|
|
933
|
+
je(i);
|
|
934
934
|
const s = await gt(), o = await ht("请选择你自己(用于企微通知):", (u) => u.length > 1 ? "只能选一个" : u.length < 1 ? "请选一个" : !0), { name: r, value: c } = s.find((u) => u.value === o[0]);
|
|
935
935
|
J({
|
|
936
936
|
weWorkName: r,
|
|
@@ -941,32 +941,32 @@ async function ka() {
|
|
|
941
941
|
}
|
|
942
942
|
const e = y("配置信息初始化中").start();
|
|
943
943
|
try {
|
|
944
|
-
const t = await
|
|
944
|
+
const t = await _a();
|
|
945
945
|
J({
|
|
946
946
|
gitUserId: t.id,
|
|
947
947
|
gitName: t.name,
|
|
948
948
|
gitEnglishName: t.username,
|
|
949
949
|
gitEmail: t.email
|
|
950
|
-
}), me("latestCheckVersionTimestamp", Date.now()), oe(), C("jobType") === ue.FRONT_END && await
|
|
950
|
+
}), me("latestCheckVersionTimestamp", Date.now()), oe(), C("jobType") === ue.FRONT_END && await ti(), e.succeed("配置信息初始化完成"), process.exit(0);
|
|
951
951
|
} catch (t) {
|
|
952
952
|
e.fail("配置信息初始化失败"), le.isAxiosError(t) && p("请检查你的域名及令牌配置"), p(t);
|
|
953
953
|
}
|
|
954
954
|
}
|
|
955
|
-
async function
|
|
956
|
-
await D(Ne(), "", { mode: 493 }), await D(
|
|
957
|
-
`, { mode: 493 }), await D(
|
|
958
|
-
z run commit-msg`, { mode: 493 }), await D(
|
|
955
|
+
async function Ei() {
|
|
956
|
+
await D(Ne(), "", { mode: 493 }), await D(T(".gitignore"), `.commit-msg-tpl
|
|
957
|
+
`, { mode: 493 }), await D(T("commit-msg"), `#!/usr/bin/env sh
|
|
958
|
+
z run commit-msg`, { mode: 493 }), await D(T("pre-commit"), `#!/usr/bin/env sh
|
|
959
959
|
z run commit-files`, { mode: 493 });
|
|
960
|
-
const { language: e } =
|
|
960
|
+
const { language: e } = ie();
|
|
961
961
|
if ([w.JAVASCRIPT, w.MARKDOWN].includes(e) && (await D(
|
|
962
|
-
|
|
963
|
-
`${JSON.stringify(await
|
|
962
|
+
T(".prettierrc.json"),
|
|
963
|
+
`${JSON.stringify(await Ja(), null, 2)}
|
|
964
964
|
`,
|
|
965
965
|
{
|
|
966
966
|
mode: 493
|
|
967
967
|
}
|
|
968
|
-
), await D(
|
|
969
|
-
await
|
|
968
|
+
), await D(T(".prettierignore"), await Fa(), { mode: 493 }), await D(T("tsconfig.node.json"), await za(), { mode: 493 }), await D(T("tsconfig.browser.json"), await Ma(), { mode: 493 })), e === w.JAVA) {
|
|
969
|
+
await Pa(`${B("FECDNDomain")}/file/vgnlfbfHRF.jar`, T("checkstyle.jar")), await D(T("checkstyle.xml"), await Ga(), { mode: 493 });
|
|
970
970
|
const t = m.join("package.json");
|
|
971
971
|
A(t) || await D(t, JSON.stringify({ version: "0.0.1" }, null, 2), {
|
|
972
972
|
mode: 493
|
|
@@ -974,9 +974,9 @@ z run commit-files`, { mode: 493 });
|
|
|
974
974
|
}
|
|
975
975
|
st();
|
|
976
976
|
}
|
|
977
|
-
async function
|
|
978
|
-
const
|
|
979
|
-
|
|
977
|
+
async function Ti(e, t) {
|
|
978
|
+
const a = await d("git remote get-url --push origin");
|
|
979
|
+
a || p("获取项目远程git地址失败,请配置后重试");
|
|
980
980
|
let n = e;
|
|
981
981
|
n || (n = await k({
|
|
982
982
|
message: "请选择项目语言",
|
|
@@ -999,55 +999,55 @@ async function Ea(e, t) {
|
|
|
999
999
|
}
|
|
1000
1000
|
]
|
|
1001
1001
|
}));
|
|
1002
|
-
let
|
|
1003
|
-
if (!
|
|
1004
|
-
const s = ee(
|
|
1002
|
+
let i = t;
|
|
1003
|
+
if (!i) {
|
|
1004
|
+
const s = ee(a), o = await dt(s);
|
|
1005
1005
|
if (!o)
|
|
1006
|
-
return p(`未找到项目,请确认项目${
|
|
1007
|
-
|
|
1006
|
+
return p(`未找到项目,请确认项目${a}是否存在,或者当前账号权限`);
|
|
1007
|
+
i = o.namespace.full_path;
|
|
1008
1008
|
}
|
|
1009
1009
|
mt({
|
|
1010
1010
|
language: n,
|
|
1011
|
-
"lint-staged":
|
|
1011
|
+
"lint-staged": wa[n],
|
|
1012
1012
|
repository: {
|
|
1013
|
-
url:
|
|
1014
|
-
group:
|
|
1013
|
+
url: a,
|
|
1014
|
+
group: i
|
|
1015
1015
|
}
|
|
1016
1016
|
});
|
|
1017
1017
|
}
|
|
1018
1018
|
async function Le(e, t) {
|
|
1019
|
-
e ? L.rm("-rf", Q) : A(
|
|
1019
|
+
e ? L.rm("-rf", Q) : A(T()) && (await Xe({
|
|
1020
1020
|
message: `当前项目中已存在配置文件夹${Q},确认重新配置?`
|
|
1021
|
-
}) ? L.rm("-rf", Q) : process.exit(0)), await pe(
|
|
1022
|
-
const
|
|
1023
|
-
await
|
|
1021
|
+
}) ? L.rm("-rf", Q) : process.exit(0)), await pe(T(), { recursive: !0 }), await Ti(e, t);
|
|
1022
|
+
const a = y("项目初始化中...").start();
|
|
1023
|
+
await Ei(), a.succeed("项目初始化完成");
|
|
1024
1024
|
}
|
|
1025
|
-
async function
|
|
1026
|
-
A(
|
|
1025
|
+
async function Ri() {
|
|
1026
|
+
A(T()) && A(Ne()) ? st() : await Le(), process.exit(0);
|
|
1027
1027
|
}
|
|
1028
|
-
async function
|
|
1029
|
-
t.projectLanguage && !Object.values(w).includes(t.projectLanguage) && p("项目语言不支持"), e ? (K(), e === "." ? (await Le(t.projectLanguage, void 0), process.exit(0)) : e === "prepare" ? await
|
|
1028
|
+
async function Ii(e, t) {
|
|
1029
|
+
t.projectLanguage && !Object.values(w).includes(t.projectLanguage) && p("项目语言不支持"), e ? (K(), e === "." ? (await Le(t.projectLanguage, void 0), process.exit(0)) : e === "prepare" ? await Ri() : p("参数错误。执行 z init -h 查看帮助。")) : await ki();
|
|
1030
1030
|
}
|
|
1031
|
-
P.command("init").alias("i").description("初始化工具配置、项目配置").argument("[type]", "非必填。不传为初始化全局配置;传 . 为初始化当前项目;传 prepare 为初始化GIT HOOKS").option("--project-language", `项目语言。可选值:${Object.values(w).join("/")} `).action((...e) => M(
|
|
1032
|
-
async function
|
|
1031
|
+
P.command("init").alias("i").description("初始化工具配置、项目配置").argument("[type]", "非必填。不传为初始化全局配置;传 . 为初始化当前项目;传 prepare 为初始化GIT HOOKS").option("--project-language", `项目语言。可选值:${Object.values(w).join("/")} `).action((...e) => M(Ii, ...e));
|
|
1032
|
+
async function Ci(e, t) {
|
|
1033
1033
|
if (!e)
|
|
1034
1034
|
return "不能为空";
|
|
1035
1035
|
if (!/^[a-z0-9-]+$/.test(e))
|
|
1036
1036
|
return "格式为小写字母、中横线(可选)、数字(不推荐)。如apple, apple-tree";
|
|
1037
1037
|
if (ut().includes(e))
|
|
1038
1038
|
return "当前目录下已存在同名文件夹,请先处理。";
|
|
1039
|
-
const
|
|
1040
|
-
return
|
|
1039
|
+
const i = (await qa(e)).find((s) => s.path_with_namespace === `${t}/${e}`);
|
|
1040
|
+
return i ? `远程仓库中已存在同名项目(${i.http_url_to_repo}),请更名后重试` : !0;
|
|
1041
1041
|
}
|
|
1042
|
-
function
|
|
1042
|
+
function xi(e) {
|
|
1043
1043
|
return e ? !0 : "不能为空";
|
|
1044
1044
|
}
|
|
1045
|
-
function
|
|
1045
|
+
function Pi(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 Di(e) {
|
|
1049
|
+
ae(), K(), await be();
|
|
1050
|
+
let t, a;
|
|
1051
1051
|
e.branchType ? t = e.branchType : t = await k({
|
|
1052
1052
|
message: "请选择创建分支的类型",
|
|
1053
1053
|
choices: [
|
|
@@ -1064,36 +1064,36 @@ async function Da(e) {
|
|
|
1064
1064
|
value: de.REFACTOR
|
|
1065
1065
|
}
|
|
1066
1066
|
]
|
|
1067
|
-
}), e.branchPurpose ?
|
|
1067
|
+
}), e.branchPurpose ? a = e.branchPurpose : (a = await U({
|
|
1068
1068
|
message: "请输入创建分支的目的(大小写字母、数字,小驼峰式命名。如userInfo)",
|
|
1069
|
-
validate:
|
|
1070
|
-
}),
|
|
1071
|
-
const n = `${t}_${
|
|
1069
|
+
validate: Pi
|
|
1070
|
+
}), a = a.trim());
|
|
1071
|
+
const n = `${t}_${a}_${lt()}`;
|
|
1072
1072
|
await d(`git fetch origin ${$.MASTER}`), await d(`git checkout -b ${n} origin/${$.MASTER}`), await d(`git push -u origin ${n}`), process.exit(0);
|
|
1073
1073
|
}
|
|
1074
1074
|
const wt = (e) => `${B("ZenTaoDomain")}${e}`;
|
|
1075
|
-
async function
|
|
1075
|
+
async function Li() {
|
|
1076
1076
|
const e = await $e({
|
|
1077
1077
|
url: wt("/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
|
|
1088
|
+
async function Oi() {
|
|
1089
1089
|
const e = await $e({
|
|
1090
1090
|
url: wt("/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
|
})) : [];
|
|
@@ -1103,42 +1103,42 @@ const Ce = async () => (await U({
|
|
|
1103
1103
|
validate: (t) => t.length === 0 ? "请输入commit msg" : !0
|
|
1104
1104
|
})).trim();
|
|
1105
1105
|
async function qe(e, t) {
|
|
1106
|
-
const
|
|
1107
|
-
|
|
1108
|
-
const n =
|
|
1106
|
+
const a = await d("git diff --name-only HEAD");
|
|
1107
|
+
a || p("git暂存区没有内容,请先git add添加文件到暂存区");
|
|
1108
|
+
const n = a.replace(/\r\n/g, `
|
|
1109
1109
|
`).split(`
|
|
1110
|
-
`).filter(Boolean),
|
|
1110
|
+
`).filter(Boolean), i = [];
|
|
1111
1111
|
for (const r of n)
|
|
1112
1112
|
try {
|
|
1113
1113
|
const c = m.normalize(r), u = await He(c);
|
|
1114
|
-
u.isFile() && u.size <
|
|
1114
|
+
u.isFile() && u.size < aa && i.push(r);
|
|
1115
1115
|
} catch {
|
|
1116
1116
|
}
|
|
1117
|
-
if (
|
|
1117
|
+
if (i.length === 0)
|
|
1118
1118
|
return We("文件太大,无法生成commit msg"), t.stop(), await Ce();
|
|
1119
|
-
const s = await d(`git diff HEAD -- ${
|
|
1119
|
+
const s = await d(`git diff HEAD -- ${i.map((r) => `"${r}"`).join(" ")}`);
|
|
1120
1120
|
if (!s)
|
|
1121
1121
|
return We("无法获取文件差异信息"), t.stop(), await Ce();
|
|
1122
|
-
const o = await
|
|
1122
|
+
const o = await Ni({
|
|
1123
1123
|
type: "commit-message-v2",
|
|
1124
1124
|
input: s
|
|
1125
1125
|
// modelName: "qwen-turbo",
|
|
1126
1126
|
});
|
|
1127
1127
|
return e + o;
|
|
1128
1128
|
}
|
|
1129
|
-
async function
|
|
1129
|
+
async function Te(e, t, a) {
|
|
1130
1130
|
const n = y("🤖 生成提交信息中...").start();
|
|
1131
|
-
let
|
|
1131
|
+
let i = "", s = !0;
|
|
1132
1132
|
if ([S.FEAT, S.FIX, S.REFACTOR].includes(e)) {
|
|
1133
1133
|
const o = t.map((r) => r.value).join(",");
|
|
1134
|
-
if (
|
|
1134
|
+
if (a || (i = await qe(`${e}(${o}): `, n)), !i) {
|
|
1135
1135
|
const r = t.map((c) => c.name).join(";");
|
|
1136
|
-
|
|
1136
|
+
i = `${e}(${o}): ${r}`, s = !1;
|
|
1137
1137
|
}
|
|
1138
1138
|
}
|
|
1139
|
-
e === S.CHORE && (t ?
|
|
1139
|
+
e === S.CHORE && (t ? i = `${e}: ${t}` : i = await qe(`${e}: `, n)), await D(Ne(), i, "utf-8"), s || a ? n.succeed("提交信息已生成(↓),可以进行提交了!") : n.warn("AI生成提交信息失败,已使用默认模板(↓),可以进行提交了!"), console.log(N.yellow(i));
|
|
1140
1140
|
}
|
|
1141
|
-
async function
|
|
1141
|
+
async function Mi(e) {
|
|
1142
1142
|
const t = await k({
|
|
1143
1143
|
message: "请选择你要创建的模板类型",
|
|
1144
1144
|
choices: [
|
|
@@ -1161,58 +1161,58 @@ async function Ma(e) {
|
|
|
1161
1161
|
]
|
|
1162
1162
|
});
|
|
1163
1163
|
if ([S.FEAT, S.REFACTOR].includes(t)) {
|
|
1164
|
-
const
|
|
1165
|
-
if (!
|
|
1164
|
+
const a = await Li();
|
|
1165
|
+
if (!a.length)
|
|
1166
1166
|
return q("🤷 暂无开发任务");
|
|
1167
1167
|
const n = await ve({
|
|
1168
1168
|
message: "请关联开发任务(可多选):",
|
|
1169
|
-
validate: (
|
|
1170
|
-
choices:
|
|
1171
|
-
...
|
|
1172
|
-
name: `[${
|
|
1169
|
+
validate: (i) => i.length === 0 ? "请选择项" : !0,
|
|
1170
|
+
choices: a.map((i) => ({
|
|
1171
|
+
...i,
|
|
1172
|
+
name: `[${i.value.value}]: ${i.name}`
|
|
1173
1173
|
})),
|
|
1174
|
-
pageSize:
|
|
1174
|
+
pageSize: a.length
|
|
1175
1175
|
});
|
|
1176
|
-
await
|
|
1176
|
+
await Te(S.FEAT, n, e);
|
|
1177
1177
|
}
|
|
1178
1178
|
if (t === S.FIX) {
|
|
1179
|
-
const
|
|
1180
|
-
if (!
|
|
1179
|
+
const a = await Oi();
|
|
1180
|
+
if (!a.length)
|
|
1181
1181
|
return q("🤷 暂无BUG");
|
|
1182
1182
|
const n = await ve({
|
|
1183
1183
|
message: "请关联Bug(可多选):",
|
|
1184
|
-
validate: (
|
|
1185
|
-
choices:
|
|
1186
|
-
...
|
|
1187
|
-
name: `[${
|
|
1184
|
+
validate: (i) => i.length === 0 ? "请选择项" : !0,
|
|
1185
|
+
choices: a.map((i) => ({
|
|
1186
|
+
...i,
|
|
1187
|
+
name: `[${i.value.value}]: ${i.name}`
|
|
1188
1188
|
})),
|
|
1189
|
-
pageSize:
|
|
1189
|
+
pageSize: a.length
|
|
1190
1190
|
});
|
|
1191
|
-
await
|
|
1191
|
+
await Te(S.FIX, n, e);
|
|
1192
1192
|
}
|
|
1193
1193
|
if (t === S.CHORE) {
|
|
1194
|
-
let
|
|
1195
|
-
e && (
|
|
1194
|
+
let a = "";
|
|
1195
|
+
e && (a = await Ce()), await Te(S.CHORE, a);
|
|
1196
1196
|
}
|
|
1197
1197
|
process.exit(0);
|
|
1198
1198
|
}
|
|
1199
|
-
async function
|
|
1199
|
+
async function zi() {
|
|
1200
1200
|
try {
|
|
1201
1201
|
const e = {}, t = async () => {
|
|
1202
|
-
const O = ut(), { projects: se } = await
|
|
1202
|
+
const O = ut(), { projects: se } = await Da(), X = se.map((ce) => {
|
|
1203
1203
|
const Je = {
|
|
1204
1204
|
name: `${ce.name} [${ce.desc}]`,
|
|
1205
1205
|
value: ce.name,
|
|
1206
1206
|
disabled: !1
|
|
1207
1207
|
};
|
|
1208
1208
|
return O.includes(ce.name) && (Je.disabled = "目录下已存在同名文件夹"), Je;
|
|
1209
|
-
}),
|
|
1209
|
+
}), Et = await k({
|
|
1210
1210
|
message: "请选择一个项目模板",
|
|
1211
1211
|
choices: X
|
|
1212
|
-
}),
|
|
1213
|
-
e.tplName =
|
|
1214
|
-
},
|
|
1215
|
-
const { groups: O } =
|
|
1212
|
+
}), Ee = se.find((ce) => ce.name === Et);
|
|
1213
|
+
e.tplName = Ee.name, e.tplUrl = Ee.url, e.tplLanguage = Ee.language;
|
|
1214
|
+
}, a = async () => {
|
|
1215
|
+
const { groups: O } = ei(), se = await k({
|
|
1216
1216
|
message: "请选择一个分组",
|
|
1217
1217
|
choices: O.map((X) => ({
|
|
1218
1218
|
name: `${X.name} [${X.description}]`,
|
|
@@ -1227,17 +1227,17 @@ async function za() {
|
|
|
1227
1227
|
}, n = async () => {
|
|
1228
1228
|
e.projectName = await U({
|
|
1229
1229
|
message: "请输入项目名称",
|
|
1230
|
-
validate: (O) =>
|
|
1230
|
+
validate: (O) => Ci(O, e.group?.name || "")
|
|
1231
1231
|
}), e.projectName = e.projectName.trim(), e.projectDesc = await U({
|
|
1232
1232
|
message: "请输入项目描述",
|
|
1233
|
-
validate:
|
|
1233
|
+
validate: xi
|
|
1234
1234
|
}), e.projectDesc = e.projectDesc.trim();
|
|
1235
1235
|
};
|
|
1236
|
-
await t(), await
|
|
1237
|
-
const
|
|
1238
|
-
await d(`git clone --depth=1 ${e.tplUrl}`), await Ke(e.tplName, e.projectName), L.cd(e.projectName), L.rm("-rf", ".git"), await d(`git init --initial-branch=${$.MASTER}`), await d(`git remote add origin ${
|
|
1236
|
+
await t(), await a(), await n();
|
|
1237
|
+
const i = `${fe}/${e.group?.name}/${e.projectName}.git`, s = y("模版初始化中").start();
|
|
1238
|
+
await d(`git clone --depth=1 ${e.tplUrl}`), await Ke(e.tplName, e.projectName), L.cd(e.projectName), L.rm("-rf", ".git"), await d(`git init --initial-branch=${$.MASTER}`), await d(`git remote add origin ${i}`), await d(`git config user.name ${C("gitName")}`), await d(`git config user.email ${C("gitEmail")}`);
|
|
1239
1239
|
const o = Pe();
|
|
1240
|
-
|
|
1240
|
+
Ta({
|
|
1241
1241
|
...o,
|
|
1242
1242
|
name: e.projectName,
|
|
1243
1243
|
description: e.projectDesc,
|
|
@@ -1245,22 +1245,22 @@ async function za() {
|
|
|
1245
1245
|
...o.scripts,
|
|
1246
1246
|
prepare: "[ -n '$z' ] && z init prepare || echo 'Warning: z not exist at global'"
|
|
1247
1247
|
}
|
|
1248
|
-
}), await I.writeFile(m.resolve("README.md"),
|
|
1248
|
+
}), await I.writeFile(m.resolve("README.md"), ha(e.projectName, e.projectDesc)), s.succeed("模版初始化完成"), await Le(e.tplLanguage, e.group?.name);
|
|
1249
1249
|
const r = y("依赖安装中").start();
|
|
1250
1250
|
await d("npm install --registry https://registry.npmmirror.com/"), r.succeed("依赖安装完成");
|
|
1251
1251
|
const c = y("项目推送中").start();
|
|
1252
1252
|
await d('git add . && git commit -m "chore: 项目初始化"'), await d("git tag v0.0.1");
|
|
1253
|
-
const u = await
|
|
1253
|
+
const u = await Va({
|
|
1254
1254
|
name: e.projectName,
|
|
1255
1255
|
description: e.projectDesc,
|
|
1256
1256
|
path: e.projectName,
|
|
1257
1257
|
visibility: "private",
|
|
1258
1258
|
namespace_id: e.group?.id
|
|
1259
1259
|
});
|
|
1260
|
-
await d(`git push -u origin ${$.MASTER}`), await d(`git push origin HEAD:${$.MASTER} --tags`), c.succeed(`项目已推送到远程,地址: ${N.blue(
|
|
1260
|
+
await d(`git push -u origin ${$.MASTER}`), await d(`git push origin HEAD:${$.MASTER} --tags`), c.succeed(`项目已推送到远程,地址: ${N.blue(i)}`);
|
|
1261
1261
|
const l = y("初始化分支中").start(), f = `feat_init_${lt()}`, h = [$.DEV, $.TEST, $.RELEASE, f], g = await Promise.allSettled(
|
|
1262
1262
|
h.map(
|
|
1263
|
-
(O) =>
|
|
1263
|
+
(O) => Ya({
|
|
1264
1264
|
id: u.id,
|
|
1265
1265
|
branch: O,
|
|
1266
1266
|
ref: $.MASTER
|
|
@@ -1276,21 +1276,21 @@ async function za() {
|
|
|
1276
1276
|
p(e);
|
|
1277
1277
|
}
|
|
1278
1278
|
}
|
|
1279
|
-
async function
|
|
1280
|
-
let
|
|
1279
|
+
async function Fi(e, t) {
|
|
1280
|
+
let a;
|
|
1281
1281
|
e ? [
|
|
1282
1282
|
"project",
|
|
1283
1283
|
"pr"
|
|
1284
1284
|
/* ProjectAbbr */
|
|
1285
|
-
].includes(e) ?
|
|
1285
|
+
].includes(e) ? a = "project" : [
|
|
1286
1286
|
"branch",
|
|
1287
1287
|
"b"
|
|
1288
1288
|
/* BranchAbbr */
|
|
1289
|
-
].includes(e) ?
|
|
1289
|
+
].includes(e) ? a = "branch" : [
|
|
1290
1290
|
"commit-msg",
|
|
1291
1291
|
"cm"
|
|
1292
1292
|
/* CommitMsgAbbr */
|
|
1293
|
-
].includes(e) ?
|
|
1293
|
+
].includes(e) ? a = "commit-msg" : p("参数输入错误") : a = await k({
|
|
1294
1294
|
message: "请选择你要创建的类型",
|
|
1295
1295
|
choices: [
|
|
1296
1296
|
{
|
|
@@ -1309,52 +1309,52 @@ async function Fa(e, t) {
|
|
|
1309
1309
|
/* Project */
|
|
1310
1310
|
}
|
|
1311
1311
|
]
|
|
1312
|
-
}),
|
|
1312
|
+
}), a === "project" ? await zi() : (ae(), K(), a === "branch" ? await Di(t) : a === "commit-msg" && (await d("git status -s") ? await Mi(t.commitMessageCloseAi) : p("没有要变动的文件,无法生成提交信息")));
|
|
1313
1313
|
}
|
|
1314
|
-
P.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(
|
|
1315
|
-
const
|
|
1316
|
-
const t = await
|
|
1314
|
+
P.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(Fi, ...e));
|
|
1315
|
+
const Ji = async (e) => {
|
|
1316
|
+
const t = await xa(), a = C("weWorkUserId"), { notifyUsers: n, notifyGroups: i, ...s } = e, o = y("部署任务创建中").start(), r = await bi({
|
|
1317
1317
|
...s,
|
|
1318
1318
|
userToken: t,
|
|
1319
|
-
userWeworkId:
|
|
1320
|
-
notifyUsers: [.../* @__PURE__ */ new Set([
|
|
1321
|
-
notifyGroups:
|
|
1319
|
+
userWeworkId: a,
|
|
1320
|
+
notifyUsers: [.../* @__PURE__ */ new Set([a, ...n])].join(Ie),
|
|
1321
|
+
notifyGroups: i.join(Ie)
|
|
1322
1322
|
});
|
|
1323
1323
|
s.moduleNames.length > 1 ? (o.succeed(`多模块部署任务创建完成,共 ${s.moduleNames.length} 个模块`), o.succeed(`当前已创建首个模块 ${N.blue(s.moduleNames[0])} 的 k8s 地址:`), console.log(N.blue(r)), o.info("后续模块会在前一个模块完成后依次部署,并通过企微通知下发对应地址。")) : (o.succeed("部署任务创建完成"), console.log(`如有需要,可在k8s中查看 ${N.blue(r)}`));
|
|
1324
1324
|
};
|
|
1325
|
-
function
|
|
1326
|
-
const
|
|
1327
|
-
if (
|
|
1328
|
-
const
|
|
1329
|
-
|
|
1325
|
+
function Ui(e, t) {
|
|
1326
|
+
const a = Pe();
|
|
1327
|
+
if (ie()?.repository?.url || p(".z/project.json中缺少repository.url"), t === V.H5) {
|
|
1328
|
+
const i = `build:${e}`;
|
|
1329
|
+
a?.scripts[i] || p(`项目package.json文件scripts不存在命令${i}。`);
|
|
1330
1330
|
}
|
|
1331
|
-
t === V.NPM && (
|
|
1331
|
+
t === V.NPM && (a?.scripts.build || p("项目package.json文件scripts不存在命令build。")), t === V.SERVER && (a?.scripts.build || p("项目package.json文件scripts不存在命令build。"));
|
|
1332
1332
|
}
|
|
1333
1333
|
async function yt(e, t) {
|
|
1334
|
-
|
|
1335
|
-
let
|
|
1336
|
-
const
|
|
1337
|
-
if (
|
|
1334
|
+
ae(), K();
|
|
1335
|
+
let a = e, n = t.platform;
|
|
1336
|
+
const i = ie();
|
|
1337
|
+
if (i.language === w.JAVA && (n = V.SERVER), a && !Object.values($).includes(a) && p("仅支持发布指定环境分支"), n && !Object.values(V).includes(n) && p("发布平台错误"), n || (n = await k({
|
|
1338
1338
|
message: "请选择平台",
|
|
1339
1339
|
choices: Xt
|
|
1340
|
-
})), n === V.NPM && (
|
|
1340
|
+
})), n === V.NPM && (a = $.MASTER), !a) {
|
|
1341
1341
|
const u = await k({
|
|
1342
1342
|
message: "请选择部署环境",
|
|
1343
|
-
choices:
|
|
1343
|
+
choices: at
|
|
1344
1344
|
});
|
|
1345
|
-
|
|
1345
|
+
a = fa(u);
|
|
1346
1346
|
}
|
|
1347
1347
|
let s = "";
|
|
1348
|
-
|
|
1348
|
+
i.language === w.JAVASCRIPT && (s = ea);
|
|
1349
1349
|
const o = [];
|
|
1350
|
-
if (
|
|
1350
|
+
if (i.language === w.JAVASCRIPT) {
|
|
1351
1351
|
let u = "";
|
|
1352
1352
|
const l = Pe();
|
|
1353
1353
|
l.name.startsWith("@") && l.name.includes("/") ? u = l.name.split("/").pop() || "" : u = l.name, u && o.push(u);
|
|
1354
1354
|
}
|
|
1355
|
-
if (
|
|
1356
|
-
const { projects: u } = await
|
|
1357
|
-
(f) => ee(f.url) === ee(
|
|
1355
|
+
if (i.language === w.JAVA) {
|
|
1356
|
+
const { projects: u } = await La(), l = u.find(
|
|
1357
|
+
(f) => ee(f.url) === ee(i.repository.url)
|
|
1358
1358
|
);
|
|
1359
1359
|
if (!l)
|
|
1360
1360
|
p("未找到项目对应的模块信息");
|
|
@@ -1389,25 +1389,25 @@ async function yt(e, t) {
|
|
|
1389
1389
|
let r = [];
|
|
1390
1390
|
t.skipSelectionNotification || (r = await ht("请选择部署成功要通知的人员:", () => !0, !0));
|
|
1391
1391
|
let c = [];
|
|
1392
|
-
if (t.skipGroupNotification || (c = await
|
|
1393
|
-
const u =
|
|
1394
|
-
|
|
1392
|
+
if (t.skipGroupNotification || (c = await Si("请选择部署成功要通知的群组:", () => !0, !0)), i.language === w.JAVASCRIPT) {
|
|
1393
|
+
const u = da(a);
|
|
1394
|
+
Ui(u, n);
|
|
1395
1395
|
}
|
|
1396
|
-
await
|
|
1396
|
+
await Ji({
|
|
1397
1397
|
moduleNames: o,
|
|
1398
1398
|
k8sGroupName: s,
|
|
1399
|
-
branchName:
|
|
1399
|
+
branchName: a,
|
|
1400
1400
|
notifyUsers: r,
|
|
1401
1401
|
notifyGroups: c
|
|
1402
1402
|
});
|
|
1403
1403
|
}
|
|
1404
|
-
async function vt(e, t,
|
|
1405
|
-
const
|
|
1404
|
+
async function vt(e, t, a, n) {
|
|
1405
|
+
const i = y(`分支合并中,${e} -> ${t}`).start();
|
|
1406
1406
|
let s = 0;
|
|
1407
1407
|
try {
|
|
1408
|
-
const { iid: r } = await
|
|
1408
|
+
const { iid: r } = await Za({
|
|
1409
1409
|
title: `${e} -> ${t} by z-develop`,
|
|
1410
|
-
id:
|
|
1410
|
+
id: a.id,
|
|
1411
1411
|
source_branch: e,
|
|
1412
1412
|
target_branch: t,
|
|
1413
1413
|
// 合到主分支上的分支需要在合并完成后被移除
|
|
@@ -1415,60 +1415,60 @@ async function vt(e, t, i, n) {
|
|
|
1415
1415
|
});
|
|
1416
1416
|
s = r;
|
|
1417
1417
|
} catch (r) {
|
|
1418
|
-
le.isAxiosError(r) && r?.response?.status === 409 && p(`存在重复的合并请求,前往查看${
|
|
1418
|
+
le.isAxiosError(r) && r?.response?.status === 409 && p(`存在重复的合并请求,前往查看${a.mergeRequestUrl}`), p(r);
|
|
1419
1419
|
}
|
|
1420
1420
|
const o = async () => {
|
|
1421
1421
|
try {
|
|
1422
1422
|
await new Promise((r) => {
|
|
1423
1423
|
setTimeout(r, 5e3);
|
|
1424
|
-
}), await
|
|
1425
|
-
id:
|
|
1424
|
+
}), await Ha({
|
|
1425
|
+
id: a.id,
|
|
1426
1426
|
iid: s
|
|
1427
|
-
}),
|
|
1427
|
+
}), i.succeed(`分支${e}已合并到分支${t}`);
|
|
1428
1428
|
} catch (r) {
|
|
1429
1429
|
le.isAxiosError(r) || p(r);
|
|
1430
1430
|
const c = r?.response?.status;
|
|
1431
1431
|
if (c === 406)
|
|
1432
1432
|
return await o();
|
|
1433
|
-
if (await
|
|
1434
|
-
id:
|
|
1433
|
+
if (await Ka({
|
|
1434
|
+
id: a.id,
|
|
1435
1435
|
iid: s,
|
|
1436
1436
|
state_event: "close"
|
|
1437
1437
|
}), c === 405) {
|
|
1438
|
-
const u = await
|
|
1439
|
-
id:
|
|
1438
|
+
const u = await Xa({
|
|
1439
|
+
id: a.id,
|
|
1440
1440
|
iid: s
|
|
1441
1441
|
});
|
|
1442
1442
|
if (u.merge_status === "cannot_be_merged" && u.diff_refs.base_sha === u.diff_refs.head_sha) {
|
|
1443
|
-
|
|
1443
|
+
i.warn("MR已关闭。判定为空的合并请求(没有新内容),可继续进行部署");
|
|
1444
1444
|
return;
|
|
1445
1445
|
}
|
|
1446
1446
|
}
|
|
1447
|
-
|
|
1447
|
+
i.fail("合并过程中出现冲突,MR已关闭。建议在本地完成合并。"), process.exit(1);
|
|
1448
1448
|
}
|
|
1449
1449
|
};
|
|
1450
1450
|
await o();
|
|
1451
1451
|
}
|
|
1452
|
-
async function
|
|
1453
|
-
const
|
|
1454
|
-
`git log ${n}...${
|
|
1452
|
+
async function Bi(e, t) {
|
|
1453
|
+
const a = `origin/${e.sourceBranch}`, n = await d(`git log -b origin/${$.MASTER} -1 --format=%H`), i = await d(`git log -b origin/${e.sourceBranch} -1 --format=%H`), s = await d(
|
|
1454
|
+
`git log ${n}...${i} -b ${a}`
|
|
1455
1455
|
);
|
|
1456
1456
|
if (s || p(`分支${e.sourceBranch}上不存在新的commit,不需要合并。`), await d(
|
|
1457
|
-
`git branch --contains ${n} -r ${
|
|
1457
|
+
`git branch --contains ${n} -r ${a}`
|
|
1458
1458
|
) || (console.log(N.yellow("注意:当前分支上不存在远程主分支最新代码,将在自动合入后继续。")), await vt($.MASTER, e.sourceBranch, e)), t === $.MASTER) {
|
|
1459
1459
|
const r = s.split(`
|
|
1460
|
-
`).filter((f) => f), c = await d(`git log -b origin/${
|
|
1461
|
-
`git log ${n}...${c} -b origin/${
|
|
1460
|
+
`).filter((f) => f), c = await d(`git log -b origin/${E.TEST} -1 --format=%H`), l = (await d(
|
|
1461
|
+
`git log ${n}...${c} -b origin/${E.TEST}`
|
|
1462
1462
|
)).split(`
|
|
1463
1463
|
`).filter((f) => f);
|
|
1464
|
-
|
|
1464
|
+
pa(l, r) || p("请先在测试环境发布要部署的代码");
|
|
1465
1465
|
}
|
|
1466
1466
|
}
|
|
1467
|
-
async function
|
|
1468
|
-
|
|
1469
|
-
const
|
|
1470
|
-
Object.values($).includes(
|
|
1471
|
-
const
|
|
1467
|
+
async function Gi(e, t) {
|
|
1468
|
+
ae(), K(), await be();
|
|
1469
|
+
const a = await Ra();
|
|
1470
|
+
Object.values($).includes(a.sourceBranch) && p(`当前分支${a.sourceBranch}不可作为源分支合并到目标分支。`);
|
|
1471
|
+
const i = (await Qa(a.id)).filter((c) => ![a.sourceBranch].includes(c.name)).map((c) => {
|
|
1472
1472
|
let u = c.name;
|
|
1473
1473
|
return Object.values($).includes(u) && (u = N.bold.blue(u)), {
|
|
1474
1474
|
name: u,
|
|
@@ -1476,30 +1476,30 @@ async function Ga(e, t) {
|
|
|
1476
1476
|
};
|
|
1477
1477
|
});
|
|
1478
1478
|
let s;
|
|
1479
|
-
e && !
|
|
1479
|
+
e && !i.filter((c) => c.value === e).length && p(`未找到目标分支${e}`), e ? s = e : s = await k({
|
|
1480
1480
|
message: "请选择要合并到的目标分支:",
|
|
1481
|
-
choices:
|
|
1482
|
-
});
|
|
1483
|
-
const o = y(`本地分支${
|
|
1484
|
-
if (await d(`git ls-remote --heads origin ${
|
|
1485
|
-
o.text = `存在远程分支origin/${
|
|
1486
|
-
const c = await d(`git rev-parse ${
|
|
1487
|
-
await d(`git merge-base ${u} HEAD`) === u ? (await d(`git push -u origin ${
|
|
1488
|
-
`远程分支origin/${
|
|
1481
|
+
choices: i
|
|
1482
|
+
});
|
|
1483
|
+
const o = y(`本地分支${a.sourceBranch}检测中`).start();
|
|
1484
|
+
if (await d(`git ls-remote --heads origin ${a.sourceBranch}`)) {
|
|
1485
|
+
o.text = `存在远程分支origin/${a.sourceBranch}`, await d("git fetch");
|
|
1486
|
+
const c = await d(`git rev-parse ${a.sourceBranch}`), u = await d(`git rev-parse origin/${a.sourceBranch}`);
|
|
1487
|
+
await d(`git merge-base ${u} HEAD`) === u ? (await d(`git push -u origin ${a.sourceBranch}`), o.succeed(`本地分支${a.sourceBranch}已推送到远程分支origin/${a.sourceBranch}`)) : await d(`git merge-base ${c} ${u}`) === c ? (await d("git pull"), o.succeed(`本地分支${a.sourceBranch}已更新`)) : (o.fail(
|
|
1488
|
+
`远程分支origin/${a.sourceBranch}和本地分支${a.sourceBranch}都有新的提交,请手动合并后再试。`
|
|
1489
1489
|
), process.exit(1));
|
|
1490
1490
|
} else
|
|
1491
|
-
await d(`git push -u origin ${
|
|
1492
|
-
await
|
|
1493
|
-
`${
|
|
1491
|
+
await d(`git push -u origin ${a.sourceBranch}`), o.succeed(`本地分支${a.sourceBranch}已推送到远程分支origin/${a.sourceBranch}`);
|
|
1492
|
+
await Bi(a, s), await vt(a.sourceBranch, s, a, t.keepBranchAfterMergeMaster), $.MASTER === s && !t.keepBranchAfterMergeMaster && (await d(`git checkout ${$.MASTER}`), await d(`git pull origin ${$.MASTER}`), await d(`git branch -d ${a.sourceBranch}`), q(
|
|
1493
|
+
`${a.sourceBranch}分支已移除,当前已切换到最新的${$.MASTER}。如需继续开发,请检出新分支(z c b)。`
|
|
1494
1494
|
)), Object.values($).includes(s) && await yt(s, {
|
|
1495
1495
|
platform: t.deployPlatform,
|
|
1496
1496
|
skipSelectionNotification: t.deploySkipSelectionNotification,
|
|
1497
1497
|
skipGroupNotification: t.skipGroupNotification
|
|
1498
1498
|
});
|
|
1499
1499
|
}
|
|
1500
|
-
P.command("merge").alias("m").description("合并当前分支到指定远程分支,并部署。").argument("[branch]", "目标分支名称").option("--deploy-platform <platform>", `合并成功后要部署的平台。可选值:${Object.values(V).join("/")}`).option("--deploy-skip-selection-notification", "部署时,是否跳过选择部署通知人环节").option("--skip-group-notification", "是否跳过选择部署通知群聊环节").option("--keep-branch-after-merge-master", "在合并到主分支之后,是否保留分支。默认否").action((...e) => M(
|
|
1500
|
+
P.command("merge").alias("m").description("合并当前分支到指定远程分支,并部署。").argument("[branch]", "目标分支名称").option("--deploy-platform <platform>", `合并成功后要部署的平台。可选值:${Object.values(V).join("/")}`).option("--deploy-skip-selection-notification", "部署时,是否跳过选择部署通知人环节").option("--skip-group-notification", "是否跳过选择部署通知群聊环节").option("--keep-branch-after-merge-master", "在合并到主分支之后,是否保留分支。默认否").action((...e) => M(Gi, ...e));
|
|
1501
1501
|
P.command("deploy").alias("d").description("部署到指定环境").argument("[branchName]", `部署环境。可选值:${Object.values($).join("/")}`).option("--platform <platform>", `部署平台。可选值:${Object.values(V).join("/")}`).option("--module <module>", "部署模块。Java项目适用,填入要部署的模块名称,多个使用逗号分隔").option("--skip-selection-notification", "是否跳过选择部署通知人环节").option("--skip-group-notification", "是否跳过选择部署通知群聊环节").action((...e) => M(yt, ...e));
|
|
1502
|
-
async function
|
|
1502
|
+
async function _i() {
|
|
1503
1503
|
try {
|
|
1504
1504
|
await d("java -jar ./.z/checkstyle.jar -c ./.z/checkstyle.xml .", {
|
|
1505
1505
|
silent: !1
|
|
@@ -1508,7 +1508,7 @@ async function _a() {
|
|
|
1508
1508
|
p("checkstyle执行出错"), process.exit(1);
|
|
1509
1509
|
}
|
|
1510
1510
|
}
|
|
1511
|
-
async function
|
|
1511
|
+
async function Wi() {
|
|
1512
1512
|
A(m.resolve("node_modules", ".bin", "markdownlint")) || p("该项目未安装markdownlint,请安装后重试");
|
|
1513
1513
|
const e = y("markdownlint执行中...").start();
|
|
1514
1514
|
try {
|
|
@@ -1519,36 +1519,36 @@ async function Wa() {
|
|
|
1519
1519
|
e.fail("markdownlint校验出错"), process.exit(1);
|
|
1520
1520
|
}
|
|
1521
1521
|
}
|
|
1522
|
-
function
|
|
1523
|
-
const e =
|
|
1522
|
+
function Vi() {
|
|
1523
|
+
const e = ie();
|
|
1524
1524
|
if (e["lint-staged"])
|
|
1525
1525
|
return e["lint-staged"];
|
|
1526
1526
|
throw new Error("未找到lint配置");
|
|
1527
1527
|
}
|
|
1528
|
-
async function
|
|
1528
|
+
async function qi() {
|
|
1529
1529
|
const e = y("代码风格检测中...").start();
|
|
1530
1530
|
await Mt({
|
|
1531
1531
|
concurrent: 4,
|
|
1532
1532
|
debug: !1,
|
|
1533
|
-
config:
|
|
1533
|
+
config: Vi(),
|
|
1534
1534
|
quiet: !0,
|
|
1535
1535
|
relative: !0
|
|
1536
1536
|
}) ? (e.succeed("代码风格检测通过!"), process.exit(0)) : (e.fail("代码风格检测未通过!"), process.exit(1));
|
|
1537
1537
|
}
|
|
1538
|
-
function
|
|
1538
|
+
function Zi(e) {
|
|
1539
1539
|
if (e.includes("Merge") && e.includes("# Conflicts:") || zt.valid(e))
|
|
1540
1540
|
return !0;
|
|
1541
1541
|
const t = e.split(": ");
|
|
1542
1542
|
if (t.length === 1)
|
|
1543
1543
|
return "body前缺少「: 」";
|
|
1544
|
-
const
|
|
1545
|
-
return /^(feat|fix|refactor)/.test(
|
|
1544
|
+
const a = t[0];
|
|
1545
|
+
return /^(feat|fix|refactor)/.test(a) ? /\(\d+(?:,\d+)*\)/.test(a) ? !0 : "ID缺少或者格式不正确。" : /^(chore|ci)/.test(a) ? [S.CHORE, S.CI].includes(a) ? !0 : "chore/ci类型无需填写ID。" : S.Break === a ? !0 : "不存在的提交类型。";
|
|
1546
1546
|
}
|
|
1547
|
-
async function
|
|
1548
|
-
const e = await Re(m.resolve(".git", "COMMIT_EDITMSG"), "utf-8"), t = y("提交信息格式校验中...").start(),
|
|
1549
|
-
|
|
1547
|
+
async function Hi() {
|
|
1548
|
+
const e = await Re(m.resolve(".git", "COMMIT_EDITMSG"), "utf-8"), t = y("提交信息格式校验中...").start(), a = Zi(e);
|
|
1549
|
+
a === !0 ? (t.succeed("提交信息格式校验通过"), process.exit(0)) : (t.fail(`提交信息格式校验失败。${a}`), process.exit(1));
|
|
1550
1550
|
}
|
|
1551
|
-
async function
|
|
1551
|
+
async function Ki() {
|
|
1552
1552
|
await be();
|
|
1553
1553
|
const e = await Ft({
|
|
1554
1554
|
// 分组,展示仓库链接
|
|
@@ -1562,24 +1562,24 @@ async function Ka() {
|
|
|
1562
1562
|
});
|
|
1563
1563
|
if (e && Object.keys(e).length) {
|
|
1564
1564
|
q("升级完成 🎉");
|
|
1565
|
-
const t = Object.entries(e).map(([
|
|
1565
|
+
const t = Object.entries(e).map(([a, n]) => `${a}@${n}`).join("; ");
|
|
1566
1566
|
await d(`git add . && git commit -m "chore: 依赖升级。${t}"`);
|
|
1567
1567
|
}
|
|
1568
1568
|
process.exit(0);
|
|
1569
1569
|
}
|
|
1570
|
-
async function
|
|
1570
|
+
async function Xi(e) {
|
|
1571
1571
|
A(m.resolve("node_modules", ".bin", "eslint")) || p("该项目未安装eslint,请安装后重试");
|
|
1572
1572
|
const t = y("eslint执行中...").start();
|
|
1573
1573
|
try {
|
|
1574
|
-
let
|
|
1575
|
-
process.platform === "win32" && (
|
|
1574
|
+
let a = "npx eslint '**/*.{vue,js,jsx,cjs,mjs,ts,tsx,cts,mts}' --fix";
|
|
1575
|
+
process.platform === "win32" && (a = 'npx eslint "**/*.{vue,js,jsx,cjs,mjs,ts,tsx,cts,mts}" --fix'), e.quiet && (a += " --quiet"), e.maxWarnings && !isNaN(Number(e.maxWarnings)) ? a += ` --max-warnings ${Number(e.maxWarnings)}` : a += " --max-warnings 100", await d(a, {
|
|
1576
1576
|
silent: !1
|
|
1577
1577
|
}), t.succeed("eslint执行成功"), process.exit(0);
|
|
1578
1578
|
} catch {
|
|
1579
1579
|
t.fail("eslint校验出错"), process.exit(1);
|
|
1580
1580
|
}
|
|
1581
1581
|
}
|
|
1582
|
-
async function
|
|
1582
|
+
async function Yi() {
|
|
1583
1583
|
A(m.resolve("node_modules", ".bin", "prettier")) || p("该项目未安装prettier,请安装后重试");
|
|
1584
1584
|
const e = y("prettier执行中...").start();
|
|
1585
1585
|
try {
|
|
@@ -1593,12 +1593,12 @@ async function Ya() {
|
|
|
1593
1593
|
e.fail("prettier校验出错"), process.exit(1);
|
|
1594
1594
|
}
|
|
1595
1595
|
}
|
|
1596
|
-
function
|
|
1597
|
-
A(m.resolve("./node_modules/.bin/vue-tsc")) || p("请先安装vue-tsc。推荐命令: npm i -D vue-tsc"),
|
|
1596
|
+
function Qi() {
|
|
1597
|
+
A(m.resolve("./node_modules/.bin/vue-tsc")) || p("请先安装vue-tsc。推荐命令: npm i -D vue-tsc"), ma("npx vue-tsc --build"), process.exit(0);
|
|
1598
1598
|
}
|
|
1599
1599
|
async function en(e, t) {
|
|
1600
|
-
|
|
1601
|
-
const
|
|
1600
|
+
ae(), K();
|
|
1601
|
+
const a = ie();
|
|
1602
1602
|
let n;
|
|
1603
1603
|
if (e)
|
|
1604
1604
|
[
|
|
@@ -1635,18 +1635,18 @@ async function en(e, t) {
|
|
|
1635
1635
|
/* MarkdownLintAbbr */
|
|
1636
1636
|
].includes(e) ? n = "markdown-lint" : p("参数输入错误");
|
|
1637
1637
|
else {
|
|
1638
|
-
const
|
|
1638
|
+
const i = [
|
|
1639
1639
|
{
|
|
1640
1640
|
name: "执行 prettier",
|
|
1641
1641
|
value: "prettier"
|
|
1642
1642
|
/* Prettier */
|
|
1643
1643
|
}
|
|
1644
1644
|
];
|
|
1645
|
-
|
|
1645
|
+
a.language === w.JAVA && i.push({
|
|
1646
1646
|
name: "执行 check-style",
|
|
1647
1647
|
value: "checkstyle"
|
|
1648
1648
|
/* CheckStyle */
|
|
1649
|
-
}),
|
|
1649
|
+
}), a.language === w.JAVASCRIPT && i.push(
|
|
1650
1650
|
{
|
|
1651
1651
|
name: "执行 eslint",
|
|
1652
1652
|
value: "eslint"
|
|
@@ -1662,7 +1662,7 @@ async function en(e, t) {
|
|
|
1662
1662
|
value: "dependency-check"
|
|
1663
1663
|
/* DependencyCheck */
|
|
1664
1664
|
}
|
|
1665
|
-
),
|
|
1665
|
+
), a.language === w.MARKDOWN && i.push(
|
|
1666
1666
|
{
|
|
1667
1667
|
name: "执行markdown-lint",
|
|
1668
1668
|
value: "markdown-lint"
|
|
@@ -1685,10 +1685,10 @@ async function en(e, t) {
|
|
|
1685
1685
|
}
|
|
1686
1686
|
), n = await k({
|
|
1687
1687
|
message: "请选择你要执行的操作",
|
|
1688
|
-
choices:
|
|
1688
|
+
choices: i
|
|
1689
1689
|
});
|
|
1690
1690
|
}
|
|
1691
|
-
n === "commit-msg" ? await
|
|
1691
|
+
n === "commit-msg" ? await Hi() : n === "commit-files" ? await qi() : n === "prettier" ? await Yi() : n === "eslint" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? await Xi(t) : n === "type-check" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? Qi() : n === "dependency-check" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? await Ki() : n === "checkstyle" && a.language === w.JAVA ? await _i() : n === "markdown-lint" && a.language === w.MARKDOWN && await Wi();
|
|
1692
1692
|
}
|
|
1693
1693
|
P.command("run").alias("r").description("执行 eslint / prettier / type-check / dependency-check / checkstyle / markdown-lint。").argument(
|
|
1694
1694
|
"[type]",
|
|
@@ -1697,8 +1697,8 @@ P.command("run").alias("r").description("执行 eslint / prettier / type-check /
|
|
|
1697
1697
|
async function $t(e = "latest") {
|
|
1698
1698
|
const t = y("安装中...").start();
|
|
1699
1699
|
await d(`npm i -g ${re.name}@${e} --registry https://registry.npmmirror.com/`), t.text = "本地配置更新中...", me("latestCheckVersionTimestamp", Date.now()), me("version", e);
|
|
1700
|
-
const
|
|
1701
|
-
je(
|
|
1700
|
+
const a = await De();
|
|
1701
|
+
je(a), oe(), t.succeed(`升级完成,当前版本${e}`), process.exit(0);
|
|
1702
1702
|
}
|
|
1703
1703
|
P.command("update").alias("u").description("升级").argument("[version]", "版本号", "latest").action((...e) => M($t, ...e));
|
|
1704
1704
|
const Oe = /Thumbs\.db|\.git|DS_Store|idea/, Nt = "testcase";
|
|
@@ -1710,11 +1710,11 @@ function At(e) {
|
|
|
1710
1710
|
id: t[2],
|
|
1711
1711
|
displayName: t[1]?.trim() || ""
|
|
1712
1712
|
};
|
|
1713
|
-
const
|
|
1714
|
-
return
|
|
1713
|
+
const a = e.match(/^\[(\d+)](.+)$/);
|
|
1714
|
+
return a ? {
|
|
1715
1715
|
type: "case",
|
|
1716
|
-
id:
|
|
1717
|
-
displayName:
|
|
1716
|
+
id: a[1],
|
|
1717
|
+
displayName: a[2]?.trim() || ""
|
|
1718
1718
|
} : {
|
|
1719
1719
|
type: "directory",
|
|
1720
1720
|
id: void 0,
|
|
@@ -1722,13 +1722,13 @@ function At(e) {
|
|
|
1722
1722
|
};
|
|
1723
1723
|
}
|
|
1724
1724
|
async function te(e, t = {}) {
|
|
1725
|
-
const { exclude:
|
|
1726
|
-
async function
|
|
1725
|
+
const { exclude: a = Oe } = t, n = [];
|
|
1726
|
+
async function i(s) {
|
|
1727
1727
|
const o = m.basename(s);
|
|
1728
1728
|
if ((await He(s)).isFile())
|
|
1729
1729
|
return null;
|
|
1730
1730
|
const c = await xe(s, { withFileTypes: !0 }), u = (await Promise.all(
|
|
1731
|
-
c.filter((v) => v.isDirectory() && !
|
|
1731
|
+
c.filter((v) => v.isDirectory() && !a.test(v.name)).map((v) => i(m.join(s, v.name)))
|
|
1732
1732
|
)).filter(Boolean), { type: l, id: f, displayName: h } = At(o), g = {
|
|
1733
1733
|
name: o,
|
|
1734
1734
|
id: f,
|
|
@@ -1739,17 +1739,17 @@ async function te(e, t = {}) {
|
|
|
1739
1739
|
};
|
|
1740
1740
|
return (t.hasRoot || m.resolve(e) !== s) && n.push(g), g;
|
|
1741
1741
|
}
|
|
1742
|
-
return await
|
|
1742
|
+
return await i(m.resolve(e)), n;
|
|
1743
1743
|
}
|
|
1744
1744
|
async function bt(e, t = {}) {
|
|
1745
|
-
const { exclude:
|
|
1745
|
+
const { exclude: a = Oe } = t;
|
|
1746
1746
|
try {
|
|
1747
1747
|
const n = await xe(m.resolve(e), { withFileTypes: !0 });
|
|
1748
1748
|
return await Promise.all(
|
|
1749
|
-
n.filter((
|
|
1750
|
-
const s = m.join(e,
|
|
1749
|
+
n.filter((i) => i.isDirectory() && !a.test(i.name)).map((i) => {
|
|
1750
|
+
const s = m.join(e, i.name), { type: o, id: r, displayName: c } = At(i.name);
|
|
1751
1751
|
return {
|
|
1752
|
-
name:
|
|
1752
|
+
name: i.name,
|
|
1753
1753
|
id: r,
|
|
1754
1754
|
displayName: c,
|
|
1755
1755
|
path: s,
|
|
@@ -1761,39 +1761,39 @@ async function bt(e, t = {}) {
|
|
|
1761
1761
|
return p(`读取目录失败: ${e} : ${n}`), [];
|
|
1762
1762
|
}
|
|
1763
1763
|
}
|
|
1764
|
-
function Z(e, t,
|
|
1764
|
+
function Z(e, t, a) {
|
|
1765
1765
|
switch (e) {
|
|
1766
1766
|
case "module":
|
|
1767
|
-
return
|
|
1767
|
+
return a ? `${t}[${a}]` : t;
|
|
1768
1768
|
case "case":
|
|
1769
|
-
return
|
|
1769
|
+
return a ? `[${a}]${t}` : t;
|
|
1770
1770
|
default:
|
|
1771
1771
|
return t;
|
|
1772
1772
|
}
|
|
1773
1773
|
}
|
|
1774
|
-
async function we(e, t,
|
|
1774
|
+
async function we(e, t, a, n) {
|
|
1775
1775
|
try {
|
|
1776
|
-
const
|
|
1777
|
-
if (
|
|
1776
|
+
const i = m.basename(e), s = Z(a, t, n);
|
|
1777
|
+
if (i === s)
|
|
1778
1778
|
return !0;
|
|
1779
1779
|
const o = m.dirname(e), r = m.join(o, s);
|
|
1780
|
-
return await
|
|
1781
|
-
} catch (
|
|
1782
|
-
return p(`重命名文件夹失败: ${e} -> ${t}。${
|
|
1780
|
+
return await ga(e) ? await Ke(e, r) : (await d(`git mv "${e}" "${r}"`), await d("git add .")), !0;
|
|
1781
|
+
} catch (i) {
|
|
1782
|
+
return p(`重命名文件夹失败: ${e} -> ${t}。${i}`), !1;
|
|
1783
1783
|
}
|
|
1784
1784
|
}
|
|
1785
|
-
async function tn(e, t,
|
|
1786
|
-
const { exclude: n = Oe } =
|
|
1787
|
-
async function
|
|
1785
|
+
async function tn(e, t, a = {}) {
|
|
1786
|
+
const { exclude: n = Oe } = a;
|
|
1787
|
+
async function i(s, o) {
|
|
1788
1788
|
if (!s || s.length === 0) return;
|
|
1789
1789
|
const r = await bt(o, { exclude: n });
|
|
1790
1790
|
for (const c of s) {
|
|
1791
1791
|
const u = String(c.value), l = Z("module", c.label, u), f = r.find((g) => g.id === u);
|
|
1792
1792
|
let h = f?.path || m.join(o, l);
|
|
1793
|
-
f ? f.displayName !== c.label && await we(f.path, c.label, "module", u) && (h = m.join(o, l)) : (await pe(h, { recursive: !0 }), await d(`git add "${h}"`)), c.children && c.children.length > 0 && await
|
|
1793
|
+
f ? f.displayName !== c.label && await we(f.path, c.label, "module", u) && (h = m.join(o, l)) : (await pe(h, { recursive: !0 }), await d(`git add "${h}"`)), c.children && c.children.length > 0 && await i(c.children, h);
|
|
1794
1794
|
}
|
|
1795
1795
|
}
|
|
1796
|
-
await
|
|
1796
|
+
await i(e, m.resolve(t));
|
|
1797
1797
|
}
|
|
1798
1798
|
async function jt(e) {
|
|
1799
1799
|
const t = {
|
|
@@ -1804,27 +1804,27 @@ async function jt(e) {
|
|
|
1804
1804
|
if (e)
|
|
1805
1805
|
Number.isNaN(Number(e)) && p("请输入正确的产品ID"), t.id = Number(e);
|
|
1806
1806
|
else {
|
|
1807
|
-
const
|
|
1807
|
+
const a = await ni();
|
|
1808
1808
|
t.id = await k({
|
|
1809
1809
|
message: "请选择产品",
|
|
1810
|
-
choices:
|
|
1810
|
+
choices: a.map((n) => ({
|
|
1811
1811
|
name: `${n.label}[${n.value}]`,
|
|
1812
1812
|
value: n.value
|
|
1813
1813
|
}))
|
|
1814
1814
|
});
|
|
1815
1815
|
}
|
|
1816
|
-
return t.name = await
|
|
1816
|
+
return t.name = await si(t.id), t.path = m.join(Nt, Z("module", t.name, String(t.id))), t;
|
|
1817
1817
|
}
|
|
1818
1818
|
async function Me(e) {
|
|
1819
|
-
return (await bt(Nt)).find((
|
|
1819
|
+
return (await bt(Nt)).find((a) => Number(a.id) === e.id);
|
|
1820
1820
|
}
|
|
1821
1821
|
async function St(e, t) {
|
|
1822
|
-
const
|
|
1822
|
+
const a = {
|
|
1823
1823
|
precondition: e.precondition,
|
|
1824
1824
|
priority: e.pri,
|
|
1825
1825
|
steps: []
|
|
1826
1826
|
};
|
|
1827
|
-
|
|
1827
|
+
a.steps = await oi(e.id), I.writeJSONSync(t, a, {
|
|
1828
1828
|
spaces: 2
|
|
1829
1829
|
});
|
|
1830
1830
|
}
|
|
@@ -1833,48 +1833,48 @@ async function kt(e, t) {
|
|
|
1833
1833
|
recursive: !0
|
|
1834
1834
|
}), await St(e, m.join(t, "config.json")), I.ensureFileSync(m.join(t, "data.yaml")), await D(
|
|
1835
1835
|
m.join(t, "data.yaml"),
|
|
1836
|
-
A(m.resolve(Q, "data.yaml")) ? await Re(m.resolve(Q, "data.yaml")) : await
|
|
1836
|
+
A(m.resolve(Q, "data.yaml")) ? await Re(m.resolve(Q, "data.yaml")) : await Ua()
|
|
1837
1837
|
), I.ensureFileSync(m.join(t, "main.py")), await D(
|
|
1838
1838
|
m.join(t, "main.py"),
|
|
1839
|
-
A(m.resolve(Q, "main.py")) ? await Re(m.resolve(Q, "main.py")) : await
|
|
1839
|
+
A(m.resolve(Q, "main.py")) ? await Re(m.resolve(Q, "main.py")) : await Ba()
|
|
1840
1840
|
);
|
|
1841
1841
|
}
|
|
1842
1842
|
function ze(e) {
|
|
1843
1843
|
if (e) {
|
|
1844
|
-
const t = e.split(",").map((
|
|
1845
|
-
const n = Number(
|
|
1844
|
+
const t = e.split(",").map((a) => a.trim()).filter((a) => {
|
|
1845
|
+
const n = Number(a);
|
|
1846
1846
|
return Number.isInteger(n) && n > 0;
|
|
1847
|
-
}).map((
|
|
1847
|
+
}).map((a) => Number(a));
|
|
1848
1848
|
return t.length === 0 ? (p('未找到有效的ID,请输入格式如 "1,2,3,4" 的正整数ID'), []) : t;
|
|
1849
1849
|
}
|
|
1850
1850
|
return [];
|
|
1851
1851
|
}
|
|
1852
1852
|
async function Se(e, t) {
|
|
1853
|
-
|
|
1854
|
-
let
|
|
1855
|
-
t ? ([R.MODULE, R.CASE].includes(t) || p(`不支持的参数${t}。参数值应为 ${R.MODULE} 或者 ${R.CASE}。`),
|
|
1853
|
+
ae(), K(), await be();
|
|
1854
|
+
let a;
|
|
1855
|
+
t ? ([R.MODULE, R.CASE].includes(t) || p(`不支持的参数${t}。参数值应为 ${R.MODULE} 或者 ${R.CASE}。`), a = t) : a = await k({
|
|
1856
1856
|
message: `请选择要${e}的数据类型`,
|
|
1857
|
-
choices:
|
|
1857
|
+
choices: ta
|
|
1858
1858
|
});
|
|
1859
|
-
const n =
|
|
1859
|
+
const n = a === R.MODULE ? "模块" : R.CASE === a ? "用例" : "";
|
|
1860
1860
|
return {
|
|
1861
|
-
type:
|
|
1861
|
+
type: a,
|
|
1862
1862
|
typeStr: n
|
|
1863
1863
|
};
|
|
1864
1864
|
}
|
|
1865
1865
|
async function ke(e) {
|
|
1866
|
-
const t = await jt(e),
|
|
1867
|
-
return
|
|
1866
|
+
const t = await jt(e), a = await Me(t);
|
|
1867
|
+
return a || p(`本地未找到产品【${t.name}[${t.id}]】`), {
|
|
1868
1868
|
product: t,
|
|
1869
|
-
localProduct:
|
|
1869
|
+
localProduct: a
|
|
1870
1870
|
};
|
|
1871
1871
|
}
|
|
1872
|
-
async function an(e, t,
|
|
1872
|
+
async function an(e, t, a) {
|
|
1873
1873
|
e.text = "查找本地产品目录...", await Me(t) || p(`本地未找到产品【${t.name}[${t.id}]】`), e.text = "解析ID参数...";
|
|
1874
|
-
const
|
|
1874
|
+
const i = ze(a);
|
|
1875
1875
|
let s = await te(t.path);
|
|
1876
1876
|
e.text = "获取远程用例列表...";
|
|
1877
|
-
const o = await
|
|
1877
|
+
const o = await ri(t.id, i);
|
|
1878
1878
|
e.text = "本地用例同步中...";
|
|
1879
1879
|
for (const r of o) {
|
|
1880
1880
|
let c;
|
|
@@ -1894,14 +1894,14 @@ async function an(e, t, i) {
|
|
|
1894
1894
|
}
|
|
1895
1895
|
async function nn(e, t) {
|
|
1896
1896
|
e.text = "本地产品目录查找中...";
|
|
1897
|
-
const
|
|
1898
|
-
|
|
1897
|
+
const a = await Me(t);
|
|
1898
|
+
a ? (e.text = "找到产品目录。开始重命名...", a.displayName !== t.name && await we(a.path, t.name, a.type, a.id) && (e.text = `重命名成功: ${a.displayName} -> ${t.name}`)) : (e.text = "未找到。开始创建产品目录...", await pe(t.path, { recursive: !0 }), await d("git add .")), e.text = "获取远程模块列表...";
|
|
1899
1899
|
const n = await ft(t.id);
|
|
1900
1900
|
e.text = "本地同步模块中...", await tn(n || [], t.path);
|
|
1901
1901
|
}
|
|
1902
1902
|
async function sn(e, t) {
|
|
1903
|
-
const { type:
|
|
1904
|
-
if (R.MODULE ===
|
|
1903
|
+
const { type: a, typeStr: n } = await Se("拉取", e), i = await jt(t.productId), s = y(`${n}同步中...`).start();
|
|
1904
|
+
if (R.MODULE === a && await nn(s, i), R.CASE === a && await an(s, i, t.caseIds), s.succeed(`${n}同步完成 🎉`), !t.disableAutoCommit && await d("git status -s")) {
|
|
1905
1905
|
const o = y("代码提交中...").start();
|
|
1906
1906
|
try {
|
|
1907
1907
|
await d(`git add . && git commit -m "chore: 同步禅道${n}数据"`), o.succeed("代码已提交 ✅");
|
|
@@ -1911,29 +1911,29 @@ async function sn(e, t) {
|
|
|
1911
1911
|
}
|
|
1912
1912
|
}
|
|
1913
1913
|
P.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(sn, ...e));
|
|
1914
|
-
async function rn(e, t,
|
|
1914
|
+
async function rn(e, t, a) {
|
|
1915
1915
|
let n = await U({
|
|
1916
1916
|
message: "请输入你要创建的用例的前置条件(可不填)"
|
|
1917
1917
|
});
|
|
1918
1918
|
n = n.trim();
|
|
1919
|
-
const
|
|
1920
|
-
|
|
1921
|
-
const s = await
|
|
1919
|
+
const i = y(`用例【${a}】开始创建...`).start();
|
|
1920
|
+
i.text = "远程用例创建中...";
|
|
1921
|
+
const s = await ui({
|
|
1922
1922
|
product: Number(e.id),
|
|
1923
1923
|
// 如果父模块是产品根目录,parent=0
|
|
1924
1924
|
module: m.resolve(e?.path) === t?.path ? 0 : Number(t?.id || 0),
|
|
1925
|
-
title:
|
|
1925
|
+
title: a,
|
|
1926
1926
|
type: "interface",
|
|
1927
1927
|
openedBy: C("ldapAccount"),
|
|
1928
1928
|
precondition: n || ""
|
|
1929
1929
|
});
|
|
1930
|
-
|
|
1930
|
+
i.text = "远程用例步骤创建中...", await li({
|
|
1931
1931
|
case: s,
|
|
1932
1932
|
type: "step",
|
|
1933
1933
|
desc: "按照预期执行",
|
|
1934
1934
|
expect: "正常执行,符合预期"
|
|
1935
|
-
}),
|
|
1936
|
-
const o = m.join(t.path, Z("case",
|
|
1935
|
+
}), i.text = "本地用例创建中...";
|
|
1936
|
+
const o = m.join(t.path, Z("case", a, String(s)));
|
|
1937
1937
|
return A(o) ? q(`${o}已存在,请检查是否对应,本地不再创建。`) : (await kt(
|
|
1938
1938
|
{
|
|
1939
1939
|
id: s,
|
|
@@ -1941,19 +1941,19 @@ async function rn(e, t, i) {
|
|
|
1941
1941
|
precondition: n
|
|
1942
1942
|
},
|
|
1943
1943
|
o
|
|
1944
|
-
),
|
|
1944
|
+
), i.succeed(`用例【[${o}】创建完成 🎉`), o);
|
|
1945
1945
|
}
|
|
1946
|
-
async function on(e, t,
|
|
1947
|
-
const n = y(`模块【${
|
|
1946
|
+
async function on(e, t, a) {
|
|
1947
|
+
const n = y(`模块【${a}】开始创建...`).start();
|
|
1948
1948
|
n.text = "远程模块创建中...";
|
|
1949
|
-
const
|
|
1949
|
+
const i = await ci({
|
|
1950
1950
|
root: Number(e.id),
|
|
1951
|
-
name:
|
|
1951
|
+
name: a,
|
|
1952
1952
|
// 如果父模块是产品根目录,parent=0
|
|
1953
1953
|
parent: m.resolve(e?.path) === t?.path ? 0 : Number(t?.id || 0)
|
|
1954
1954
|
});
|
|
1955
1955
|
n.text = "本地模块创建中...";
|
|
1956
|
-
const s = m.join(t.path, Z("module",
|
|
1956
|
+
const s = m.join(t.path, Z("module", a, String(i)));
|
|
1957
1957
|
if (A(s))
|
|
1958
1958
|
return q(`${s}已存在,请检查是否对应,本地不再创建。`);
|
|
1959
1959
|
await pe(s, {
|
|
@@ -1963,8 +1963,8 @@ async function on(e, t, i) {
|
|
|
1963
1963
|
function cn(e) {
|
|
1964
1964
|
function t(n) {
|
|
1965
1965
|
if (!n.children || n.children.length === 0) return;
|
|
1966
|
-
const
|
|
1967
|
-
|
|
1966
|
+
const i = n.children[0];
|
|
1967
|
+
i && i.label === n.label && i.value === n.value && (!i.children || i.children.length === 0) || n.children.unshift({
|
|
1968
1968
|
value: n.value,
|
|
1969
1969
|
label: n.label,
|
|
1970
1970
|
type: n.type,
|
|
@@ -1972,20 +1972,20 @@ function cn(e) {
|
|
|
1972
1972
|
tempTitle: "当前层级"
|
|
1973
1973
|
});
|
|
1974
1974
|
}
|
|
1975
|
-
async function
|
|
1976
|
-
const s =
|
|
1975
|
+
async function a(n, i = []) {
|
|
1976
|
+
const s = i.length ? `请选择层级(当前:${i.join(" / ")})` : "请选择层级", o = await k({
|
|
1977
1977
|
message: s,
|
|
1978
1978
|
choices: n.map((r) => ({
|
|
1979
1979
|
name: `${r.tempTitle ? r.tempTitle : r.label} ${r.children?.length ? "(有子级)" : ""}`,
|
|
1980
1980
|
value: r
|
|
1981
1981
|
}))
|
|
1982
1982
|
});
|
|
1983
|
-
return o?.children?.length ? (t(o),
|
|
1983
|
+
return o?.children?.length ? (t(o), a(o.children, [...i, o.label])) : o;
|
|
1984
1984
|
}
|
|
1985
|
-
return
|
|
1985
|
+
return a(e);
|
|
1986
1986
|
}
|
|
1987
1987
|
async function un(e, t) {
|
|
1988
|
-
const { type:
|
|
1988
|
+
const { type: a, typeStr: n } = await Se("创建", e), { product: i, localProduct: s } = await ke(t.productId), o = await ft(i.id), r = await cn(o), c = Z("module", r.label, String(r.value)), l = (await te(i.path, { hasRoot: !0 })).find((g) => g.name === c);
|
|
1989
1989
|
if (!l?.path || !A(l.path))
|
|
1990
1990
|
return p(`本地不存在${c}模块`);
|
|
1991
1991
|
let f = await U({
|
|
@@ -1995,7 +1995,7 @@ async function un(e, t) {
|
|
|
1995
1995
|
});
|
|
1996
1996
|
f = f.trim();
|
|
1997
1997
|
let h = "";
|
|
1998
|
-
if (R.MODULE ===
|
|
1998
|
+
if (R.MODULE === a && await on(s, l, f), R.CASE === a && (h = await rn(s, l, f)), !t.disableAutoCommit && R.CASE === a) {
|
|
1999
1999
|
const g = y("代码提交中...").start();
|
|
2000
2000
|
try {
|
|
2001
2001
|
await d(`git add . && git commit -m "chore: 创建了用例${m.basename(h)}"`), g.succeed("代码已提交 ✅");
|
|
@@ -2007,12 +2007,12 @@ async function un(e, t) {
|
|
|
2007
2007
|
P.command("qa-create").alias("qc").description("创建模块或者用例").argument("[type]", "可选值为module/case").option("--product-id <productId>", "指定产品ID").option("--disable-auto-commit", "是否跳过自动将修改结果提交。").action((...e) => M(un, ...e));
|
|
2008
2008
|
async function ln(e, t) {
|
|
2009
2009
|
const n = (await te(e.path)).filter((r) => r.type === "case");
|
|
2010
|
-
let
|
|
2010
|
+
let i = [];
|
|
2011
2011
|
if (t.length)
|
|
2012
|
-
|
|
2012
|
+
i = n.filter((r) => t.includes(Number(r.id))).map((r) => ({
|
|
2013
2013
|
id: Number(r.id),
|
|
2014
2014
|
path: r.path
|
|
2015
|
-
})),
|
|
2015
|
+
})), i.length || p(`未找到对应用例,请确认输入的用例ID(${t.join(", ")})是否正确`);
|
|
2016
2016
|
else {
|
|
2017
2017
|
const r = n.map((c) => ({
|
|
2018
2018
|
value: {
|
|
@@ -2021,7 +2021,7 @@ async function ln(e, t) {
|
|
|
2021
2021
|
},
|
|
2022
2022
|
name: c.path.replace(m.resolve(e.path), "")
|
|
2023
2023
|
}));
|
|
2024
|
-
|
|
2024
|
+
i = await H({
|
|
2025
2025
|
message: "选择要删除的用例",
|
|
2026
2026
|
pageSize: 100,
|
|
2027
2027
|
loop: !1,
|
|
@@ -2031,23 +2031,23 @@ async function ln(e, t) {
|
|
|
2031
2031
|
}
|
|
2032
2032
|
});
|
|
2033
2033
|
}
|
|
2034
|
-
const s = y("远程用例删除中...").start(), o =
|
|
2035
|
-
await
|
|
2034
|
+
const s = y("远程用例删除中...").start(), o = i.map((r) => r.id);
|
|
2035
|
+
await pi({
|
|
2036
2036
|
product: Number(e.id),
|
|
2037
2037
|
caseIds: o
|
|
2038
2038
|
}), s.text = "本地用例删除中...";
|
|
2039
|
-
for (const r of
|
|
2039
|
+
for (const r of i)
|
|
2040
2040
|
A(r.path) && L.rm("-rf", r.path);
|
|
2041
2041
|
return s.succeed("用例删除完成"), o;
|
|
2042
2042
|
}
|
|
2043
2043
|
async function mn(e, t) {
|
|
2044
2044
|
const n = (await te(e.path)).filter((r) => r.type === "module");
|
|
2045
|
-
let
|
|
2045
|
+
let i = [];
|
|
2046
2046
|
if (t.length)
|
|
2047
|
-
|
|
2047
|
+
i = n.filter((r) => t.includes(Number(r.id))).map((r) => ({
|
|
2048
2048
|
id: Number(r.id),
|
|
2049
2049
|
path: r.path
|
|
2050
|
-
})),
|
|
2050
|
+
})), i.length || p(`未找到对应模块,请确认输入的模块ID(${t.join(", ")})是否正确`);
|
|
2051
2051
|
else {
|
|
2052
2052
|
const r = n.map((c) => ({
|
|
2053
2053
|
value: {
|
|
@@ -2056,7 +2056,7 @@ async function mn(e, t) {
|
|
|
2056
2056
|
},
|
|
2057
2057
|
name: c.path.replace(m.resolve(e.path), "")
|
|
2058
2058
|
}));
|
|
2059
|
-
|
|
2059
|
+
i = await H({
|
|
2060
2060
|
message: "选择要删除的模块",
|
|
2061
2061
|
pageSize: 100,
|
|
2062
2062
|
loop: !1,
|
|
@@ -2066,20 +2066,20 @@ async function mn(e, t) {
|
|
|
2066
2066
|
}
|
|
2067
2067
|
});
|
|
2068
2068
|
}
|
|
2069
|
-
|
|
2070
|
-
const s = y("远程模块删除中...").start(), o =
|
|
2071
|
-
await
|
|
2069
|
+
i = i.sort((r, c) => r.path.localeCompare(c.path));
|
|
2070
|
+
const s = y("远程模块删除中...").start(), o = i.map((r) => r.id);
|
|
2071
|
+
await mi({
|
|
2072
2072
|
product: Number(e.id),
|
|
2073
2073
|
moduleIds: o
|
|
2074
2074
|
}), s.text = "本地模块删除中...";
|
|
2075
|
-
for (const r of
|
|
2075
|
+
for (const r of i)
|
|
2076
2076
|
A(r.path) && L.rm("-rf", r.path);
|
|
2077
2077
|
return s.succeed("模块删除完成"), o;
|
|
2078
2078
|
}
|
|
2079
2079
|
async function pn(e, t) {
|
|
2080
|
-
const { type:
|
|
2080
|
+
const { type: a, typeStr: n } = await Se("删除", e), { localProduct: i } = await ke(t.productId), s = ze(t.targetIds);
|
|
2081
2081
|
let o = [];
|
|
2082
|
-
if (R.MODULE ===
|
|
2082
|
+
if (R.MODULE === a ? o = await mn(i, s) : R.CASE === a && (o = await ln(i, s)), !t.disableAutoCommit && await d("git status -s")) {
|
|
2083
2083
|
const r = y("代码提交中...").start();
|
|
2084
2084
|
try {
|
|
2085
2085
|
await d(`git add . && git commit -m 'chore: 删除了一些${n}(${o.join(", ")})'`), r.succeed("代码已提交 ✅");
|
|
@@ -2091,9 +2091,9 @@ async function pn(e, t) {
|
|
|
2091
2091
|
P.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(pn, ...e));
|
|
2092
2092
|
async function dn(e, t) {
|
|
2093
2093
|
const n = (await te(e.path)).filter((h) => h.type === "case");
|
|
2094
|
-
let
|
|
2094
|
+
let i;
|
|
2095
2095
|
if (t.targetId) {
|
|
2096
|
-
if (
|
|
2096
|
+
if (i = n.find((h) => Number(h.id) === Number(t.targetId)), !i)
|
|
2097
2097
|
return p(`未找到对应用例,请确认输入的用例ID(${t.targetId})是否正确`);
|
|
2098
2098
|
} else {
|
|
2099
2099
|
const h = n.map((g) => ({
|
|
@@ -2104,7 +2104,7 @@ async function dn(e, t) {
|
|
|
2104
2104
|
},
|
|
2105
2105
|
name: g.path.replace(m.resolve(e.path), "")
|
|
2106
2106
|
}));
|
|
2107
|
-
[
|
|
2107
|
+
[i] = await H({
|
|
2108
2108
|
message: "选择要更新的用例",
|
|
2109
2109
|
pageSize: 100,
|
|
2110
2110
|
loop: !1,
|
|
@@ -2117,18 +2117,18 @@ async function dn(e, t) {
|
|
|
2117
2117
|
}
|
|
2118
2118
|
let s = await U({
|
|
2119
2119
|
message: "修改用例名称",
|
|
2120
|
-
default:
|
|
2120
|
+
default: i.displayName,
|
|
2121
2121
|
required: !0,
|
|
2122
2122
|
validate: (h) => h.length > 0 && h.length < 255,
|
|
2123
2123
|
prefill: "editable"
|
|
2124
2124
|
});
|
|
2125
2125
|
s = s.trim();
|
|
2126
2126
|
const o = y("用例重命名中...").start();
|
|
2127
|
-
s !==
|
|
2128
|
-
id: Number(
|
|
2127
|
+
s !== i.displayName ? (await fi({
|
|
2128
|
+
id: Number(i.id),
|
|
2129
2129
|
name: s
|
|
2130
|
-
}), await we(
|
|
2131
|
-
let r = I.readJsonSync(m.join(
|
|
2130
|
+
}), await we(i.path, s, "case", String(i.id)) && o.succeed(`用例重命名成功: ${i.displayName} -> ${s}`), i.displayName = s, i.path = m.join(m.dirname(i.path), Z("case", s, String(i.id)))) : o.succeed("用例名称无变动");
|
|
2131
|
+
let r = I.readJsonSync(m.join(i.path, "config.json")), c;
|
|
2132
2132
|
t.casePriority ? Number.isInteger(t.casePriority) && Number(t.casePriority) > 0 && Number(t.casePriority) < 6 ? c = Number(t.casePriority) : c = await Ge({
|
|
2133
2133
|
message: "修改用例优先级",
|
|
2134
2134
|
min: 1,
|
|
@@ -2145,17 +2145,17 @@ async function dn(e, t) {
|
|
|
2145
2145
|
validate: (h) => h > 0 && h < 6
|
|
2146
2146
|
});
|
|
2147
2147
|
const u = y("用例优先级设置中...").start();
|
|
2148
|
-
c !== r.priority ? (await
|
|
2149
|
-
id: Number(
|
|
2148
|
+
c !== r.priority ? (await gi({
|
|
2149
|
+
id: Number(i.id),
|
|
2150
2150
|
priority: c
|
|
2151
2151
|
}), I.writeJSONSync(
|
|
2152
|
-
m.join(
|
|
2152
|
+
m.join(i.path, "config.json"),
|
|
2153
2153
|
{
|
|
2154
2154
|
...r,
|
|
2155
2155
|
priority: c
|
|
2156
2156
|
},
|
|
2157
2157
|
{ spaces: 2 }
|
|
2158
|
-
), u.succeed(`用例优先级修改成功:${r.priority} -> ${c}`)) : u.succeed("用例优先级无变动"), r = I.readJsonSync(m.join(
|
|
2158
|
+
), u.succeed(`用例优先级修改成功:${r.priority} -> ${c}`)) : u.succeed("用例优先级无变动"), r = I.readJsonSync(m.join(i.path, "config.json"));
|
|
2159
2159
|
let l;
|
|
2160
2160
|
t.casePrecondition ? l = t.casePrecondition : (l = await U({
|
|
2161
2161
|
message: "修改用例前置条件",
|
|
@@ -2163,23 +2163,23 @@ async function dn(e, t) {
|
|
|
2163
2163
|
prefill: "editable"
|
|
2164
2164
|
}), l = l.trim());
|
|
2165
2165
|
const f = y("用例前置条件设置中...").start();
|
|
2166
|
-
return l !== r.precondition ? (await
|
|
2167
|
-
id: Number(
|
|
2166
|
+
return l !== r.precondition ? (await hi({
|
|
2167
|
+
id: Number(i.id),
|
|
2168
2168
|
precondition: l
|
|
2169
2169
|
}), I.writeJSONSync(
|
|
2170
|
-
m.join(
|
|
2170
|
+
m.join(i.path, "config.json"),
|
|
2171
2171
|
{
|
|
2172
2172
|
...r,
|
|
2173
2173
|
precondition: l
|
|
2174
2174
|
},
|
|
2175
2175
|
{ spaces: 2 }
|
|
2176
|
-
), f.succeed(`用例前置条件修改成功:${r.precondition} -> ${l}`)) : f.succeed("用例前置条件无变动"),
|
|
2176
|
+
), f.succeed(`用例前置条件修改成功:${r.precondition} -> ${l}`)) : f.succeed("用例前置条件无变动"), i.id;
|
|
2177
2177
|
}
|
|
2178
2178
|
async function fn(e, t) {
|
|
2179
2179
|
const n = (await te(e.path)).filter((r) => r.type === "module");
|
|
2180
|
-
let
|
|
2180
|
+
let i;
|
|
2181
2181
|
if (t.targetId) {
|
|
2182
|
-
if (
|
|
2182
|
+
if (i = n.find((r) => Number(r.id) === Number(t.targetId)), !i)
|
|
2183
2183
|
return p(`未找到对应模块,请确认输入的模块ID(${t.targetId})是否正确`);
|
|
2184
2184
|
} else {
|
|
2185
2185
|
const r = n.map((c) => ({
|
|
@@ -2190,7 +2190,7 @@ async function fn(e, t) {
|
|
|
2190
2190
|
},
|
|
2191
2191
|
name: c.path.replace(m.resolve(e.path), "")
|
|
2192
2192
|
}));
|
|
2193
|
-
[
|
|
2193
|
+
[i] = await H({
|
|
2194
2194
|
message: "选择要更新的模块",
|
|
2195
2195
|
pageSize: 100,
|
|
2196
2196
|
loop: !1,
|
|
@@ -2203,22 +2203,22 @@ async function fn(e, t) {
|
|
|
2203
2203
|
}
|
|
2204
2204
|
let s = await U({
|
|
2205
2205
|
message: "修改模块名称",
|
|
2206
|
-
default:
|
|
2206
|
+
default: i.displayName,
|
|
2207
2207
|
required: !0,
|
|
2208
2208
|
validate: (r) => r.length > 0 && r.length < 255,
|
|
2209
2209
|
prefill: "editable"
|
|
2210
2210
|
});
|
|
2211
2211
|
s = s.trim();
|
|
2212
2212
|
const o = y("模块重命名中...").start();
|
|
2213
|
-
return s !==
|
|
2214
|
-
id: Number(
|
|
2213
|
+
return s !== i.displayName ? (await di({
|
|
2214
|
+
id: Number(i.id),
|
|
2215
2215
|
name: s
|
|
2216
|
-
}), await we(
|
|
2216
|
+
}), await we(i.path, s, "module", String(i.id)) && o.succeed(`模块重命名成功: ${i.displayName} -> ${s}`)) : o.succeed("模块名称无变动"), i.id;
|
|
2217
2217
|
}
|
|
2218
2218
|
async function gn(e, t) {
|
|
2219
|
-
const { type:
|
|
2219
|
+
const { type: a, typeStr: n } = await Se("修改", e), { localProduct: i } = await ke(t.productId);
|
|
2220
2220
|
let s;
|
|
2221
|
-
if (R.MODULE ===
|
|
2221
|
+
if (R.MODULE === a ? s = await fn(i, t) : R.CASE === a && (s = await dn(i, t)), !t.disableAutoCommit && await d("git status -s")) {
|
|
2222
2222
|
const o = y("代码提交中...").start();
|
|
2223
2223
|
try {
|
|
2224
2224
|
await d(`git add . && git commit -m 'chore: 修改了一个${n}(${s})'`), o.succeed("代码已提交 ✅");
|
|
@@ -2231,30 +2231,30 @@ P.command("qa-update").alias("qu").description("修改模块或者用例").argum
|
|
|
2231
2231
|
async function hn(e, t) {
|
|
2232
2232
|
if (!e.length)
|
|
2233
2233
|
return [];
|
|
2234
|
-
const
|
|
2235
|
-
(
|
|
2234
|
+
const a = Jt(20), n = e.map(
|
|
2235
|
+
(i) => a(async () => {
|
|
2236
2236
|
try {
|
|
2237
|
-
const s = t.env || "production", o = await d(`python ${
|
|
2237
|
+
const s = t.env || "production", o = await d(`python ${i.path}/main.py --env ${s}`);
|
|
2238
2238
|
try {
|
|
2239
|
-
|
|
2239
|
+
i.result = JSON.parse(o);
|
|
2240
2240
|
} catch {
|
|
2241
|
-
p(`用例${
|
|
2241
|
+
p(`用例${i.displayName}[${i.id}]返回格式错误:${o}`);
|
|
2242
2242
|
}
|
|
2243
2243
|
} catch (s) {
|
|
2244
2244
|
const o = s instanceof Error ? s.message : String(s);
|
|
2245
|
-
p(`用例${
|
|
2245
|
+
p(`用例${i.displayName}[${i.id}]执行失败: ${o}`);
|
|
2246
2246
|
}
|
|
2247
2247
|
})
|
|
2248
2248
|
);
|
|
2249
2249
|
return await Promise.all(n), e;
|
|
2250
2250
|
}
|
|
2251
2251
|
async function wn(e) {
|
|
2252
|
-
|
|
2252
|
+
ae(), K();
|
|
2253
2253
|
const { localProduct: t } = await ke(e.productId);
|
|
2254
|
-
let
|
|
2255
|
-
const
|
|
2254
|
+
let a = [];
|
|
2255
|
+
const i = (await te(t.path)).filter((c) => c.type === "case");
|
|
2256
2256
|
if (e.all)
|
|
2257
|
-
|
|
2257
|
+
a = i.map((c) => ({
|
|
2258
2258
|
id: Number(c.id),
|
|
2259
2259
|
path: c.path,
|
|
2260
2260
|
displayName: c.displayName
|
|
@@ -2262,13 +2262,13 @@ async function wn(e) {
|
|
|
2262
2262
|
else {
|
|
2263
2263
|
const c = ze(e.caseIds);
|
|
2264
2264
|
if (c.length)
|
|
2265
|
-
|
|
2265
|
+
a = i.filter((u) => c.includes(Number(u.id))).map((u) => ({
|
|
2266
2266
|
id: Number(u.id),
|
|
2267
2267
|
path: u.path,
|
|
2268
2268
|
displayName: u.displayName
|
|
2269
2269
|
}));
|
|
2270
2270
|
else {
|
|
2271
|
-
const u =
|
|
2271
|
+
const u = i.map((l) => ({
|
|
2272
2272
|
value: {
|
|
2273
2273
|
id: Number(l.id),
|
|
2274
2274
|
path: l.path,
|
|
@@ -2276,7 +2276,7 @@ async function wn(e) {
|
|
|
2276
2276
|
},
|
|
2277
2277
|
name: l.path.replace(m.resolve(t.path), "")
|
|
2278
2278
|
}));
|
|
2279
|
-
|
|
2279
|
+
a = await H({
|
|
2280
2280
|
message: "选择要执行的用例",
|
|
2281
2281
|
pageSize: 100,
|
|
2282
2282
|
loop: !1,
|
|
@@ -2287,7 +2287,7 @@ async function wn(e) {
|
|
|
2287
2287
|
});
|
|
2288
2288
|
}
|
|
2289
2289
|
}
|
|
2290
|
-
const s = y("用例执行中...").start(), r = (await hn(
|
|
2290
|
+
const s = y("用例执行中...").start(), r = (await hn(a, e)).filter((c) => c.result.length);
|
|
2291
2291
|
if (r.length === 0)
|
|
2292
2292
|
s.succeed("所有用例执行通过 🎉");
|
|
2293
2293
|
else {
|
|
@@ -2299,10 +2299,10 @@ async function wn(e) {
|
|
|
2299
2299
|
if (e.executionId)
|
|
2300
2300
|
Number.isNaN(Number(e.executionId)) && p(`executionId ${e.executionId}不是正整数`), u = Number(e.executionId);
|
|
2301
2301
|
else {
|
|
2302
|
-
const f = await
|
|
2302
|
+
const f = await yi(), h = await k({
|
|
2303
2303
|
message: "请选择用例执行出错后,BUG所属的项目",
|
|
2304
2304
|
choices: f.map(({ id: v, name: G }) => ({ name: G, value: v }))
|
|
2305
|
-
}), g = await
|
|
2305
|
+
}), g = await vi(h);
|
|
2306
2306
|
u = await k({
|
|
2307
2307
|
message: "请选择用例执行出错后,BUG所属的执行",
|
|
2308
2308
|
choices: g.map(({ id: v, name: G }) => ({ name: G, value: v }))
|
|
@@ -2312,7 +2312,7 @@ async function wn(e) {
|
|
|
2312
2312
|
if (e.buildId)
|
|
2313
2313
|
l = e.buildId;
|
|
2314
2314
|
else {
|
|
2315
|
-
const f = await $
|
|
2315
|
+
const f = await $i(Number(u));
|
|
2316
2316
|
if (f.length) {
|
|
2317
2317
|
const h = await ve({
|
|
2318
2318
|
message: "请选择BUG关联的构建版本(可多选;非必选,默认主干)",
|
|
@@ -2328,7 +2328,7 @@ async function wn(e) {
|
|
|
2328
2328
|
}
|
|
2329
2329
|
s.start("上传中...");
|
|
2330
2330
|
for (const f of r)
|
|
2331
|
-
await
|
|
2331
|
+
await wi({
|
|
2332
2332
|
caseId: f.id,
|
|
2333
2333
|
caseResult: "fail",
|
|
2334
2334
|
stepResults: f.result,
|
|
@@ -2350,13 +2350,13 @@ const Ze = (e) => {
|
|
|
2350
2350
|
return "路径格式不合法";
|
|
2351
2351
|
if (m.isAbsolute(t))
|
|
2352
2352
|
return "只允许输入相对路径";
|
|
2353
|
-
const
|
|
2354
|
-
return !
|
|
2353
|
+
const a = m.normalize(t);
|
|
2354
|
+
return !a || a === "." || a === ".." ? "请输入有效的目录路径" : a.startsWith(`..${m.sep}`) ? "路径不能跳出当前项目" : !0;
|
|
2355
2355
|
}, yn = async () => {
|
|
2356
|
-
const { projects: e } = await
|
|
2356
|
+
const { projects: e } = await Oa(), t = ie();
|
|
2357
2357
|
if (t.serverProjectURL) {
|
|
2358
2358
|
const n = e.find(
|
|
2359
|
-
(
|
|
2359
|
+
(i) => ot(i.url, t.serverProjectURL)
|
|
2360
2360
|
);
|
|
2361
2361
|
if (n)
|
|
2362
2362
|
return {
|
|
@@ -2364,16 +2364,16 @@ const Ze = (e) => {
|
|
|
2364
2364
|
moduleList: n.modules || []
|
|
2365
2365
|
};
|
|
2366
2366
|
}
|
|
2367
|
-
const
|
|
2367
|
+
const a = await k({
|
|
2368
2368
|
message: "请选择本项目对应的服务端项目",
|
|
2369
2369
|
choices: e.map((n) => ({
|
|
2370
2370
|
name: `${n.name}(${n.url})`,
|
|
2371
2371
|
value: n.url
|
|
2372
2372
|
}))
|
|
2373
2373
|
});
|
|
2374
|
-
return mt({ ...t, serverProjectURL:
|
|
2375
|
-
projectId: decodeURIComponent(ee(
|
|
2376
|
-
moduleList: e.find((n) => n.url ===
|
|
2374
|
+
return mt({ ...t, serverProjectURL: a }), {
|
|
2375
|
+
projectId: decodeURIComponent(ee(a)),
|
|
2376
|
+
moduleList: e.find((n) => n.url === a)?.modules || []
|
|
2377
2377
|
};
|
|
2378
2378
|
}, vn = async (e) => {
|
|
2379
2379
|
if (e) {
|
|
@@ -2396,9 +2396,9 @@ const Ze = (e) => {
|
|
|
2396
2396
|
});
|
|
2397
2397
|
}, $n = async (e, t) => {
|
|
2398
2398
|
if (e)
|
|
2399
|
-
return e.split(",").filter((
|
|
2399
|
+
return e.split(",").filter((a) => t.map((n) => n.name).includes(a.trim()));
|
|
2400
2400
|
{
|
|
2401
|
-
const
|
|
2401
|
+
const a = await ve({
|
|
2402
2402
|
message: "请选择对应的后端服务,不选默认全部",
|
|
2403
2403
|
choices: t.map((n) => ({
|
|
2404
2404
|
name: `${n.name}(${n.desc})`,
|
|
@@ -2408,93 +2408,102 @@ const Ze = (e) => {
|
|
|
2408
2408
|
pageSize: 10,
|
|
2409
2409
|
loop: !0
|
|
2410
2410
|
});
|
|
2411
|
-
return
|
|
2411
|
+
return a?.length ? a : t.map((n) => n.name);
|
|
2412
2412
|
}
|
|
2413
|
-
}, Nn = async (e) => e && [
|
|
2413
|
+
}, Nn = async (e) => e && [E.DEV, E.TEST, E.RELEASE, E.PROD].includes(e.trim()) ? e : await k({
|
|
2414
2414
|
message: "请选择对应的环境",
|
|
2415
2415
|
// 去掉prod 环境
|
|
2416
|
-
choices:
|
|
2416
|
+
choices: at.filter((t) => t.value !== E.PROD)
|
|
2417
2417
|
}), Fe = (e) => {
|
|
2418
2418
|
const t = /^https?:\/\/[^/]+\/api\/([^/]+)\/v3\//;
|
|
2419
2419
|
return e.match(t)?.[1];
|
|
2420
|
-
}, An = async (e) => {
|
|
2420
|
+
}, An = async (e, t) => {
|
|
2421
2421
|
try {
|
|
2422
|
-
const
|
|
2422
|
+
const a = await ne({
|
|
2423
2423
|
url: e,
|
|
2424
2424
|
method: "get"
|
|
2425
|
-
}),
|
|
2426
|
-
return
|
|
2427
|
-
Object.entries(
|
|
2428
|
-
)), Bt(
|
|
2429
|
-
|
|
2430
|
-
|
|
2425
|
+
}), n = Fe(e);
|
|
2426
|
+
return n && (a.paths = Object.fromEntries(
|
|
2427
|
+
Object.entries(a.paths).map(([i, s]) => [`/${n}${i}`, s])
|
|
2428
|
+
)), Bt(a, {
|
|
2429
|
+
throwOnValidateError: !t
|
|
2430
|
+
});
|
|
2431
|
+
} catch (a) {
|
|
2432
|
+
throw p(`Error fetching Swagger JSON: ${a.message}`), a;
|
|
2431
2433
|
}
|
|
2432
2434
|
}, bn = (e) => {
|
|
2433
|
-
const t = (
|
|
2434
|
-
const { reason: n, url:
|
|
2435
|
-
return `## ${Fe(
|
|
2435
|
+
const t = (a) => {
|
|
2436
|
+
const { reason: n, url: i } = a;
|
|
2437
|
+
return `## ${Fe(i)}服务接口文档校验失败
|
|
2436
2438
|
${n.message}`;
|
|
2437
2439
|
};
|
|
2438
2440
|
return `# 服务端接口文档校验失败
|
|
2439
2441
|
${e.map(t).join(`
|
|
2440
2442
|
`)}`;
|
|
2441
2443
|
}, jn = async (e, t) => {
|
|
2442
|
-
const
|
|
2444
|
+
const a = bn(e), n = ie(), { groups: i } = await pt(), s = i.find(
|
|
2443
2445
|
(c) => c.projects.some((u) => ot(u, n.serverProjectURL))
|
|
2444
2446
|
);
|
|
2445
|
-
t.fail("API数据解析失败"), s || (t.fail("未找到对应的项目群聊组!"), process.stdout.write(`${N.red(
|
|
2447
|
+
t.fail("API数据解析失败"), s || (t.fail("未找到对应的项目群聊组!"), process.stdout.write(`${N.red(a)}
|
|
2446
2448
|
`), process.exit(1));
|
|
2447
|
-
const { code: o, message: r } = await
|
|
2448
|
-
content:
|
|
2449
|
+
const { code: o, message: r } = await Ai({
|
|
2450
|
+
content: a,
|
|
2449
2451
|
webhooks: [s.url]
|
|
2450
2452
|
});
|
|
2451
|
-
o !== 0 && t.fail(`发送消息到企微群组失败: ${N.red(r)}`), process.stdout.write(`${N.red(
|
|
2453
|
+
o !== 0 && t.fail(`发送消息到企微群组失败: ${N.red(r)}`), process.stdout.write(`${N.red(a)}
|
|
2452
2454
|
`), process.exit(1);
|
|
2453
|
-
}, Sn = async (e, t,
|
|
2454
|
-
const
|
|
2455
|
-
if (!
|
|
2455
|
+
}, Sn = async (e, t, a, n) => {
|
|
2456
|
+
const i = e.filter((u) => t.includes(u.name)).map((u) => u.swagger);
|
|
2457
|
+
if (!i.length)
|
|
2456
2458
|
throw new Error("Failed to fetch Swagger JSON");
|
|
2457
|
-
const
|
|
2458
|
-
const
|
|
2459
|
-
return
|
|
2459
|
+
const s = i.flatMap((u) => {
|
|
2460
|
+
const l = u.find((f) => f.env === a);
|
|
2461
|
+
return l ? [l.url] : [];
|
|
2460
2462
|
});
|
|
2461
|
-
if (!
|
|
2463
|
+
if (!s.length)
|
|
2462
2464
|
throw new Error("Failed to fetch Swagger JSON");
|
|
2463
|
-
const
|
|
2464
|
-
(
|
|
2465
|
+
const o = y("API数据请求中...").start(), r = await Promise.allSettled(s.map((u) => An(u, n))), c = r.flatMap(
|
|
2466
|
+
(u, l) => u.status === "rejected" ? [{ reason: u.reason, url: s[l] }] : []
|
|
2465
2467
|
);
|
|
2466
|
-
return
|
|
2467
|
-
}, kn = async (e) => {
|
|
2468
|
-
const
|
|
2469
|
-
for (const
|
|
2470
|
-
const { apis:
|
|
2471
|
-
|
|
2468
|
+
return c.length && await jn(c, o), o.succeed("API数据请求成功"), r.flatMap((u, l) => u.status === "fulfilled" ? [{ serverName: Fe(s[l]), swaggerJson: u.value }] : []);
|
|
2469
|
+
}, kn = async (e, t) => {
|
|
2470
|
+
const a = [];
|
|
2471
|
+
for (const n of e) {
|
|
2472
|
+
const { apis: i } = await Gt(n, {
|
|
2473
|
+
throwOnValidateError: !t
|
|
2474
|
+
});
|
|
2475
|
+
a.push(...i.map((s) => ({ name: s.path, value: s.path })));
|
|
2472
2476
|
}
|
|
2473
2477
|
return H({
|
|
2474
2478
|
message: "请选择需要生成的API",
|
|
2475
|
-
options: (
|
|
2479
|
+
options: (n) => n ? a.filter((i) => i.name.includes(n)) : a,
|
|
2476
2480
|
pageSize: 20,
|
|
2477
2481
|
loop: !0,
|
|
2478
2482
|
clearInputWhenSelected: !0,
|
|
2479
2483
|
multiple: !0,
|
|
2480
|
-
validate: (
|
|
2484
|
+
validate: (n) => n.length ? !0 : "至少选择一个API",
|
|
2481
2485
|
filter: !0
|
|
2482
2486
|
});
|
|
2483
|
-
},
|
|
2484
|
-
const
|
|
2487
|
+
}, En = async (e, t, a) => {
|
|
2488
|
+
const n = y("API 开始生成...").start();
|
|
2485
2489
|
try {
|
|
2486
|
-
|
|
2487
|
-
for (const { swaggerJson:
|
|
2488
|
-
if (!t.some((
|
|
2490
|
+
n.stop();
|
|
2491
|
+
for (const { swaggerJson: i, serverName: s } of e) {
|
|
2492
|
+
if (!t.some((r) => r.startsWith(`/${s}`)))
|
|
2489
2493
|
continue;
|
|
2490
|
-
const
|
|
2491
|
-
|
|
2494
|
+
const o = await _t({
|
|
2495
|
+
swaggerJson: i,
|
|
2496
|
+
merge: !0,
|
|
2497
|
+
controller: t,
|
|
2498
|
+
throwOnValidateError: !a
|
|
2499
|
+
});
|
|
2500
|
+
console.log(Wt(o, { language: "typescript", ignoreIllegals: !0 }));
|
|
2492
2501
|
}
|
|
2493
|
-
|
|
2494
|
-
} catch (
|
|
2495
|
-
|
|
2502
|
+
n.start().succeed("API 生成成功");
|
|
2503
|
+
} catch (i) {
|
|
2504
|
+
n.fail(`API 生成失败: ${i.message}`);
|
|
2496
2505
|
}
|
|
2497
|
-
},
|
|
2506
|
+
}, Tn = (e) => {
|
|
2498
2507
|
if (e) {
|
|
2499
2508
|
const t = Ze(e);
|
|
2500
2509
|
return t !== !0 && p(t), e;
|
|
@@ -2509,41 +2518,42 @@ ${e.map(t).join(`
|
|
|
2509
2518
|
}), In = async (e) => {
|
|
2510
2519
|
const t = await Rn.lintFiles(e);
|
|
2511
2520
|
await Ye.outputFixes(t);
|
|
2512
|
-
for (const
|
|
2513
|
-
const n = m.resolve(
|
|
2521
|
+
for (const a of e) {
|
|
2522
|
+
const n = m.resolve(a), i = Vt(n, "utf-8"), s = await qt.format(i, {
|
|
2514
2523
|
filepath: n
|
|
2515
2524
|
});
|
|
2516
2525
|
xt(n, s);
|
|
2517
2526
|
}
|
|
2518
|
-
}, Cn = async (e, t,
|
|
2519
|
-
const
|
|
2527
|
+
}, Cn = async (e, t, a, n) => {
|
|
2528
|
+
const i = e.map((s) => s.swaggerJson);
|
|
2520
2529
|
if (t === "single") {
|
|
2521
|
-
const
|
|
2522
|
-
await
|
|
2530
|
+
const s = await kn(i, n);
|
|
2531
|
+
await En(e, s, n);
|
|
2523
2532
|
} else {
|
|
2524
|
-
const
|
|
2525
|
-
|
|
2526
|
-
swaggerJson:
|
|
2533
|
+
const s = y("API 开始生成...").start(), o = await Ut(
|
|
2534
|
+
i.map((l) => ({
|
|
2535
|
+
swaggerJson: l,
|
|
2536
|
+
throwOnValidateError: !n
|
|
2527
2537
|
}))
|
|
2528
2538
|
);
|
|
2529
|
-
|
|
2530
|
-
const
|
|
2531
|
-
Ue.mkdirSync(
|
|
2532
|
-
const
|
|
2533
|
-
|
|
2534
|
-
for (const
|
|
2535
|
-
const { path:
|
|
2536
|
-
|
|
2539
|
+
s.stop();
|
|
2540
|
+
const r = await Tn(a), c = m.resolve(r);
|
|
2541
|
+
Ue.mkdirSync(c, { recursive: !0 });
|
|
2542
|
+
const u = [];
|
|
2543
|
+
s.start(), s.text = "API 生成中...";
|
|
2544
|
+
for (const l of o) {
|
|
2545
|
+
const { path: f, content: h } = l, g = m.resolve(c, f);
|
|
2546
|
+
u.push(g), Ue.writeFileSync(g, h);
|
|
2537
2547
|
}
|
|
2538
|
-
|
|
2548
|
+
s.text = "开始格式化代码", await In(u), s.text = "代码格式化完成", s.succeed(`API 已生成到 ${r} 目录下`);
|
|
2539
2549
|
}
|
|
2540
2550
|
};
|
|
2541
2551
|
async function xn(e, t) {
|
|
2542
|
-
|
|
2543
|
-
const { moduleList:
|
|
2544
|
-
await Cn(
|
|
2552
|
+
ae(), K();
|
|
2553
|
+
const { moduleList: a } = await yn(), { module: n, env: i, dir: s, skipSwaggerValidate: o = !1 } = t, r = await $n(n, a), c = await Nn(i), u = await Sn(a, r, c, o), l = await vn(e);
|
|
2554
|
+
await Cn(u, l, s, o), process.exit(0);
|
|
2545
2555
|
}
|
|
2546
|
-
P.command("api").alias("a").description("选择对应的服务端项目,获取接口并转成ts接口代码及类型").argument("[type]", "可选值为service单个服务, controller单个controller, single单个接口").option("--module [module]", "模块名称。多个使用逗号隔开").option("--env [env]", "指定环境。dev/test/release").option("--controller-name [controllerName]", "controller名称").option("--api-name [apiName]", "api名称").action((...e) => M(xn, ...e));
|
|
2556
|
+
P.command("api").alias("a").description("选择对应的服务端项目,获取接口并转成ts接口代码及类型").argument("[type]", "可选值为service单个服务, controller单个controller, single单个接口").option("--module [module]", "模块名称。多个使用逗号隔开").option("--env [env]", "指定环境。dev/test/release").option("--controller-name [controllerName]", "controller名称").option("--api-name [apiName]", "api名称").option("--skip-swagger-validate [skipSwaggerValidate]", "是否跳过 swagger 校验").action((...e) => M(xn, ...e));
|
|
2547
2557
|
function Pn() {
|
|
2548
2558
|
process.on("unhandledRejection", (e) => {
|
|
2549
2559
|
}), process.on("uncaughtException", (e) => {
|
|
@@ -2552,19 +2562,19 @@ function Pn() {
|
|
|
2552
2562
|
async function Dn() {
|
|
2553
2563
|
const e = ge("latestCheckVersionTimestamp"), t = ge("versionCheckDuring");
|
|
2554
2564
|
if (Date.now() - Number(e) > Number(t) * 24 * 3600 * 1e3) {
|
|
2555
|
-
const
|
|
2556
|
-
je(
|
|
2565
|
+
const a = await De();
|
|
2566
|
+
je(a);
|
|
2557
2567
|
let n;
|
|
2558
2568
|
try {
|
|
2559
|
-
const
|
|
2560
|
-
setTimeout(() => o(
|
|
2569
|
+
const i = "TIME_OUT", s = new Promise((o) => {
|
|
2570
|
+
setTimeout(() => o(i), 3e3);
|
|
2561
2571
|
});
|
|
2562
2572
|
n = await Promise.race([
|
|
2563
2573
|
s,
|
|
2564
2574
|
d(`npm view ${re.name} version --registry https://registry.npmmirror.com/`)
|
|
2565
|
-
]), n !==
|
|
2566
|
-
} catch (
|
|
2567
|
-
console.log("升级出错!请重试,或者手动升级"), p(
|
|
2575
|
+
]), n !== i && n !== re.version && (console.log(`${N.blue(re.name)}本地版本为${re.version},低于线上版本${n},开始升级`), await $t(n)), me("latestCheckVersionTimestamp", Date.now()), oe();
|
|
2576
|
+
} catch (i) {
|
|
2577
|
+
console.log("升级出错!请重试,或者手动升级"), p(i);
|
|
2568
2578
|
}
|
|
2569
2579
|
}
|
|
2570
2580
|
}
|
|
@@ -2575,10 +2585,10 @@ async function Ln() {
|
|
|
2575
2585
|
const t = I.readJSONSync(Ae());
|
|
2576
2586
|
J(t.profile), me(t.main), je(t.constants), await Dn();
|
|
2577
2587
|
} else
|
|
2578
|
-
p(`请先初始化z-develop(执行 z i)。更多见${
|
|
2588
|
+
p(`请先初始化z-develop(执行 z i)。更多见${it}`);
|
|
2579
2589
|
}
|
|
2580
2590
|
async function On() {
|
|
2581
2591
|
Pn(), await Ln();
|
|
2582
2592
|
}
|
|
2583
|
-
P.name("z-develop").alias("z").description(`z-develop, 开发流程管理工具。了解更多: ${N.blue(
|
|
2593
|
+
P.name("z-develop").alias("z").description(`z-develop, 开发流程管理工具。了解更多: ${N.blue(it)}`).usage("<command> [options]").hook("preAction", On).version(re.version, "-v, --version", "当前版本号").helpOption("-h, --help", "帮助").showHelpAfterError("可以使用z -h查看帮助。");
|
|
2584
2594
|
P.parse();
|