Files
shadcn-ui/apps/v4/scripts/build-examples.ts
shadcn 47c47eaed2 feat: add docs for base-ui components (#9304)
* feat: add base and radix docs

* feat: transform code for display

* fix

* fix

* fix

* fix

* fix

* chore: remove claude files

* fix

* fix

* fix

* chore: run format:write

* fix

* feat: add more examples

* fix

* feat: add aspect-ratio

* feat: add avatar

* feat: add badge

* feat: add breadcrumb

* fix

* feat: add button

* fix

* fix

* fix

* feat: add calendar and card

* feat: add carousel

* fix: chart

* feat: add checkbox

* feat: add collapsible

* feat: add combobox

* feat: add command

* feat: add context menu

* feat: add data-table dialog and drawer

* feat: dropdown-menu

* feat: add date-picker

* feat: add empty

* feat: add field and hover-card

* fix: input

* feat: add input

* feat: add input-group

* feat: add input-otp

* feat: add item

* feat: add kbd and label

* feat: add menubar

* feat: add native-select

* feat: add more components

* feat: more components

* feat: more components

* feat: add skeleton, slider and sonner

* feat: add spinner and switch

* feat: add more components

* fix: tabs

* fix: tabs

* feat: add docs for sidebar

* fix

* fix

* fi

* docs: update

* fix: create page

* fix

* fix

* chore: add changelog

* fix
2026-01-20 19:31:38 +04:00

73 lines
1.9 KiB
TypeScript

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...")
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 base of BASES) {
const baseDir = path.join(examplesDir, base.name)
try {
await fs.access(baseDir)
} catch {
console.log(` Skipping ${base.name} - directory does not exist`)
continue
}
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}`)
index += `
"${base.name}": {`
for (const file of files) {
const name = file.replace(/\.tsx$/, "")
const filePath = `examples/${base.name}/${file}`
index += `
"${name}": {
name: "${name}",
filePath: "${filePath}",
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")
rimraf.sync(indexPath)
await fs.writeFile(indexPath, index)
console.log(`\n✅ Generated examples/__index__.tsx`)
}
buildExamplesIndex().catch(console.error)