From 1bd6b5530e8b23d70be5aadf9654411f73f98bdd Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Sun, 15 Jun 2025 10:00:47 +0800 Subject: [PATCH] feat: add custom file paths options for ui-plugin-bundler-kit (#7552) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /area ui /kind improvement /area plugin /milestone 2.21.x #### What this PR does / why we need it: Added support for customization options to the HaloUIPluginBundlerKit. example: ```ts import { HaloUIPluginBundlerKit } from '@halo-dev/ui-plugin-bundler-kit'; export default { plugins: [ HaloUIPluginBundlerKit({ outDir: { dev: "../custom/dev/path", prod: "../custom/prod/path" }, manifestPath: "../custom/plugin.yaml" }) ] } ``` #### Does this PR introduce a user-facing change? ```release-note `@halo-dev/ui-plugin-bundler-kit` 支持自定义 `outDir` 和 `manifestPath`。 ``` --- .../ui-plugin-bundler-kit/src/index.ts | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/ui/packages/ui-plugin-bundler-kit/src/index.ts b/ui/packages/ui-plugin-bundler-kit/src/index.ts index 239f63b9e..a0c4a81ce 100644 --- a/ui/packages/ui-plugin-bundler-kit/src/index.ts +++ b/ui/packages/ui-plugin-bundler-kit/src/index.ts @@ -3,20 +3,42 @@ import fs from "fs"; import yaml from "js-yaml"; import { Plugin } from "vite"; -export function HaloUIPluginBundlerKit(): Plugin { +const DEFAULT_OUT_DIR_DEV = "../src/main/resources/console"; +const DEFAULT_OUT_DIR_PROD = "../build/resources/main/console"; +const DEFAULT_MANIFEST_PATH = "../src/main/resources/plugin.yaml"; + +interface HaloUIPluginBundlerKitOptions { + outDir?: + | string + | { + dev: string; + prod: string; + }; + manifestPath?: string; +} + +export function HaloUIPluginBundlerKit( + options: HaloUIPluginBundlerKitOptions = {} +): Plugin { return { name: "halo-ui-plugin-bundler-kit", config(config, env) { const isProduction = env.mode === "production"; - // fixme: allow user to config outDir - const outDir = isProduction - ? "../src/main/resources/console" - : "../build/resources/main/console"; + let outDir = isProduction ? DEFAULT_OUT_DIR_PROD : DEFAULT_OUT_DIR_DEV; + + if (options.outDir) { + if (typeof options.outDir === "string") { + outDir = options.outDir; + } else { + outDir = isProduction ? options.outDir.prod : options.outDir.dev; + } + } + + const manifestPath = options.manifestPath || DEFAULT_MANIFEST_PATH; - // fixme: allow user to config manifest path const manifest = yaml.load( - fs.readFileSync("../src/main/resources/plugin.yaml", "utf8") + fs.readFileSync(manifestPath, "utf8") ) as HaloPlugin; return {