From 09cf6d56a83492c0270d34ac30bd108d4ed4bebb Mon Sep 17 00:00:00 2001 From: zernonia Date: Sat, 23 Mar 2024 14:38:22 +0800 Subject: [PATCH] chore: build registry --- apps/www/__registry__/index.ts | 14 ++++++++++++++ apps/www/src/lib/registry/registry.ts | 21 ++++++++++++--------- apps/www/src/lib/registry/schema.ts | 1 + 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/apps/www/__registry__/index.ts b/apps/www/__registry__/index.ts index 92472ada..01ba753b 100644 --- a/apps/www/__registry__/index.ts +++ b/apps/www/__registry__/index.ts @@ -1102,6 +1102,13 @@ export const Index = { component: () => import("../src/lib/registry/default/example/Cards/Metric.vue").then((m) => m.default), files: ["../src/lib/registry/default/example/Cards/Metric.vue"], }, + "Authentication01": { + name: "Authentication01", + type: "components:block", + registryDependencies: ["button","card","input","label"], + component: () => import("../src/lib/registry/default/block/Authentication01.vue").then((m) => m.default), + files: ["../src/lib/registry/default/block/Authentication01.vue"], + }, }, "new-york": { "AccordionDemo": { name: "AccordionDemo", @@ -2202,5 +2209,12 @@ export const Index = { component: () => import("../src/lib/registry/new-york/example/Cards/Metric.vue").then((m) => m.default), files: ["../src/lib/registry/new-york/example/Cards/Metric.vue"], }, + "Authentication01": { + name: "Authentication01", + type: "components:block", + registryDependencies: ["button","card","input","label"], + component: () => import("../src/lib/registry/new-york/block/Authentication01.vue").then((m) => m.default), + files: ["../src/lib/registry/new-york/block/Authentication01.vue"], + }, }, } diff --git a/apps/www/src/lib/registry/registry.ts b/apps/www/src/lib/registry/registry.ts index 2205d062..5ad0acd9 100644 --- a/apps/www/src/lib/registry/registry.ts +++ b/apps/www/src/lib/registry/registry.ts @@ -27,9 +27,12 @@ export async function buildRegistry() { const uiRegistry = await crawlUI(ui_path) const example_path = resolve('./src/lib/registry/default/example') - const exampleRegistry = await crawlExample(example_path) + const exampleRegistry = await crawlDirectory(example_path, 'example') - return uiRegistry.concat(exampleRegistry) + const block_path = resolve('./src/lib/registry/default/block') + const blockRegistry = await crawlDirectory(block_path, 'block') + + return uiRegistry.concat(exampleRegistry).concat(blockRegistry) } async function crawlUI(rootPath: string) { @@ -53,15 +56,15 @@ async function crawlUI(rootPath: string) { return uiRegistry } -async function crawlExample(rootPath: string) { - const type = 'components:example' +async function crawlDirectory(rootPath: string, typeName: 'example' | 'block') { + const type = `components:${typeName}` as const const dir = await readdir(rootPath, { recursive: true, withFileTypes: true, }) - const exampleRegistry: Registry = [] + const registry: Registry = [] for (const dirent of dir) { if (dirent.name === 'index.ts') @@ -69,11 +72,11 @@ async function crawlExample(rootPath: string) { if (dirent.isFile()) { const [name] = dirent.name.split('.vue') - const file_path = join('example', normalize(dirent.path).split('/example')[1], dirent.name) + const file_path = join(typeName, normalize(dirent.path).split(`/${typeName}`)[1], dirent.name) const { dependencies, registryDependencies } = await getDependencies(join(dirent.path, dirent.name)) - exampleRegistry.push({ + registry.push({ name, type, files: [file_path], @@ -87,14 +90,14 @@ async function crawlExample(rootPath: string) { // if (dirent.isDirectory()) { // const componentPath = resolve(rootPath, dirent.name); // const ui = await buildUIRegistry(componentPath, dirent.name); - // exampleRegistry.push({ + // registry.push({ // ...ui, // type // }); // } } - return exampleRegistry + return registry } async function buildUIRegistry(componentPath: string, componentName: string) { diff --git a/apps/www/src/lib/registry/schema.ts b/apps/www/src/lib/registry/schema.ts index 36b22454..94387a37 100644 --- a/apps/www/src/lib/registry/schema.ts +++ b/apps/www/src/lib/registry/schema.ts @@ -10,6 +10,7 @@ export const registrySchema = z.array( 'components:ui', 'components:component', 'components:example', + 'components:block', ]), }), )