refactor(ui): extract reusable component package
This commit is contained in:
parent
87261b5a3f
commit
2664804e91
86 changed files with 102 additions and 85 deletions
74
packages/ui/src/content-boundary.test.ts
Normal file
74
packages/ui/src/content-boundary.test.ts
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
const root = process.cwd();
|
||||
const uiSourceRoot = existsSync(join(root, "packages/ui/src"))
|
||||
? join(root, "packages/ui/src")
|
||||
: join(root, "src");
|
||||
|
||||
const forbiddenTerms = [
|
||||
"dimensionlab",
|
||||
"dimension lab",
|
||||
"vaultwarden",
|
||||
"forgejo",
|
||||
"grafana",
|
||||
"uptime kuma",
|
||||
"prometheus",
|
||||
"backrest",
|
||||
"open webui",
|
||||
"comfyui",
|
||||
"adminer",
|
||||
"cockpit",
|
||||
"ollama",
|
||||
];
|
||||
|
||||
describe("UI package content boundary", () => {
|
||||
test("contains the reusable dashboard component inventory", () => {
|
||||
expect(existsSync(join(uiSourceRoot, "index.ts"))).toBe(true);
|
||||
expect(existsSync(join(uiSourceRoot, "components/DashboardFrame.tsx"))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(existsSync(join(uiSourceRoot, "components/ThemeToggle.tsx"))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(existsSync(join(uiSourceRoot, "styles.css"))).toBe(true);
|
||||
});
|
||||
|
||||
test("keeps environment-specific content out of reusable UI source", () => {
|
||||
const source = readUiSource(uiSourceRoot).toLowerCase();
|
||||
|
||||
expect(forbiddenTerms.filter((term) => source.includes(term))).toEqual([]);
|
||||
});
|
||||
|
||||
test("does not import website runtime modules", () => {
|
||||
const source = readUiSource(uiSourceRoot);
|
||||
|
||||
expect(source).not.toMatch(
|
||||
/from ["'](?:apps\/web|\$lib\/server|\$lib\/model)/,
|
||||
);
|
||||
expect(source).not.toContain("../web/");
|
||||
});
|
||||
|
||||
test("keeps icon rendering driven by icon identifiers", () => {
|
||||
const source = readUiSource(uiSourceRoot);
|
||||
|
||||
expect(source).not.toContain("@iconify-json/");
|
||||
expect(source).not.toContain("/icons/");
|
||||
});
|
||||
});
|
||||
|
||||
function readUiSource(path: string): string {
|
||||
if (!existsSync(path)) return "";
|
||||
|
||||
const stats = statSync(path);
|
||||
if (stats.isFile()) {
|
||||
if (path.endsWith(".test.ts") || path.endsWith(".test.tsx")) return "";
|
||||
if (!/\.(tsx|ts|css)$/.test(path)) return "";
|
||||
return readFileSync(path, "utf8");
|
||||
}
|
||||
|
||||
return readdirSync(path)
|
||||
.map((entry) => readUiSource(join(path, entry)))
|
||||
.join("\n");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue