Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

1.7 KB
Raw Blame
// typecheck

import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import { registrySchema, type RegistryItem } from 'shadcn/schema'

import { resolveRegistryItem } from '../lib/registry-resolution'
import { registry } from '../registry/index'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const registryPath = path.join(__dirname, '..', 'public', 'r', 'registry.json')

registrySchema.parse(registry)
const items = new Map<string, RegistryItem>()
for (const item of registry.items) {
  if (items.has(item.name)) throw new Error(`Duplicate registry item "${item.name}"`)
  items.set(item.name, item)
}
for (const name of items.keys()) {
  resolveRegistryItem((itemName) => items.get(itemName), name)
}

const cleanedRegistry = {
  $schema: 'https://ui.shadcn.com/schema/registry.json',
  ...registry,
  items: registry.items.filter((item) => item.type !== 'registry:example'),
}

fs.writeFileSync(registryPath, JSON.stringify(cleanedRegistry, null, 2))

// Create a registry index file for use by ComponentPreview in the app.
const registryIndex = `
// @ts-nocheck
// This file is autogenerated by scripts/build-registry.mts
// Do not edit this file directly.
import * as React from "react"

export const Index = {
  "default": {
    ${registry.items
      .filter((item) => item.type === 'registry:example')
      .map((item) => {
        const componentFile = item.files.find((file) => file.path.endsWith('.tsx'))

        return `
    "${item.name}": {
      component: ${componentFile ? `React.lazy(() => import("@/${componentFile.path}"))` : 'null'},
    }
    `
      })}
  },
} as const
`
fs.writeFileSync(`__registry__/index.tsx`, registryIndex)