35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { readdirSync, readFileSync } from "node:fs";
|
|
import { join, relative } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
const ROOTS = ["src/app/admin", "src/components/admin"];
|
|
const GRAPHICAL_ALLOWLIST = [
|
|
"src/app/admin/favicon/favicon-generator.tsx",
|
|
"src/app/admin/import/clone/import-clone-client.tsx",
|
|
"src/app/admin/import/furni/import-furni-client.tsx",
|
|
"src/components/admin/catalog/items-shop-preview.tsx",
|
|
];
|
|
|
|
function sourceFiles(directory: string): string[] {
|
|
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
const path = join(directory, entry.name);
|
|
return entry.isDirectory() ? sourceFiles(path) : /\.(?:ts|tsx)$/.test(entry.name) ? [path] : [];
|
|
});
|
|
}
|
|
|
|
describe("admin theme source audit", () => {
|
|
it("keeps ordinary admin text theme-aware", () => {
|
|
const violations: string[] = [];
|
|
for (const root of ROOTS) {
|
|
for (const file of sourceFiles(root)) {
|
|
const normalized = relative(process.cwd(), file).replaceAll("\\", "/");
|
|
if (GRAPHICAL_ALLOWLIST.includes(normalized)) continue;
|
|
const source = readFileSync(file, "utf8");
|
|
const risky = source.match(/(?:text-(?:gray|slate)-(?:400|500|600|700|800|900)|text-white(?:\/\d+)?|\)\]0)/g);
|
|
if (risky) violations.push(`${normalized}: ${[...new Set(risky)].join(", ")}`);
|
|
}
|
|
}
|
|
expect(violations).toEqual([]);
|
|
});
|
|
});
|