From 6bd4b869bf42d37e3b9d28364352db60cc7f6e04 Mon Sep 17 00:00:00 2001 From: DemaPy Date: Sat, 28 Dec 2024 23:08:06 +0100 Subject: [PATCH] missing files in toast manual installation --- apps/www/lib/rehype-component.ts | 28 ++++++++++++++++++---------- apps/www/registry/schema.ts | 2 ++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/www/lib/rehype-component.ts b/apps/www/lib/rehype-component.ts index c43aa8d8721..3a3b8cd3951 100644 --- a/apps/www/lib/rehype-component.ts +++ b/apps/www/lib/rehype-component.ts @@ -4,6 +4,8 @@ import { UnistNode, UnistTree } from "types/unist" import { u } from "unist-builder" import { visit } from "unist-util-visit" +import { type RegistryItem } from "@/registry/schema" + import { Index } from "../__registry__" import { styles } from "../registry/registry-styles" @@ -35,18 +37,24 @@ export function rehypeComponent() { if (srcPath) { src = path.join(process.cwd(), srcPath) } else { - const component = Index[style.name][name] - src = fileName - ? component.files.find((file: unknown) => { - if (typeof file === "string") { + const component: RegistryItem = Index[style.name][name] + if (component.files) { + console.log(fileName) + + src = fileName + ? component.files.find((file) => { return ( - file.endsWith(`${fileName}.tsx`) || - file.endsWith(`${fileName}.ts`) + file.path.endsWith(`${fileName}.tsx`) || + file.path.endsWith(`${fileName}.ts`) ) - } - return false - }) || component.files[0]?.path - : component.files[0]?.path + })?.path || component.files[0]?.path + : component.files[0]?.path + } else { + // TODO: Is files always exist in Registry type? + // Because in registryItemSchema it is marked like optional. + src = component.files![0]?.path + } + console.log(src); } // Read the source file. diff --git a/apps/www/registry/schema.ts b/apps/www/registry/schema.ts index 3bcda767eb3..ae17afba00c 100644 --- a/apps/www/registry/schema.ts +++ b/apps/www/registry/schema.ts @@ -53,6 +53,8 @@ export const registryItemSchema = z.object({ export const registrySchema = z.array(registryItemSchema) export type Registry = z.infer +export type RegistryItem = Registry[number] +export type FileRegistry = Registry[number]['files'] export const blockSchema = registryItemSchema.extend({ type: z.literal("registry:block"),