- Move preview session and IPC wiring into the new preview module - Tighten IPC validation with schema-based handlers - Update preview asset paths and tests for the browser preview port
41 lines
1.6 KiB
JavaScript
41 lines
1.6 KiB
JavaScript
import { readFile, writeFile } from "node:fs/promises";
|
|
import { createRequire } from "node:module";
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import { compile } from "tailwindcss";
|
|
|
|
const directory = dirname(fileURLToPath(import.meta.url));
|
|
const appRoot = join(directory, "..");
|
|
const sourcePath = join(appRoot, "src", "preview", "Annotation.css");
|
|
const preloadPath = join(appRoot, "src", "preview", "PickPreload.ts");
|
|
const outputPath = join(appRoot, "src", "preview", "AnnotationStyles.generated.ts");
|
|
const require = createRequire(import.meta.url);
|
|
const tailwindRoot = dirname(require.resolve("tailwindcss/package.json"));
|
|
|
|
const [annotationSource, preloadSource, themeSource, preflightSource] = await Promise.all([
|
|
readFile(sourcePath, "utf8"),
|
|
readFile(preloadPath, "utf8"),
|
|
readFile(join(tailwindRoot, "theme.css"), "utf8"),
|
|
readFile(join(tailwindRoot, "preflight.css"), "utf8"),
|
|
]);
|
|
|
|
const candidates = new Set(
|
|
Array.from(preloadSource.matchAll(/!?-?[A-Za-z0-9_:@/.[\]()%,-]+/g), (match) => match[0]),
|
|
);
|
|
const compilerInput = [
|
|
themeSource,
|
|
preflightSource,
|
|
annotationSource.replace('@import "tailwindcss";', "@tailwind utilities;"),
|
|
].join("\n");
|
|
const compiler = await compile(compilerInput, { base: appRoot });
|
|
const css = compiler.build([...candidates]);
|
|
const encodedCss = `'${css
|
|
.replaceAll("\\", "\\\\")
|
|
.replaceAll("'", "\\'")
|
|
.replaceAll("\r", "\\r")
|
|
.replaceAll("\n", "\\n")}'`;
|
|
const moduleSource = `// Generated by scripts/build-preview-annotation-css.mjs. Do not edit.\nexport const previewAnnotationStyles =\n ${encodedCss};\n`;
|
|
|
|
await writeFile(outputPath, moduleSource);
|