|
1
|
import { rm } from "node:fs/promises" |
|
2
|
import path from "node:path" |
|
3
|
import type { Plugin } from "vite" |
|
4
|
|
|
5
|
interface ClearPluginBuildOptions { |
|
6
|
outDir: string |
|
7
|
} |
|
8
|
|
|
9
|
export const clearPluginBuild = (options: ClearPluginBuildOptions): Plugin => ({ |
|
10
|
name: "medusa:clear-plugin-build", |
|
11
|
buildStart: async () => { |
|
12
|
const adminDir = path.join(options.outDir, "admin") |
|
13
|
try { |
|
14
|
await rm(adminDir, { recursive: true, force: true }) |
|
15
|
} catch (e) { |
|
16
|
// Directory might not exist, ignore |
|
17
|
} |
|
18
|
}, |
|
19
|
}) |