Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

2.5 KB
Raw Blame
import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";

const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const catalogPath = resolve(root, "src/data/shaders.tsx");
const outputPath = resolve(root, "src/index.ts");
const componentsPath = resolve(root, "src/package-components");
const catalog = await readFile(catalogPath, "utf8");

const lazyPattern = /import\("(\.\.\/shaders\/[^"]+)"\)\.then\(\(module\) => \(\{ default: module\.([A-Za-z_$][\w$]*) \}\)\)/g;
const eagerPattern = /import \{ ([A-Za-z_$][\w$]*) as CommunityRenderer\d+ \} from "(\.\.\/shaders\/[^"]+)"/g;
const exports = [
  ...[...catalog.matchAll(lazyPattern)].map((match) => ({ path: match[1].replace("../", "./"), name: match[2] })),
  ...[...catalog.matchAll(eagerPattern)].map((match) => ({ path: match[2].replace("../", "./"), name: match[1] })),
];

const compatibilityExports = [
  { name: "SkeuomorphicToggle", path: "./shaders/neuform-isolated/NeuformBatchEffects" },
];

for (const compatibilityExport of compatibilityExports) {
  const current = exports.find((item) => item.name === compatibilityExport.name);
  if (current && current.path !== compatibilityExport.path) {
    throw new Error(`Compatibility export ${compatibilityExport.name} moved from ${compatibilityExport.path} to ${current.path}.`);
  }
  if (!current) exports.push(compatibilityExport);
}

if (!exports.length) throw new Error("No Community renderer exports were found in src/data/shaders.tsx");

const names = new Set();
for (const item of exports) {
  if (names.has(item.name)) throw new Error(`Duplicate Community export: ${item.name}`);
  names.add(item.name);
}

await mkdir(componentsPath, { recursive: true });
for (const name of await readdir(componentsPath)) {
  if (name.endsWith(".ts")) await rm(resolve(componentsPath, name));
}
for (const item of exports) {
  await writeFile(
    resolve(componentsPath, `${item.name}.ts`),
    `// Generated by scripts/generate-library-entry.mjs. Do not edit by hand.\nexport { ${item.name} } from "../${item.path.slice(2)}";\n`,
  );
}

const lines = [
  "// Generated by scripts/generate-library-entry.mjs. Do not edit by hand.",
  'import "./shaders/community.css";',
  "",
  ...exports
    .sort((left, right) => left.name.localeCompare(right.name))
    .map((item) => `export { ${item.name} } from "./package-components/${item.name}";`),
  "",
];

await writeFile(outputPath, lines.join("\n"));
console.log(`Generated ${exports.length} Community component entry points.`);