From 4cb9c017482d8d075409e6b83f32c16b098c7ed7 Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Sun, 18 Jan 2026 18:44:59 +0000 Subject: [PATCH] Add sourceRoots config for component registry --- json-components-registry.json | 8 ++++++ schemas/json-components-registry-schema.json | 9 +++++++ src/lib/json-ui/component-registry.ts | 26 +++++++++++--------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/json-components-registry.json b/json-components-registry.json index 575f4c0..02deb09 100644 --- a/json-components-registry.json +++ b/json-components-registry.json @@ -12,6 +12,14 @@ "data": "Data display and visualization components", "custom": "Custom domain-specific components" }, + "sourceRoots": { + "atoms": ["@/components/atoms/*.tsx"], + "molecules": ["@/components/molecules/*.tsx"], + "organisms": ["@/components/organisms/*.tsx"], + "ui": ["@/components/ui/**/*.{ts,tsx}"], + "wrappers": ["@/lib/json-ui/wrappers/*.tsx"], + "icons": [] + }, "components": [ { "type": "ActionCard", diff --git a/schemas/json-components-registry-schema.json b/schemas/json-components-registry-schema.json index 9b9d424..a4ebcae 100644 --- a/schemas/json-components-registry-schema.json +++ b/schemas/json-components-registry-schema.json @@ -22,6 +22,15 @@ "type": "string" } }, + "sourceRoots": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } + }, "components": { "type": "array", "items": { diff --git a/src/lib/json-ui/component-registry.ts b/src/lib/json-ui/component-registry.ts index d18b342..1f51c00 100644 --- a/src/lib/json-ui/component-registry.ts +++ b/src/lib/json-ui/component-registry.ts @@ -24,6 +24,7 @@ interface JsonRegistryEntry { interface JsonComponentRegistry { components?: JsonRegistryEntry[] + sourceRoots?: Record } export interface DeprecatedComponentInfo { @@ -32,6 +33,15 @@ export interface DeprecatedComponentInfo { } const jsonRegistry = jsonComponentsRegistry as JsonComponentRegistry +const sourceRoots = jsonRegistry.sourceRoots ?? {} +const moduleMapsBySource = Object.fromEntries( + Object.entries(sourceRoots).map(([source, patterns]) => { + if (!patterns || patterns.length === 0) { + return [source, {}] + } + return [source, import.meta.glob(patterns, { eager: true })] + }) +) as Record> const getRegistryEntryKey = (entry: JsonRegistryEntry): string | undefined => entry.name ?? entry.type @@ -89,17 +99,11 @@ const buildComponentMapFromModules = ( }, {}) } -const atomModules = import.meta.glob('@/components/atoms/*.tsx', { eager: true }) -const moleculeModules = import.meta.glob('@/components/molecules/*.tsx', { eager: true }) -const organismModules = import.meta.glob('@/components/organisms/*.tsx', { eager: true }) -const uiModules = import.meta.glob('@/components/ui/**/*.{ts,tsx}', { eager: true }) -const wrapperModules = import.meta.glob('@/lib/json-ui/wrappers/*.tsx', { eager: true }) - -const atomComponentMap = buildComponentMapFromModules(atomModules) -const moleculeComponentMap = buildComponentMapFromModules(moleculeModules) -const organismComponentMap = buildComponentMapFromModules(organismModules) -const uiComponentMap = buildComponentMapFromModules(uiModules) -const wrapperComponentMap = buildComponentMapFromModules(wrapperModules) +const atomComponentMap = buildComponentMapFromModules(moduleMapsBySource.atoms ?? {}) +const moleculeComponentMap = buildComponentMapFromModules(moduleMapsBySource.molecules ?? {}) +const organismComponentMap = buildComponentMapFromModules(moduleMapsBySource.organisms ?? {}) +const uiComponentMap = buildComponentMapFromModules(moduleMapsBySource.ui ?? {}) +const wrapperComponentMap = buildComponentMapFromModules(moduleMapsBySource.wrappers ?? {}) const iconComponentMap = buildComponentMapFromExports(PhosphorIcons) const sourceAliases: Record> = {