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