mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
sdk/raea/library/components holds 475 pieces from remocn, 79 from the React Video Editor templates and 55 from snapcn, ported to raea's composition API and sorted by what they're for (text, numbers, transitions, screens, HUDs and more), not by who made them. catalog.json lists each piece's category, type, what it does, its files, the shared helpers it needs, its fonts and npm packages and its source; CREDITS.md holds the licences and every file's first line names its source. - `raea make component list` ends with the library's categories; `list WORDS` searches by category, category/type or words (catalog.ts). `add NAME` copies the piece into components/CATEGORY/NAME/ with its helpers under components/_lib/, and installs its npm packages through the engine. - The native host reads the library beside the binary (share/raea, which tools/release.sh already packs from sdk/raea/library), in RAEA_HOME, or in the tree a built raea runs from. - tools/effects-catalog.sh writes the cut-down catalogue raea cloud's dashboard imports (Libraries › Effects). - tools/size.sh leaves the library out: it's other people's code, kept as they wrote it but for imports. - conformance/catalog.test.ts: every listed file exists, imports stay inside what a piece copies, none imports another video framework, and search finds by use.
49 lines
2.8 KiB
TypeScript
49 lines
2.8 KiB
TypeScript
// The component library (sdk/raea/library/components, catalog.ts): every listed file is there, every relative import
|
|
// in it lands on a file of the library, nothing imports another video framework, and the search finds by use.
|
|
import { describe, expect, test } from "bun:test";
|
|
import { existsSync, readFileSync } from "node:fs";
|
|
import { dirname, join, normalize } from "node:path";
|
|
import { listed, type Item } from "../src/catalog";
|
|
|
|
const lib = join(import.meta.dir, "../../../sdk/raea/library/components");
|
|
const cat = JSON.parse(readFileSync(join(lib, "catalog.json"), "utf8")) as { sources: Record<string, { licence: string }>; items: Item[] };
|
|
|
|
describe("the component library", () => {
|
|
test("each item's files and the shared files it needs are there, and each item names a known source", () => {
|
|
const missing = cat.items.flatMap((i) => [...i.files, ...i.needs].filter((f) => !existsSync(join(lib, f))).map((f) => `${i.name}: ${f}`));
|
|
expect(missing).toEqual([]);
|
|
expect(cat.items.filter((i) => !cat.sources[i.from]?.licence).map((i) => i.name)).toEqual([]);
|
|
});
|
|
|
|
test("an item's relative imports land inside what it copies, and none is another framework's", () => {
|
|
const bad: string[] = [];
|
|
for (const i of cat.items) {
|
|
const copied = new Set([...i.files, ...i.needs]);
|
|
for (const f of i.files.concat(i.needs).filter((f) => /\.tsx?$/.test(f))) {
|
|
const src = readFileSync(join(lib, f), "utf8");
|
|
if (/from\s+["']@?remotion/.test(src)) bad.push(`${f}: imports remotion`);
|
|
// a package it imports is one `add` installs (its packages), or raea's own, or React
|
|
for (const [, pkg] of src.matchAll(/from\s+"([^".][^"]*)"/g)) if (!/^(raea|raea\/[\w/]+|react|react-dom)$/.test(pkg) && !(i.packages ?? []).includes(pkg)) bad.push(`${f}: imports ${pkg}, not in its packages`);
|
|
for (const [, spec] of src.matchAll(/(?:from\s+|import\s*\(?)"(\.[^"<]*)"/g)) {
|
|
const base = normalize(join(dirname(f), spec));
|
|
if (![base, `${base}.ts`, `${base}.tsx`, `${base}/index.ts`, `${base}/index.tsx`].some((c) => copied.has(c))) bad.push(`${i.name}: ${f} -> ${spec}`);
|
|
}
|
|
}
|
|
}
|
|
expect(bad).toEqual([]);
|
|
});
|
|
|
|
test("names are unique, so `add NAME` means one thing", () => {
|
|
const names = cat.items.map((i) => i.name);
|
|
expect(names.filter((n, k) => names.indexOf(n) !== k)).toEqual([]);
|
|
});
|
|
|
|
test("search: a category, a category/type, and words in what it does", () => {
|
|
expect(listed(cat.items, [])).toContain("text");
|
|
expect(listed(cat.items, ["text/reveal"])).toContain("text/soft-blur-in");
|
|
expect(listed(cat.items, ["text/reveal"])).not.toContain("numbers/");
|
|
expect(listed(cat.items, ["count", "up"]).split("\n")[0]).toContain("count");
|
|
expect(listed(cat.items, ["zzqx"])).toContain("no component in the library");
|
|
});
|
|
});
|