|
1 | | -import { defineConfig } from "vite"; |
| 1 | +import { defineConfig, type Plugin } from "vite"; |
2 | 2 | import { fresh } from "@fresh/plugin-vite"; |
3 | 3 | import tailwindcss from "@tailwindcss/vite"; |
4 | 4 | import inspect from "vite-plugin-inspect"; |
| 5 | +import { copy } from "@std/fs"; |
| 6 | +import * as path from "@std/path"; |
5 | 7 |
|
6 | 8 | export default defineConfig({ |
7 | 9 | plugins: [ |
8 | 10 | fresh(), |
9 | 11 | tailwindcss(), |
10 | 12 | inspect(), |
| 13 | + copyDocs(), |
11 | 14 | ], |
12 | 15 | }); |
| 16 | + |
| 17 | +function copyDocs(): Plugin { |
| 18 | + let serverOutDir = ""; |
| 19 | + |
| 20 | + return { |
| 21 | + name: "fresh:copy-docs", |
| 22 | + configResolved(config) { |
| 23 | + serverOutDir = config.environments.ssr.build.outDir; |
| 24 | + }, |
| 25 | + async writeBundle() { |
| 26 | + const branches = ["canary", "latest"]; |
| 27 | + |
| 28 | + for (const branch of branches) { |
| 29 | + const source = path.join(import.meta.dirname!, "..", "docs", branch); |
| 30 | + const target = path.join(serverOutDir, "docs", branch); |
| 31 | + |
| 32 | + try { |
| 33 | + await Deno.remove(target, { recursive: true }); |
| 34 | + } catch (err) { |
| 35 | + if (!(err instanceof Deno.errors.NotFound)) { |
| 36 | + throw err; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + try { |
| 41 | + await Deno.mkdir(path.dirname(target), { recursive: true }); |
| 42 | + } catch { |
| 43 | + // Ignore |
| 44 | + } |
| 45 | + |
| 46 | + // await new Promise((r) => setTimeout(r, 2220000)); |
| 47 | + await copy(source, target); |
| 48 | + } |
| 49 | + }, |
| 50 | + }; |
| 51 | +} |
0 commit comments