Home / File/ build-examples.ts — ui Source File

build-examples.ts — ui Source File

Architecture documentation for build-examples.ts, a typescript file in the ui codebase. 4 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  3bb184bf_3ef5_bddd_de88_1acfdc78bdf5["build-examples.ts"]
  eac8f98f_e40a_7fe8_f505_372c83d20c7a["fs"]
  3bb184bf_3ef5_bddd_de88_1acfdc78bdf5 --> eac8f98f_e40a_7fe8_f505_372c83d20c7a
  d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5["path"]
  3bb184bf_3ef5_bddd_de88_1acfdc78bdf5 --> d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5
  0d49b6e0_4727_fe64_ddff_5c8125aefe3e["rimraf"]
  3bb184bf_3ef5_bddd_de88_1acfdc78bdf5 --> 0d49b6e0_4727_fe64_ddff_5c8125aefe3e
  c544a3e1_3972_d827_a6cc_0c6a194dbe9e["bases"]
  3bb184bf_3ef5_bddd_de88_1acfdc78bdf5 --> c544a3e1_3972_d827_a6cc_0c6a194dbe9e
  style 3bb184bf_3ef5_bddd_de88_1acfdc78bdf5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { promises as fs } from "fs"
import path from "path"
import { rimraf } from "rimraf"

import { BASES } from "@/registry/bases"

async function buildExamplesIndex() {
  const cwd = process.cwd()
  const examplesDir = path.join(cwd, "examples")

  console.log("📋 Generating examples/__index__.tsx...")

  // Process all bases in parallel.
  const baseResults = await Promise.all(
    Array.from(BASES).map(async (base) => {
      const baseDir = path.join(examplesDir, base.name)

      try {
        await fs.access(baseDir)
      } catch {
        console.log(`   Skipping ${base.name} - directory does not exist`)
        return null
      }

      const allEntries = await fs.readdir(baseDir, { withFileTypes: true })
      const files = allEntries
        .filter((entry) => entry.isFile() && entry.name.endsWith(".tsx"))
        .map((entry) => entry.name)
        .sort()

      console.log(`   Found ${files.length} demos for ${base.name}`)

      return { base, files }
    })
  )

  let index = `// @ts-nocheck
// This file is autogenerated by scripts/build-examples-index.mts
// Do not edit this file directly.
import * as React from "react"

export const ExamplesIndex: Record<string, Record<string, any>> = {`

  for (const result of baseResults) {
    if (!result) continue

    const { base, files } = result

    index += `
  "${base.name}": {`

    for (const file of files) {
      const name = file.replace(/\.tsx$/, "")

      index += `
    "${name}": {
      name: "${name}",
      filePath: "examples/${base.name}/${file}",
      component: React.lazy(async () => {
        const mod = await import("./${base.name}/${name}")
        const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') || "${name}"
        return { default: mod.default || mod[exportName] }
      }),
    },`
    }

    index += `
  },`
  }

  index += `
}
`

  const indexPath = path.join(examplesDir, "__index__.tsx")
  await rimraf(indexPath)
  await fs.writeFile(indexPath, index)

  console.log(`\n✅ Generated examples/__index__.tsx`)
}

buildExamplesIndex().catch(console.error)

Subdomains

Dependencies

  • bases
  • fs
  • path
  • rimraf

Frequently Asked Questions

What does build-examples.ts do?
build-examples.ts is a source file in the ui codebase, written in typescript. It belongs to the DocumentationAtlas domain, SearchAPI subdomain.
What functions are defined in build-examples.ts?
build-examples.ts defines 1 function(s): buildExamplesIndex.
What does build-examples.ts depend on?
build-examples.ts imports 4 module(s): bases, fs, path, rimraf.
Where is build-examples.ts in the architecture?
build-examples.ts is located at apps/v4/scripts/build-examples.ts (domain: DocumentationAtlas, subdomain: SearchAPI, directory: apps/v4/scripts).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free