feat: add custom file paths options for ui-plugin-bundler-kit (#7552)

#### 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`。
```
pull/7553/head^2
Ryan Wang 2025-06-15 10:00:47 +08:00 committed by GitHub
parent 5ec975e75b
commit 1bd6b5530e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 7 deletions

View File

@ -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 {