Files
supabase/apps/ui-library/scripts/build-registry.mts
Ivan Vasilov 501918857b chore: Remove unused code from ui-library (#38374)
* Remove unneeded code.

* Remove more unused code.

* Update knip.jsonc for ui-library.

* Remove unneeded imports. Change the registry generation to only generate what's needed.

* Cleanup the rehype middleware (it wasn't used). Clean up the example blocks generation.

* Don't show the "show code" button in all dropzone examples.
2025-09-02 15:36:41 +02:00

43 lines
1.2 KiB
TypeScript

// typecheck
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import { registry } from '../registry/index'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const registryPath = path.join(__dirname, '..', 'registry.json')
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)