From d2faba9d3a7fed126a63826518b4a395ace90196 Mon Sep 17 00:00:00 2001 From: ruan-cat <1219043956@qq.com> Date: Tue, 22 Oct 2024 11:29:46 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8E=20ci(vite-plugin-autogeneration-im?= =?UTF-8?q?port-file-test-app-1):=20=E6=8B=93=E5=B1=95=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=EF=BC=8C=E6=8F=90=E4=BE=9B=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=96=87=E4=BB=B6=E7=9A=84=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=EF=BC=9B=E6=8B=93=E5=B1=95turbo=E5=91=BD=E4=BB=A4=E8=B0=83?= =?UTF-8?q?=E5=BA=A6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- .../app/package.json | 3 +- .../app/scripts/del-types.ts | 50 +++++++++++++++++++ .../app/turbo.json | 7 +++ .../core/package.json | 3 +- 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 vite-plugin-autogeneration-import-file/app/scripts/del-types.ts diff --git a/package.json b/package.json index 36aa780..ea4e2fb 100644 --- a/package.json +++ b/package.json @@ -62,10 +62,12 @@ "@types/node": "^20.16.11", "@vuepress/bundler-vite": "2.0.0-rc.18", "commitizen": "^4.3.1", + "consola": "^3.2.3", "cpx2": "^7.0.2", "cross-env": "^7.0.3", "cz-git": "^1.10.1", "czg": "^1.10.1", + "del": "^8.0.0", "esbuild": "^0.23.1", "esbuild-register": "^3.6.0", "eslint": "^9.12.0", @@ -103,7 +105,6 @@ }, "dependencies": { "@dotenvx/dotenvx": "^1.17.0", - "consola": "^3.2.3", "lodash-es": "catalog:" } } diff --git a/vite-plugin-autogeneration-import-file/app/package.json b/vite-plugin-autogeneration-import-file/app/package.json index 5194805..7e902b3 100644 --- a/vite-plugin-autogeneration-import-file/app/package.json +++ b/vite-plugin-autogeneration-import-file/app/package.json @@ -8,8 +8,9 @@ "dev": "vite", "build": " vite build", "preview": "vite preview", - "predev": "turbo do-plugin-build", + "predev": "turbo do-predev", "rm:node_modules": "rimraf node_modules", + "rm:types": "node --import=tsx ./scripts/del-types.ts", "clean": "rimraf dist .turbo" }, "dependencies": { diff --git a/vite-plugin-autogeneration-import-file/app/scripts/del-types.ts b/vite-plugin-autogeneration-import-file/app/scripts/del-types.ts new file mode 100644 index 0000000..ece50e0 --- /dev/null +++ b/vite-plugin-autogeneration-import-file/app/scripts/del-types.ts @@ -0,0 +1,50 @@ +// 删除多余的类型 + +import { deleteAsync } from "del"; +import { consola } from "consola"; + +import { dirname, resolve } from "node:path"; + +/** + * 拼接路径 + * @private + * 不作为公共方法 与特定路径强耦合的 + * + * @deprecated + * 不需要 对应的删除函数不需要生成具体的路径 + */ +function joinPath(dir: string): string { + const resPath = resolve("..", "types", dir); + // console.log(" in joinPath => ", resPath); + return resPath; +} + +/** + * TODO: 拆分成各个小配置字符串,移植到vite配置内,作为静态常量。 + */ +const filenames = [ + // + // "components-instance.d.ts", + // "components.d.ts", + // 填写glob语法 对于 deleteAsync 函数匹配有效。 + "components*.d.ts", + "typed-router.d.ts", + "auto-imports.d.ts", +]; + +type Filename = (typeof filenames)[number]; + +function createTypeFilePath(filename: Filename) { + return `./types/${filename}`; +} + +filenames.forEach(async (filename) => { + const typeFilePath = createTypeFilePath(filename); + try { + const resDeleteAsync = await deleteAsync(typeFilePath); + // consola.info(" 查看删除文件的返回值路径: ", resDeleteAsync); + consola.success(`删除类型文件 ${filename} 成功`); + } catch (error) { + consola.error(`删除类型文件 ${filename} 失败`); + } +}); diff --git a/vite-plugin-autogeneration-import-file/app/turbo.json b/vite-plugin-autogeneration-import-file/app/turbo.json index 7532f42..b703c8a 100644 --- a/vite-plugin-autogeneration-import-file/app/turbo.json +++ b/vite-plugin-autogeneration-import-file/app/turbo.json @@ -8,6 +8,13 @@ "dependsOn": [ "@ruan-cat-test/vite-plugin-autogeneration-import-file#build" ] + }, + "rm:types": {}, + "do-predev": { + "dependsOn": [ + "rm:types", + "do-plugin-build" + ] } } } \ No newline at end of file diff --git a/vite-plugin-autogeneration-import-file/core/package.json b/vite-plugin-autogeneration-import-file/core/package.json index a4a0a8a..7e95796 100644 --- a/vite-plugin-autogeneration-import-file/core/package.json +++ b/vite-plugin-autogeneration-import-file/core/package.json @@ -19,7 +19,8 @@ "scripts": { "test": "pnpm run build", "clean": "rimraf dist .turbo", - "build": "pnpm run clean && microbundle --target node -f esm,cjs", + "clean:dist": "rimraf dist", + "build": "pnpm run clean:dist && microbundle --target node -f esm,cjs", "rm:node_modules": "rimraf node_modules" }, "dependencies": {