|
| 1 | +import { readFile, readdir, stat } from "node:fs/promises"; |
| 2 | +import { existsSync } from "node:fs"; |
| 3 | +import { dirname, resolve } from "node:path"; |
| 4 | +import { fileURLToPath } from "node:url"; |
| 5 | + |
| 6 | +const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); |
| 7 | +const srcDir = resolve(repoRoot, "src"); |
| 8 | +const indexPath = resolve(srcDir, "index.html"); |
| 9 | +const requiredSections = [ |
| 10 | + "hero", |
| 11 | + "how-it-works", |
| 12 | + "packages", |
| 13 | + "agentcore", |
| 14 | + "quickstart", |
| 15 | + "roadmap" |
| 16 | +]; |
| 17 | + |
| 18 | +const index = await readFile(indexPath, "utf8"); |
| 19 | +for (const section of requiredSections) { |
| 20 | + if (!index.includes(`id="${section}"`)) { |
| 21 | + throw new Error(`Missing required section #${section}`); |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +for (const placeholder of ["TODO", "lorem", "ipsum", "undefined"]) { |
| 26 | + if (index.toLowerCase().includes(placeholder.toLowerCase())) { |
| 27 | + throw new Error(`Found placeholder text: ${placeholder}`); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +for (const match of index.matchAll(/(?:href|src)="([^"]+)"/g)) { |
| 32 | + const target = match[1]; |
| 33 | + if (target.startsWith("http") || target.startsWith("#") || target.startsWith("mailto:")) continue; |
| 34 | + const localPath = resolve(dirname(indexPath), target); |
| 35 | + if (!existsSync(localPath)) { |
| 36 | + throw new Error(`Broken local asset reference: ${target}`); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +const css = await readFile(resolve(srcDir, "styles.css"), "utf8"); |
| 41 | +if (!css.includes("@media") || !css.includes(":root")) { |
| 42 | + throw new Error("CSS must include responsive rules and root design tokens."); |
| 43 | +} |
| 44 | + |
| 45 | +const files = []; |
| 46 | +async function walk(dir) { |
| 47 | + for (const entry of await readdir(dir)) { |
| 48 | + const path = resolve(dir, entry); |
| 49 | + const metadata = await stat(path); |
| 50 | + if (metadata.isDirectory()) await walk(path); |
| 51 | + else files.push(path); |
| 52 | + } |
| 53 | +} |
| 54 | +await walk(srcDir); |
| 55 | + |
| 56 | +console.log(`Validated AgentDispatch website (${files.length} source files).`); |
0 commit comments