cloudflare/kumo
Publicmirrored fromhttps://github.com/cloudflare/kumoAvailable
packages/kumo-docs-astro/astro.config.mjs
78lines · modecode
| 1 | // @ts-check |
| 2 | import { defineConfig } from "astro/config"; |
| 3 | import react from "@astrojs/react"; |
| 4 | import tailwindcss from "@tailwindcss/vite"; |
| 5 | import { execSync } from "child_process"; |
| 6 | import { readFileSync } from "fs"; |
| 7 | import { resolve } from "path"; |
| 8 | import { fileURLToPath } from "url"; |
| 9 | import { kumoColorsPlugin } from "./src/lib/vite-plugin-kumo-colors.js"; |
| 10 | import { kumoRegistryPlugin } from "./src/lib/vite-plugin-kumo-registry.js"; |
| 11 | |
| 12 | const __dirname = fileURLToPath(new URL(".", import.meta.url)); |
| 13 | |
| 14 | function getBuildInfo() { |
| 15 | // Read version from the main kumo package |
| 16 | const kumoPkg = JSON.parse( |
| 17 | readFileSync(resolve(__dirname, "../kumo/package.json"), "utf-8"), |
| 18 | ); |
| 19 | |
| 20 | // Read version from the docs-astro package |
| 21 | const docsPkg = JSON.parse( |
| 22 | readFileSync(resolve(__dirname, "package.json"), "utf-8"), |
| 23 | ); |
| 24 | |
| 25 | let commitHash = "unknown"; |
| 26 | let commitDate = "unknown"; |
| 27 | let branch = "unknown"; |
| 28 | |
| 29 | try { |
| 30 | commitHash = execSync("git rev-parse --short HEAD", { |
| 31 | encoding: "utf-8", |
| 32 | }).trim(); |
| 33 | commitDate = execSync("git log -1 --format=%cI", { |
| 34 | encoding: "utf-8", |
| 35 | }).trim(); |
| 36 | branch = execSync("git rev-parse --abbrev-ref HEAD", { |
| 37 | encoding: "utf-8", |
| 38 | }).trim(); |
| 39 | } catch (error) { |
| 40 | console.warn( |
| 41 | "[kumo-docs-astro] Git info unavailable during build:", |
| 42 | error instanceof Error ? error.message : error, |
| 43 | ); |
| 44 | console.warn( |
| 45 | "[kumo-docs-astro] This may happen with shallow clones. Set GIT_DEPTH=0 or fetch-depth: 0 in CI.", |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | return { |
| 50 | kumoVersion: kumoPkg.version, |
| 51 | docsVersion: docsPkg.version, |
| 52 | commitHash, |
| 53 | commitDate, |
| 54 | branch, |
| 55 | buildDate: new Date().toISOString(), |
| 56 | }; |
| 57 | } |
| 58 | |
| 59 | const buildInfo = getBuildInfo(); |
| 60 | |
| 61 | // https://astro.build/config |
| 62 | export default defineConfig({ |
| 63 | integrations: [react()], |
| 64 | vite: { |
| 65 | // @ts-expect-error - Vite version mismatch between Astro and @tailwindcss/vite |
| 66 | plugins: [tailwindcss(), kumoColorsPlugin(), kumoRegistryPlugin()], |
| 67 | |
| 68 | define: { |
| 69 | __KUMO_VERSION__: JSON.stringify(buildInfo.kumoVersion), |
| 70 | __DOCS_VERSION__: JSON.stringify(buildInfo.docsVersion), |
| 71 | __BUILD_VERSION__: JSON.stringify(buildInfo.kumoVersion), // Alias for backwards compatibility |
| 72 | __BUILD_COMMIT__: JSON.stringify(buildInfo.commitHash), |
| 73 | __BUILD_COMMIT_DATE__: JSON.stringify(buildInfo.commitDate), |
| 74 | __BUILD_BRANCH__: JSON.stringify(buildInfo.branch), |
| 75 | __BUILD_DATE__: JSON.stringify(buildInfo.buildDate), |
| 76 | }, |
| 77 | }, |
| 78 | }); |
| 79 | |