Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

1.8 KB
Raw Blame
// Emits src/lib/doc-modules.generated.ts: one lazy `import()` per MDX page, so
// the bundler compiles a page only when it is requested. fumadocs-mdx's eager
// index imports every page into one module graph, which made the dev server
// compile the whole site (generated reference included) on the first request.
// Page metadata still comes from the fumadocs-mdx index (async mode: frontmatter
// only); the body comes from here, compiled by the normal MDX loader.
import { readdirSync, statSync, writeFileSync, readFileSync, existsSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const docs = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const content = path.join(docs, 'content/docs');
const out = path.join(docs, 'src/lib/doc-modules.generated.ts');

function walk(dir) {
  return readdirSync(dir).flatMap((name) => {
    const full = path.join(dir, name);
    return statSync(full).isDirectory() ? walk(full) : full.endsWith('.mdx') ? [full] : [];
  });
}

export function generateDocModules() {
  const files = walk(content)
    .map((f) => path.relative(content, f).split(path.sep).join('/'))
    .sort();
  const body = [
    '// @ts-nocheck -- MDX modules are typed by fumadocs-mdx at runtime',
    '// Generated by scripts/gen-doc-modules.mjs. Do not edit.',
    'export const docModules: Record<string, () => Promise<any>> = {',
    ...files.map(
      (f) => `  ${JSON.stringify(f)}: () => import(${JSON.stringify(`../../content/docs/${f}?collection=docs`)}),`
    ),
    '};',
    '',
  ].join('\n');
  if (!existsSync(out) || readFileSync(out, 'utf8') !== body) writeFileSync(out, body);
  return files.length;
}

if (process.argv[1] === fileURLToPath(import.meta.url)) {
  console.log(`doc-modules: ${generateDocModules()} pages`);
}