cli-z-develop 0.14.8 → 0.14.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +49 -44
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19,13 +19,13 @@ import zt from "semver";
|
|
|
19
19
|
import { run as Ft } from "npm-check-updates";
|
|
20
20
|
import Jt from "p-limit";
|
|
21
21
|
import { generateTypescriptBundleApi as Ut, validateSwagger as Bt, getParsedSwagger as Gt, generateTypescriptApi as _t } from "@lonely9/api-generate";
|
|
22
|
-
import { highlight as
|
|
22
|
+
import { highlight as Wt } from "cli-highlight";
|
|
23
23
|
import { ESLint as Ye } from "eslint";
|
|
24
|
-
import { readFileSync as
|
|
24
|
+
import { readFileSync as Vt } from "fs";
|
|
25
25
|
import qt from "prettier";
|
|
26
26
|
import Zt from "minimist";
|
|
27
27
|
const Qe = "dev", et = "test", tt = "release", Ht = "production", Kt = "master";
|
|
28
|
-
var E = /* @__PURE__ */ ((e) => (e[e.DEV = Qe] = "DEV", e[e.TEST = et] = "TEST", e[e.RELEASE = tt] = "RELEASE", e[e.PROD = Ht] = "PROD", e))(E || {}), $ = /* @__PURE__ */ ((e) => (e[e.DEV = Qe] = "DEV", e[e.TEST = et] = "TEST", e[e.RELEASE = tt] = "RELEASE", e[e.MASTER = Kt] = "MASTER", e))($ || {}),
|
|
28
|
+
var E = /* @__PURE__ */ ((e) => (e[e.DEV = Qe] = "DEV", e[e.TEST = et] = "TEST", e[e.RELEASE = tt] = "RELEASE", e[e.PROD = Ht] = "PROD", e))(E || {}), $ = /* @__PURE__ */ ((e) => (e[e.DEV = Qe] = "DEV", e[e.TEST = et] = "TEST", e[e.RELEASE = tt] = "RELEASE", e[e.MASTER = Kt] = "MASTER", e))($ || {}), V = /* @__PURE__ */ ((e) => (e.H5 = "h5", e.NPM = "npm", e.SERVER = "server", e))(V || {});
|
|
29
29
|
const at = [
|
|
30
30
|
{
|
|
31
31
|
name: `开发环境 - ${E.DEV}`,
|
|
@@ -129,7 +129,7 @@ function ot(e, t) {
|
|
|
129
129
|
const { red: _e, green: ca, blue: cs, magenta: ua, yellow: la } = N;
|
|
130
130
|
function ye(...e) {
|
|
131
131
|
}
|
|
132
|
-
function
|
|
132
|
+
function We(...e) {
|
|
133
133
|
console.log(la(...e));
|
|
134
134
|
}
|
|
135
135
|
function q(...e) {
|
|
@@ -143,11 +143,11 @@ function p(e, t = !1) {
|
|
|
143
143
|
let a = e;
|
|
144
144
|
e instanceof Error ? (a = e.message, le.isAxiosError(e) && (a = `请求失败:${e.message}`), console.log(_e(a)), console.log(ua(e.stack))) : console.log(_e(e)), t || process.exit(1);
|
|
145
145
|
}
|
|
146
|
-
function
|
|
146
|
+
function Ve(e) {
|
|
147
147
|
return A(e) ? It(e).isDirectory() : !1;
|
|
148
148
|
}
|
|
149
149
|
function ut(e = process.cwd()) {
|
|
150
|
-
return
|
|
150
|
+
return Ve(e) ? Rt(e).filter((a) => Ve(m.resolve(e, a))) : [];
|
|
151
151
|
}
|
|
152
152
|
async function d(e, t = {
|
|
153
153
|
removeTailLinkBreak: !0,
|
|
@@ -279,7 +279,7 @@ const wa = {
|
|
|
279
279
|
"**/*.{vue,js,jsx,cjs,mjs,ts,tsx,cts,mts}": "eslint --fix",
|
|
280
280
|
"**/*.md": "markdownlint --fix"
|
|
281
281
|
}
|
|
282
|
-
}, ya = "cli-z-develop", va = "0.14.
|
|
282
|
+
}, ya = "cli-z-develop", va = "0.14.9", $a = "技术团队开发流程管理工具", Na = "dist/index.js", Aa = { z: "bin/z.js", "z-develop": "bin/z.js" }, ba = { prepare: "[ -n '$z' ] && z init prepare || echo 'Warning: z not exist at global'", dev: "vite build --watch", test: "bun src/main.ts", "test:debug": "DEBUG=true bun src/main.ts", "dev:debug": "DEBUG=true vite build --watch", build: "vite build", "build:w": "vite build --watch", eslint: "eslint '**/*.{ts,js}' --fix", prettier: "prettier -wu .", upload: "npm run build && npm publish --access public --registry https://registry.npmjs.org/", "upload:patch": "npm version patch && npm run upload", "upload:minor": "npm version minor && npm run upload", "upload:major": "npm version major && npm run upload" }, ja = "module", Sa = "z", ka = { "@lonely9/eslint-config-team": "^1.3.8", "@tsconfig/node22": "^22.0.5", "@types/fs-extra": "^11.0.4", "@types/inquirer": "^9.0.9", "@types/minimist": "^1.2.5", "@types/node": "^22.15.29", "@types/semver": "^7.7.1", "@types/shelljs": "^0.10.0", "@typescript-eslint/eslint-plugin": "^8.58.2", "@typescript-eslint/parser": "^8.58.2", eslint: "^9.39.2", jiti: "^2.6.1", prettier: "^3.8.2", typescript: "^5.9.3", vite: "^7.3.1", "vue-tsc": "^3.2.6" }, Ea = { "@inquirer/prompts": "^8.4.1", "@lonely9/api-generate": "^0.2.8", axios: "^1.15.0", chalk: "^5.6.2", "cli-highlight": "^2.1.11", commander: "^14.0.3", dayjs: "^1.11.20", eslint: "^9.39.2", "fs-extra": "^11.3.4", "inquirer-select-pro": "^1.0.0-alpha.9", "lint-staged": "^16.4.0", minimist: "^1.2.8", "npm-check-updates": "^19.3.1", ora: "^9.3.0", "p-limit": "^7.3.0", prettier: "^3.8.2", semver: "^7.7.4", shelljs: "^0.10.0" }, re = {
|
|
283
283
|
name: ya,
|
|
284
284
|
version: va,
|
|
285
285
|
description: $a,
|
|
@@ -333,7 +333,7 @@ function ge(e) {
|
|
|
333
333
|
function B(e) {
|
|
334
334
|
return e ? x.constants[e] : x.constants;
|
|
335
335
|
}
|
|
336
|
-
let _ = null,
|
|
336
|
+
let _ = null, W = null;
|
|
337
337
|
function Pe() {
|
|
338
338
|
if (_)
|
|
339
339
|
return _;
|
|
@@ -341,18 +341,18 @@ function Pe() {
|
|
|
341
341
|
return A(e) || p(`当前目录(${L.pwd()})不存在${e}文件,请在项目根目录执行该命令。`), _ = I.readJsonSync(e), _;
|
|
342
342
|
}
|
|
343
343
|
function ie() {
|
|
344
|
-
if (
|
|
345
|
-
return
|
|
344
|
+
if (W)
|
|
345
|
+
return W;
|
|
346
346
|
const e = nt();
|
|
347
347
|
return A(e) || p(
|
|
348
348
|
`当前目录(${L.pwd()})不存在${e}文件,请在项目根目录执行该命令,或者初始化项目(z init .)。`
|
|
349
|
-
),
|
|
349
|
+
), W = I.readJsonSync(e), W;
|
|
350
350
|
}
|
|
351
351
|
function mt(e) {
|
|
352
|
-
|
|
353
|
-
...
|
|
352
|
+
W ? W = {
|
|
353
|
+
...W,
|
|
354
354
|
...e
|
|
355
|
-
} :
|
|
355
|
+
} : W = e, I.writeJSONSync(nt(), W, { spaces: 2 });
|
|
356
356
|
}
|
|
357
357
|
function Ta(e) {
|
|
358
358
|
_ ? _ = {
|
|
@@ -595,12 +595,12 @@ function _a() {
|
|
|
595
595
|
url: `${z()}/user`
|
|
596
596
|
});
|
|
597
597
|
}
|
|
598
|
-
function
|
|
598
|
+
function Wa() {
|
|
599
599
|
return b({
|
|
600
600
|
url: `${z()}/groups`
|
|
601
601
|
});
|
|
602
602
|
}
|
|
603
|
-
function
|
|
603
|
+
function Va(e) {
|
|
604
604
|
return b({
|
|
605
605
|
url: `${z()}/projects`,
|
|
606
606
|
method: "post",
|
|
@@ -664,7 +664,7 @@ function ei() {
|
|
|
664
664
|
return A(e) ? I.readJSONSync(e) : { groups: [] };
|
|
665
665
|
}
|
|
666
666
|
async function ti() {
|
|
667
|
-
const e = await
|
|
667
|
+
const e = await Wa(), t = Qt.map((a) => {
|
|
668
668
|
const n = e.find((i) => i.name === a);
|
|
669
669
|
return n ? {
|
|
670
670
|
name: n.name,
|
|
@@ -1115,10 +1115,10 @@ async function qe(e, t) {
|
|
|
1115
1115
|
} catch {
|
|
1116
1116
|
}
|
|
1117
1117
|
if (i.length === 0)
|
|
1118
|
-
return
|
|
1118
|
+
return We("文件太大,无法生成commit msg"), t.stop(), await Ce();
|
|
1119
1119
|
const s = await d(`git diff HEAD -- ${i.map((r) => `"${r}"`).join(" ")}`);
|
|
1120
1120
|
if (!s)
|
|
1121
|
-
return
|
|
1121
|
+
return We("无法获取文件差异信息"), t.stop(), await Ce();
|
|
1122
1122
|
const o = await Ni({
|
|
1123
1123
|
type: "commit-message-v2",
|
|
1124
1124
|
input: s
|
|
@@ -1250,7 +1250,7 @@ async function zi() {
|
|
|
1250
1250
|
await d("npm install --registry https://registry.npmmirror.com/"), r.succeed("依赖安装完成");
|
|
1251
1251
|
const c = y("项目推送中").start();
|
|
1252
1252
|
await d('git add . && git commit -m "chore: 项目初始化"'), await d("git tag v0.0.1");
|
|
1253
|
-
const u = await
|
|
1253
|
+
const u = await Va({
|
|
1254
1254
|
name: e.projectName,
|
|
1255
1255
|
description: e.projectDesc,
|
|
1256
1256
|
path: e.projectName,
|
|
@@ -1324,20 +1324,20 @@ const Ji = async (e) => {
|
|
|
1324
1324
|
};
|
|
1325
1325
|
function Ui(e, t) {
|
|
1326
1326
|
const a = Pe();
|
|
1327
|
-
if (ie()?.repository?.url || p(".z/project.json中缺少repository.url"), t ===
|
|
1327
|
+
if (ie()?.repository?.url || p(".z/project.json中缺少repository.url"), t === V.H5) {
|
|
1328
1328
|
const i = `build:${e}`;
|
|
1329
1329
|
a?.scripts[i] || p(`项目package.json文件scripts不存在命令${i}。`);
|
|
1330
1330
|
}
|
|
1331
|
-
t ===
|
|
1331
|
+
t === V.NPM && (a?.scripts.build || p("项目package.json文件scripts不存在命令build。")), t === V.SERVER && (a?.scripts.build || p("项目package.json文件scripts不存在命令build。"));
|
|
1332
1332
|
}
|
|
1333
1333
|
async function yt(e, t) {
|
|
1334
1334
|
ae(), K();
|
|
1335
1335
|
let a = e, n = t.platform;
|
|
1336
1336
|
const i = ie();
|
|
1337
|
-
if (i.language === w.JAVA && (n =
|
|
1337
|
+
if (i.language === w.JAVA && (n = V.SERVER), a && !Object.values($).includes(a) && p("仅支持发布指定环境分支"), n && !Object.values(V).includes(n) && p("发布平台错误"), n || (n = await k({
|
|
1338
1338
|
message: "请选择平台",
|
|
1339
1339
|
choices: Xt
|
|
1340
|
-
})), n ===
|
|
1340
|
+
})), n === V.NPM && (a = $.MASTER), !a) {
|
|
1341
1341
|
const u = await k({
|
|
1342
1342
|
message: "请选择部署环境",
|
|
1343
1343
|
choices: at
|
|
@@ -1497,8 +1497,8 @@ async function Gi(e, t) {
|
|
|
1497
1497
|
skipGroupNotification: t.skipGroupNotification
|
|
1498
1498
|
});
|
|
1499
1499
|
}
|
|
1500
|
-
P.command("merge").alias("m").description("合并当前分支到指定远程分支,并部署。").argument("[branch]", "目标分支名称").option("--deploy-platform <platform>", `合并成功后要部署的平台。可选值:${Object.values(
|
|
1501
|
-
P.command("deploy").alias("d").description("部署到指定环境").argument("[branchName]", `部署环境。可选值:${Object.values($).join("/")}`).option("--platform <platform>", `部署平台。可选值:${Object.values(
|
|
1500
|
+
P.command("merge").alias("m").description("合并当前分支到指定远程分支,并部署。").argument("[branch]", "目标分支名称").option("--deploy-platform <platform>", `合并成功后要部署的平台。可选值:${Object.values(V).join("/")}`).option("--deploy-skip-selection-notification", "部署时,是否跳过选择部署通知人环节").option("--skip-group-notification", "是否跳过选择部署通知群聊环节").option("--keep-branch-after-merge-master", "在合并到主分支之后,是否保留分支。默认否").action((...e) => M(Gi, ...e));
|
|
1501
|
+
P.command("deploy").alias("d").description("部署到指定环境").argument("[branchName]", `部署环境。可选值:${Object.values($).join("/")}`).option("--platform <platform>", `部署平台。可选值:${Object.values(V).join("/")}`).option("--module <module>", "部署模块。Java项目适用,填入要部署的模块名称,多个使用逗号分隔").option("--skip-selection-notification", "是否跳过选择部署通知人环节").option("--skip-group-notification", "是否跳过选择部署通知群聊环节").action((...e) => M(yt, ...e));
|
|
1502
1502
|
async function _i() {
|
|
1503
1503
|
try {
|
|
1504
1504
|
await d("java -jar ./.z/checkstyle.jar -c ./.z/checkstyle.xml .", {
|
|
@@ -1508,7 +1508,7 @@ async function _i() {
|
|
|
1508
1508
|
p("checkstyle执行出错"), process.exit(1);
|
|
1509
1509
|
}
|
|
1510
1510
|
}
|
|
1511
|
-
async function
|
|
1511
|
+
async function Wi() {
|
|
1512
1512
|
A(m.resolve("node_modules", ".bin", "markdownlint")) || p("该项目未安装markdownlint,请安装后重试");
|
|
1513
1513
|
const e = y("markdownlint执行中...").start();
|
|
1514
1514
|
try {
|
|
@@ -1519,7 +1519,7 @@ async function Vi() {
|
|
|
1519
1519
|
e.fail("markdownlint校验出错"), process.exit(1);
|
|
1520
1520
|
}
|
|
1521
1521
|
}
|
|
1522
|
-
function
|
|
1522
|
+
function Vi() {
|
|
1523
1523
|
const e = ie();
|
|
1524
1524
|
if (e["lint-staged"])
|
|
1525
1525
|
return e["lint-staged"];
|
|
@@ -1530,7 +1530,7 @@ async function qi() {
|
|
|
1530
1530
|
await Mt({
|
|
1531
1531
|
concurrent: 4,
|
|
1532
1532
|
debug: !1,
|
|
1533
|
-
config:
|
|
1533
|
+
config: Vi(),
|
|
1534
1534
|
quiet: !0,
|
|
1535
1535
|
relative: !0
|
|
1536
1536
|
}) ? (e.succeed("代码风格检测通过!"), process.exit(0)) : (e.fail("代码风格检测未通过!"), process.exit(1));
|
|
@@ -1688,7 +1688,7 @@ async function en(e, t) {
|
|
|
1688
1688
|
choices: i
|
|
1689
1689
|
});
|
|
1690
1690
|
}
|
|
1691
|
-
n === "commit-msg" ? await Hi() : n === "commit-files" ? await qi() : n === "prettier" ? await Yi() : n === "eslint" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? await Xi(t) : n === "type-check" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? Qi() : n === "dependency-check" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? await Ki() : n === "checkstyle" && a.language === w.JAVA ? await _i() : n === "markdown-lint" && a.language === w.MARKDOWN && await
|
|
1691
|
+
n === "commit-msg" ? await Hi() : n === "commit-files" ? await qi() : n === "prettier" ? await Yi() : n === "eslint" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? await Xi(t) : n === "type-check" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? Qi() : n === "dependency-check" && [w.JAVASCRIPT, w.MARKDOWN].includes(a.language) ? await Ki() : n === "checkstyle" && a.language === w.JAVA ? await _i() : n === "markdown-lint" && a.language === w.MARKDOWN && await Wi();
|
|
1692
1692
|
}
|
|
1693
1693
|
P.command("run").alias("r").description("执行 eslint / prettier / type-check / dependency-check / checkstyle / markdown-lint。").argument(
|
|
1694
1694
|
"[type]",
|
|
@@ -2470,7 +2470,7 @@ ${e.map(t).join(`
|
|
|
2470
2470
|
const a = [];
|
|
2471
2471
|
for (const n of e) {
|
|
2472
2472
|
const { apis: i } = await Gt(n, {
|
|
2473
|
-
throwOnValidateError: !
|
|
2473
|
+
throwOnValidateError: !t
|
|
2474
2474
|
});
|
|
2475
2475
|
a.push(...i.map((s) => ({ name: s.path, value: s.path })));
|
|
2476
2476
|
}
|
|
@@ -2484,19 +2484,24 @@ ${e.map(t).join(`
|
|
|
2484
2484
|
validate: (n) => n.length ? !0 : "至少选择一个API",
|
|
2485
2485
|
filter: !0
|
|
2486
2486
|
});
|
|
2487
|
-
}, En = async (e, t) => {
|
|
2488
|
-
const
|
|
2487
|
+
}, En = async (e, t, a) => {
|
|
2488
|
+
const n = y("API 开始生成...").start();
|
|
2489
2489
|
try {
|
|
2490
|
-
|
|
2491
|
-
for (const { swaggerJson:
|
|
2492
|
-
if (!t.some((
|
|
2490
|
+
n.stop();
|
|
2491
|
+
for (const { swaggerJson: i, serverName: s } of e) {
|
|
2492
|
+
if (!t.some((r) => r.startsWith(`/${s}`)))
|
|
2493
2493
|
continue;
|
|
2494
|
-
const
|
|
2495
|
-
|
|
2494
|
+
const o = await _t({
|
|
2495
|
+
swaggerJson: i,
|
|
2496
|
+
merge: !0,
|
|
2497
|
+
controller: t,
|
|
2498
|
+
throwOnValidateError: !a
|
|
2499
|
+
});
|
|
2500
|
+
console.log(Wt(o, { language: "typescript", ignoreIllegals: !0 }));
|
|
2496
2501
|
}
|
|
2497
|
-
|
|
2498
|
-
} catch (
|
|
2499
|
-
|
|
2502
|
+
n.start().succeed("API 生成成功");
|
|
2503
|
+
} catch (i) {
|
|
2504
|
+
n.fail(`API 生成失败: ${i.message}`);
|
|
2500
2505
|
}
|
|
2501
2506
|
}, Tn = (e) => {
|
|
2502
2507
|
if (e) {
|
|
@@ -2514,7 +2519,7 @@ ${e.map(t).join(`
|
|
|
2514
2519
|
const t = await Rn.lintFiles(e);
|
|
2515
2520
|
await Ye.outputFixes(t);
|
|
2516
2521
|
for (const a of e) {
|
|
2517
|
-
const n = m.resolve(a), i =
|
|
2522
|
+
const n = m.resolve(a), i = Vt(n, "utf-8"), s = await qt.format(i, {
|
|
2518
2523
|
filepath: n
|
|
2519
2524
|
});
|
|
2520
2525
|
xt(n, s);
|
|
@@ -2522,8 +2527,8 @@ ${e.map(t).join(`
|
|
|
2522
2527
|
}, Cn = async (e, t, a, n) => {
|
|
2523
2528
|
const i = e.map((s) => s.swaggerJson);
|
|
2524
2529
|
if (t === "single") {
|
|
2525
|
-
const s = await kn(i);
|
|
2526
|
-
await En(e, s);
|
|
2530
|
+
const s = await kn(i, n);
|
|
2531
|
+
await En(e, s, n);
|
|
2527
2532
|
} else {
|
|
2528
2533
|
const s = y("API 开始生成...").start(), o = await Ut(
|
|
2529
2534
|
i.map((l) => ({
|