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