cloudflare/kumo

Public

mirrored fromhttps://github.com/cloudflare/kumoAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dcc30c61f1ff301fa2f86d737fe9029352677b34

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/kumo-docs-astro/astro.config.mjs

90lines · modecode

1// @ts-check
2import { defineConfig } from "astro/config";
3import react from "@astrojs/react";
4import tailwindcss from "@tailwindcss/vite";
5import { execSync } from "child_process";
6import { readFileSync } from "fs";
7import { resolve } from "path";
8import { fileURLToPath } from "url";
9import { kumoColorsPlugin } from "./src/lib/vite-plugin-kumo-colors.js";
10import { kumoRegistryPlugin } from "./src/lib/vite-plugin-kumo-registry.js";
11import { kumoHmrPlugin } from "./src/lib/vite-plugin-kumo-hmr.js";
12
13const __dirname = fileURLToPath(new URL(".", import.meta.url));
14
15function getBuildInfo() {
16 // Read version from the main kumo package
17 const kumoPkg = JSON.parse(
18 readFileSync(resolve(__dirname, "../kumo/package.json"), "utf-8"),
19 );
20
21 // Read version from the docs-astro package
22 const docsPkg = JSON.parse(
23 readFileSync(resolve(__dirname, "package.json"), "utf-8"),
24 );
25
26 let commitHash = "unknown";
27 let commitDate = "unknown";
28 let branch = "unknown";
29
30 try {
31 commitHash = execSync("git rev-parse --short HEAD", {
32 encoding: "utf-8",
33 }).trim();
34 commitDate = execSync("git log -1 --format=%cI", {
35 encoding: "utf-8",
36 }).trim();
37 branch = execSync("git rev-parse --abbrev-ref HEAD", {
38 encoding: "utf-8",
39 }).trim();
40 } catch (error) {
41 console.warn(
42 "[kumo-docs-astro] Git info unavailable during build:",
43 error instanceof Error ? error.message : error,
44 );
45 console.warn(
46 "[kumo-docs-astro] This may happen with shallow clones. Set GIT_DEPTH=0 or fetch-depth: 0 in CI.",
47 );
48 }
49
50 return {
51 kumoVersion: kumoPkg.version,
52 docsVersion: docsPkg.version,
53 commitHash,
54 commitDate,
55 branch,
56 buildDate: new Date().toISOString(),
57 };
58}
59
60const buildInfo = getBuildInfo();
61
62// Detect dev mode: `astro dev` sets this in process.argv
63const isDev = process.argv.includes("dev");
64
65// https://astro.build/config
66export default defineConfig({
67 integrations: [react()],
68 vite: {
69 plugins: [
70 // @ts-expect-error - Vite version mismatch between Astro and @tailwindcss/vite
71 tailwindcss(),
72 kumoColorsPlugin(),
73 kumoRegistryPlugin(),
74 // In dev mode, resolve @cloudflare/kumo imports to raw source files
75 // for instant HMR. In production builds, the normal package.json
76 // exports (dist/) are used — preserving the real consumer experience.
77 ...(isDev ? [kumoHmrPlugin()] : []),
78 ],
79
80 define: {
81 __KUMO_VERSION__: JSON.stringify(buildInfo.kumoVersion),
82 __DOCS_VERSION__: JSON.stringify(buildInfo.docsVersion),
83 __BUILD_VERSION__: JSON.stringify(buildInfo.kumoVersion), // Alias for backwards compatibility
84 __BUILD_COMMIT__: JSON.stringify(buildInfo.commitHash),
85 __BUILD_COMMIT_DATE__: JSON.stringify(buildInfo.commitDate),
86 __BUILD_BRANCH__: JSON.stringify(buildInfo.branch),
87 __BUILD_DATE__: JSON.stringify(buildInfo.buildDate),
88 },
89 },
90});
91