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