77 lines
3.5 KiB
JavaScript
77 lines
3.5 KiB
JavaScript
import { readFile } from "node:fs/promises";
|
|
import { resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const root = fileURLToPath(new URL("..", import.meta.url));
|
|
const cssFiles = [
|
|
"frost.css",
|
|
"core.css",
|
|
"utility-layer.css",
|
|
"component-layer.css",
|
|
"tokens.css",
|
|
"base.css",
|
|
"accessibility.css",
|
|
"layout.css",
|
|
"controls.css",
|
|
"components.css",
|
|
"utilities.css",
|
|
];
|
|
|
|
const errors = [];
|
|
|
|
for (const file of cssFiles) {
|
|
const source = await readFile(resolve(root, file), "utf8");
|
|
const opens = (source.match(/\{/g) ?? []).length;
|
|
const closes = (source.match(/\}/g) ?? []).length;
|
|
if (opens !== closes) errors.push(`${file}: unbalanced braces`);
|
|
if (/transition\s*:\s*all\b/.test(source)) errors.push(`${file}: transition: all is not allowed`);
|
|
if (/(?:^|[;{])\s*--(?!frost-)[a-z0-9-]+\s*:/.test(source)) errors.push(`${file}: found an unprefixed public custom property`);
|
|
}
|
|
|
|
const entry = await readFile(resolve(root, "frost.css"), "utf8");
|
|
for (const match of entry.matchAll(/@import\s+url\("([^"]+)"\)/g)) {
|
|
try { await readFile(resolve(root, match[1]), "utf8"); }
|
|
catch { errors.push(`frost.css: missing import ${match[1]}`); }
|
|
}
|
|
|
|
const layerSources = {
|
|
"core.css": ["tokens.css", "base.css", "accessibility.css"],
|
|
"utility-layer.css": ["core.css", "layout.css", "utilities.css"],
|
|
"component-layer.css": ["core.css", "layout.css", "controls.css", "components.css"],
|
|
};
|
|
for (const [file, requiredImports] of Object.entries(layerSources)) {
|
|
const source = await readFile(resolve(root, file), "utf8");
|
|
for (const requiredImport of requiredImports) {
|
|
if (!source.includes(`./${requiredImport}`)) errors.push(`${file}: missing layer import ${requiredImport}`);
|
|
}
|
|
}
|
|
const utilityLayerSource = await readFile(resolve(root, "utility-layer.css"), "utf8");
|
|
const componentLayerSource = await readFile(resolve(root, "component-layer.css"), "utf8");
|
|
if (utilityLayerSource.includes("./controls.css") || utilityLayerSource.includes("./components.css")) errors.push("utility-layer.css: component layer leaked into utility entry point");
|
|
if (componentLayerSource.includes("./utilities.css")) errors.push("component-layer.css: utility layer leaked into component entry point");
|
|
|
|
const utilitySource = await readFile(resolve(root, "utilities.css"), "utf8");
|
|
for (const utility of ["frost-flex", "frost-grid", "frost-gap-4", "frost-p-4", "frost-md\\:grid-cols-2", "frost-hover\\:bg-soft"]) {
|
|
if (!utilitySource.includes(`.${utility}`)) errors.push(`utilities.css: missing public utility ${utility}`);
|
|
}
|
|
|
|
const componentsSource = await readFile(resolve(root, "components.css"), "utf8");
|
|
for (const component of ["frost-navbar", "frost-breadcrumbs", "frost-tabs", "frost-accordion", "frost-pagination", "frost-table", "frost-spinner"]) {
|
|
if (!componentsSource.includes(`.${component}`)) errors.push(`components.css: missing public component ${component}`);
|
|
}
|
|
|
|
const packageJson = JSON.parse(await readFile(resolve(root, "package.json"), "utf8"));
|
|
for (const exportPath of ["./utilities", "./components", "./tokens"]) {
|
|
if (!packageJson.exports[exportPath]) errors.push(`package.json: missing export ${exportPath}`);
|
|
}
|
|
for (const exportPath of ["./core", "./utility-layer", "./component-layer"]) {
|
|
if (!packageJson.exports[exportPath]) errors.push(`package.json: missing layer export ${exportPath}`);
|
|
}
|
|
|
|
if (errors.length) {
|
|
console.error(errors.join("\n"));
|
|
process.exitCode = 1;
|
|
} else {
|
|
console.log(`Checked ${cssFiles.length} CSS files; imports, braces, transitions, and public token prefixes look valid.`);
|
|
}
|