Skip to content

Commit 89d9330

Browse files
committed
improve item registry
1 parent 900d5d1 commit 89d9330

22 files changed

Lines changed: 354 additions & 159 deletions

build-component-registry.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path, { parse } from 'node:path'
22
import { Project } from 'ts-morph'
33

4-
type ExportsConfig =
4+
type ExportEntry =
55
| {
66
type: 'named'
77
specifier: string
@@ -23,17 +23,17 @@ const source = project.addSourceFileAtPath(indexPath)
2323
const index: { id: string }[] = []
2424

2525
for (const exp of source.getExportDeclarations()) {
26-
let exportsConfig: ExportsConfig = {} as ExportsConfig
26+
const exports: ExportEntry[] = []
2727

2828
const moduleSpecifier = exp.getModuleSpecifierValue()
2929
if (!moduleSpecifier) continue
3030

3131
if (exp.getNamespaceExport()) {
32-
exportsConfig = {
32+
exports.push({
3333
type: 'namespace',
3434
specifier: moduleSpecifier,
3535
name: exp.getNamespaceExportOrThrow().getName(),
36-
}
36+
})
3737
}
3838

3939
const namedExports = exp.getNamedExports().map((ne) => {
@@ -43,11 +43,11 @@ for (const exp of source.getExportDeclarations()) {
4343
})
4444

4545
if (namedExports.length > 0) {
46-
exportsConfig = {
46+
exports.push({
4747
type: 'named',
4848
specifier: moduleSpecifier,
4949
symbols: namedExports,
50-
}
50+
})
5151
}
5252

5353
const moduleSourceFile = exp.getModuleSpecifierSourceFile()
@@ -65,13 +65,20 @@ for (const exp of source.getExportDeclarations()) {
6565
})
6666

6767
Bun.write(
68-
`./website/public/registry/latest/components/react/${id}.json`,
68+
`./website/public/registry/latest/react/components/${id}.json`,
6969
JSON.stringify(
7070
{
71+
$schema: 'https://next.park-ui.com/schema/registry-item.json',
7172
id,
72-
filename,
73-
sourceCode: await file.text(),
74-
exportsConfig,
73+
type: 'component',
74+
files: [
75+
{
76+
type: 'component',
77+
content: await file.text(),
78+
path: filename,
79+
exports,
80+
},
81+
],
7582
},
7683
null,
7784
2,
@@ -81,6 +88,6 @@ for (const exp of source.getExportDeclarations()) {
8188
}
8289

8390
Bun.write(
84-
`./website/public/registry/latest/components/react/index.json`,
91+
`./website/public/registry/latest/react/components/index.json`,
8592
JSON.stringify(index, null, 2),
8693
)

packages/cli/src/types.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1-
type RegistryItemType = 'block' | 'component' | 'recipe' | 'item'
1+
type RegistryItemType = 'block' | 'component' | 'recipe' | 'slotRecipe'
2+
3+
type ExportEntry =
4+
| {
5+
type: 'named'
6+
specifier: string
7+
symbols: {
8+
name: string
9+
isType?: boolean | undefined
10+
}[]
11+
}
12+
| {
13+
type: 'namespace'
14+
specifier: string
15+
name: string
16+
}
217

318
interface RegistryFile {
4-
/** The path to the file relative to the registry root */
19+
/** This is the path to the file in the project. */
520
path: string
621

722
/** The content of the file */
8-
content?: string
23+
content: string
924

1025
/** The type of the file. This is used to determine the type of the file when resolved for a project */
1126
type: RegistryItemType
27+
28+
/** Defines the module exports available from this file, including named exports with their symbols and namespace exports. */
29+
exports?: ExportEntry[]
1230
}
1331

1432
interface PandaConfig {

website/public/registry/latest/components/react/avatar.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

website/public/registry/latest/components/react/badge.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

website/public/registry/latest/components/react/button.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

website/public/registry/latest/components/react/card.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

website/public/registry/latest/components/react/field.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

website/public/registry/latest/components/react/heading.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

website/public/registry/latest/components/react/input.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

website/public/registry/latest/components/react/link.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)