Something went wrong. Try again.
a tiny pet with a GPT-2 brain, living in your browser
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// The host supplies a mount point/config. Preact owns the interactive markup.import { readFileSync, readdirSync } from "node:fs";import { fileURLToPath } from "node:url";const root = fileURLToPath(new URL("..", import.meta.url));const read = (p) => readFileSync(root + p, "utf8");const files = readdirSync(root + "web", { recursive: true }).filter((f) => /\.tsx?$/.test(f));const app = files.map((f) => read("web/" + f)).join("\n");const components = files .filter((f) => f.startsWith("components/")) .map((f) => read("web/" + f)) .join("\n");const page = read("site/index.html"), doc = read("docs/host-page.md");const required = [...app.matchAll(/getElementById\("([\w-]+)"\)/g)].map((m) => m[1]);const ids = new Set([...components.matchAll(/\bid="([\w-]+)"/g)].map((m) => m[1]));// These ids are composed from closed lists in App and Device.for (const id of ["chat", "diary", "shelf", "care", "debug"]) { ids.add("tab-" + id); ids.add("panel-" + id);}for (const id of ["feed", "play", "bath", "pat", "clean", "meds", "lights"]) ids.add("act-" + id);ids.add("pad-left");ids.add("pad-right");const keys = new Set([...app.matchAll(/CFG\.(\w+)/g)].map((m) => m[1]));let bad = 0;const check = (ok, message) => { if (!ok) { console.error("FAIL", message); bad++; }};for (const id of required) { check(page.includes(`id="${id}"`), `host lacks ${id}`); check(doc.includes("`" + id + "`"), `docs omit host id ${id}`);}for (const id of ids) check(doc.includes("`" + id + "`"), `docs omit component id ${id}`);for (const id of [...app.matchAll(/#[a-z][\w-]+/g)].map((m) => m[0].slice(1))) { if (/^(?:pet|pad|panel|tab|chat|brain|debug)-/.test(id)) check(ids.has(id) || required.includes(id), `selector ${id} has no component or host element`);}for (const key of keys) check(doc.includes("`" + key + "`"), `docs omit config key ${key}`);check(page.includes('src="@APP@/main.js"'), "host must load the bundled entry");check(!page.includes('id="pet-lcd"'), "interactive markup must be owned by Preact");check( !/replaceChildren|innerHTML|document\.querySelector/.test(app), "UI rendering must use components and refs",);console.log( `${required.length} host ids, ${ids.size} component ids, ${keys.size} config keys, ${bad} problems`,);process.exitCode = bad ? 1 : 0;