import { access, readFile, readdir } from "node:fs/promises"; import { join } from "node:path"; const root = process.cwd(); const generatedPath = join(root, "dist", "theme-github-dev.css"); const generatedDarkPath = join(root, "dist", "theme-github-dev-dark.css"); const themeSourceDir = join(root, "themes", "github-light"); const darkThemeSourceDir = join(root, "themes", "github-dark"); const tokenSourceDir = join(root, "styles", "tokens"); const packageJson = JSON.parse(await readFile(join(root, "package.json"), "utf8")) as { version?: string }; const generated = await readFile(generatedPath, "utf8"); const generatedDark = await readFile(generatedDarkPath, "utf8"); const requiredSnippets = [ "--theme-display-name: GitHub Light", '--theme-version: "1.26.1', "--color-primary: #0969da", "--github-bgColor-accent-emphasis: #0969da", "--color-syntax-keyword: #cf222e", "--color-syntax-string: #0a3069", ".ui.primary.button", ".repository.file.list #repo-files-table", ".page-content.user.signin", ".gitea-github-theme-templates", ]; const requiredDarkSnippets = [ '--theme-display-name: "GitHub Dark"', '--theme-color-scheme: "dark"', "--is-dark-theme: true", "--color-body: #0d1117", "--color-text: #e6edf3", "--color-diff-added-row-bg: #033a16", "--color-diff-removed-row-bg: #490202", "--github-bgColor-accent-emphasis: #1f6feb", "--color-syntax-keyword: #ff7b72", "--color-syntax-string: #a5d6ff", ".ui.primary.button", ]; if (packageJson.version !== "1.26.1") { throw new Error(`project version must be 1.26.1, got ${packageJson.version}`); } await access(join(root, "themes", "index.ts")); await access(join(themeSourceDir, "index.ts")); await access(join(darkThemeSourceDir, "index.ts")); const tokenFiles = await readdir(tokenSourceDir); const themeFiles = await readdir(themeSourceDir); const darkThemeFiles = await readdir(darkThemeSourceDir); const allowedTokenFiles = new Set(["derived.ts", "index.ts", "render-theme.ts", "required.ts"]); const unexpectedTokenFiles = tokenFiles.filter((file) => !allowedTokenFiles.has(file)); if (unexpectedTokenFiles.length > 0) { throw new Error( `styles/tokens must only contain theme rendering helpers, got: ${unexpectedTokenFiles.join(", ")}`, ); } for (const file of [ "theme-meta.ts", "core.ts", "console.ts", "named-colors.ts", "ansi-colors.ts", "diff-colors.ts", "semantic-colors.ts", "github-colors.ts", "syntax-colors.ts", "target-colors.ts", ]) { if (!themeFiles.includes(file)) { throw new Error(`themes/github-light is missing theme source file: ${file}`); } } for (const file of [ "theme-meta.ts", "core.ts", "diff-colors.ts", "github-colors.ts", "syntax-colors.ts", "target-colors.ts", "index.ts", ]) { if (!darkThemeFiles.includes(file)) { throw new Error(`themes/github-dark is missing theme source file: ${file}`); } } for (const snippet of requiredSnippets) { if (!generated.includes(snippet)) { throw new Error(`generated theme is missing required snippet: ${snippet}`); } } for (const snippet of requiredDarkSnippets) { if (!generatedDark.includes(snippet)) { throw new Error(`generated dark theme is missing snippet: ${snippet}`); } } console.log("generated theme verified");