yue2-studio / scripts /verify-build.mjs
RalphThings's picture
Upload folder using huggingface_hub
bc11697 verified
Raw History Blame Contribute Delete
1.59 kB
#!/usr/bin/env node
/**
* Asserts the build produced a real stylesheet.
*
* An unstyled page is a miserable thing to debug from a container log, because
* every process reports success. Failing the image build instead turns it into
* one obvious line.
*/
import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
const root = ".next/static";
function walk(dir) {
const out = [];
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const path = join(dir, entry.name);
if (entry.isDirectory()) out.push(...walk(path));
else out.push(path);
}
return out;
}
let files;
try {
files = walk(root);
} catch {
console.error(`verify-build: ${root} does not exist. The build did not emit assets.`);
process.exit(1);
}
const sheets = files.filter((f) => f.endsWith(".css"));
if (sheets.length === 0) {
console.error("verify-build: no stylesheet in the build output.");
process.exit(1);
}
const biggest = sheets
.map((f) => ({ f, size: statSync(f).size }))
.sort((a, b) => b.size - a.size)[0];
if (biggest.size < 2000) {
console.error(`verify-build: ${biggest.f} is only ${biggest.size} bytes, so Tailwind emitted nothing.`);
process.exit(1);
}
const css = readFileSync(biggest.f, "utf8");
for (const token of ["--color-citron", "--color-void"]) {
if (!css.includes(token)) {
console.error(`verify-build: ${token} missing from ${biggest.f}. The theme did not compile.`);
process.exit(1);
}
}
console.log(`verify-build: ok, ${biggest.f} is ${biggest.size} bytes with the theme tokens.`);