48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
import { copyFile, readFile, writeFile, readdir } from "node:fs/promises";
|
|
import { fileURLToPath } from "node:url";
|
|
import { compile } from "@tailwindcss/node";
|
|
import ts from "typescript";
|
|
|
|
await copyFile(
|
|
fileURLToPath(import.meta.resolve("@takumi-rs/wasm/takumi_wasm_bg.wasm")),
|
|
"public/takumi.wasm",
|
|
);
|
|
const globals = await readFile("app/globals.css", "utf8");
|
|
const theme = globals.slice(
|
|
globals.indexOf("@theme inline {"),
|
|
globals.indexOf("\n}", globals.indexOf("@theme inline {")) + 2,
|
|
);
|
|
const colors = globals.slice(
|
|
globals.indexOf(":root,\n.dark"),
|
|
globals.indexOf("\n}", globals.indexOf(":root,\n.dark")) + 2,
|
|
);
|
|
const candidates = new Set();
|
|
const files = (await readdir("lib/image-export/templates"))
|
|
.filter((name) => name.endsWith(".tsx"))
|
|
.map((name) => `lib/image-export/templates/${name}`);
|
|
files.push(
|
|
"lib/catalog/rarity.ts",
|
|
"lib/catalog/element.ts",
|
|
"lib/guides/stats.ts",
|
|
);
|
|
for (const path of files) {
|
|
const source = ts.createSourceFile(
|
|
path,
|
|
await readFile(path, "utf8"),
|
|
ts.ScriptTarget.Latest,
|
|
true,
|
|
path.endsWith("tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
|
|
);
|
|
function visit(node) {
|
|
if (ts.isStringLiteralLike(node))
|
|
node.text.split(/\s+/).forEach((token) => candidates.add(token));
|
|
ts.forEachChild(node, visit);
|
|
}
|
|
visit(source);
|
|
}
|
|
const compiler = await compile(
|
|
`@import "tailwindcss";\n${theme}\n${colors}\n:root { --font-anuphan: Anuphan; --font-geist-mono: Anuphan; }`,
|
|
{ base: process.cwd(), onDependency() {} },
|
|
);
|
|
await writeFile("public/takumi.css", compiler.build([...candidates]));
|