@@ -11,7 +11,7 @@ const componentsDir = resolve(__dirname, "src/ui/components");
1111const entriesDir = resolve ( __dirname , "node_modules/.cache/mongodb-mcp-server/ui-entries" ) ;
1212const templatePath = resolve ( __dirname , "src/ui/build/template.html" ) ;
1313const mountPath = resolve ( __dirname , "src/ui/build/mount.tsx" ) ;
14- const generatedModulePath = resolve ( __dirname , "src/ui/generated/uiHtml.ts " ) ;
14+ const generatedDir = resolve ( __dirname , "src/ui/generated" ) ;
1515const uiDistPath = resolve ( __dirname , "dist/ui" ) ;
1616
1717// Unique component names from uiMap - only these will be built
@@ -56,11 +56,9 @@ function generateHtmlEntries(): Plugin {
5656}
5757
5858/**
59- * Vite plugin that generates the uiHtml.ts module after the build completes.
60- * This embeds all built HTML strings into a TypeScript module so they can be
61- * imported at runtime.
59+ * Vite plugin that generates per-tool UI modules after the build completes.
6260 *
63- * Uses the uiMap from src/ui/registry/uiMap.ts to map tool names to component HTML files.
61+ * Uses the uiMap to map tool names to component HTML files.
6462 */
6563function generateUIModule ( ) : Plugin {
6664 return {
@@ -71,9 +69,16 @@ function generateUIModule(): Plugin {
7169 return ;
7270 }
7371
74- const entries : Record < string , string > = { } ;
72+ const toolsDir = join ( generatedDir , "tools" ) ;
73+ if ( ! existsSync ( generatedDir ) ) {
74+ mkdirSync ( generatedDir , { recursive : true } ) ;
75+ }
76+ if ( ! existsSync ( toolsDir ) ) {
77+ mkdirSync ( toolsDir , { recursive : true } ) ;
78+ }
79+
80+ const generatedTools : string [ ] = [ ] ;
7581
76- // Use uiMap to determine which tools get which UI
7782 for ( const [ toolName , componentName ] of Object . entries ( uiMap ) ) {
7883 const htmlFile = join ( uiDistPath , `${ componentName } .html` ) ;
7984 if ( ! existsSync ( htmlFile ) ) {
@@ -83,32 +88,21 @@ function generateUIModule(): Plugin {
8388 continue ;
8489 }
8590 const html = readFileSync ( htmlFile , "utf-8" ) ;
86- entries [ toolName ] = html ;
87- }
8891
89- const moduleContent = `/**
92+ const toolModuleContent = `/**
9093 * AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
91- *
92- * This file is generated by the UI build process (vite build --config vite.ui.config.ts).
93- * It contains the bundled HTML strings for each UI component, keyed by tool name.
94- *
95- * To add a new UI:
96- * 1. Create a component in src/ui/components/YourComponent/
97- * 2. Add the mapping in src/ui/registry/uiMap.ts
98- * 3. Run \`pnpm build:ui\` to regenerate this file
94+ * Generated by: vite build --config vite.ui.config.ts
95+ * Tool: ${ toolName }
96+ * Component: ${ componentName }
9997 */
100- export const uiHtml: Record<string, string> = ${ JSON . stringify ( entries , null , 4 ) } ;
98+ export default ${ JSON . stringify ( html ) } ;
10199` ;
102-
103- // Ensure the generated directory exists
104- const generatedDir = dirname ( generatedModulePath ) ;
105- if ( ! existsSync ( generatedDir ) ) {
106- mkdirSync ( generatedDir , { recursive : true } ) ;
100+ writeFileSync ( join ( toolsDir , `${ toolName } .ts` ) , toolModuleContent ) ;
101+ generatedTools . push ( toolName ) ;
107102 }
108103
109- writeFileSync ( generatedModulePath , moduleContent ) ;
110104 console . log (
111- `[generate-ui-module] Generated uiHtml.ts with ${ Object . keys ( entries ) . length } UI (s): ${ Object . keys ( entries ) . join ( ", " ) } `
105+ `[generate-ui-module] Generated ${ generatedTools . length } lazy UI module (s): ${ generatedTools . join ( ", " ) } `
112106 ) ;
113107 } ,
114108 } ;
0 commit comments