Skip to content

Commit e3d8b01

Browse files
committed
refactor: update HTML exports to named constants and enhance dynamic loading in UIRegistry
1 parent b7eb685 commit e3d8b01

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/ui/lib/tools/list-databases.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ui/registry/registry.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
// Converts kebab-case to PascalCase: "list-databases" -> "ListDatabases"
2+
function toPascalCase(kebabCase: string): string {
3+
return kebabCase
4+
.split("-")
5+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
6+
.join("");
7+
}
8+
19
/**
210
* UI Registry that manages bundled UI HTML strings for tools.
311
*/
@@ -28,9 +36,14 @@ export class UIRegistry {
2836
}
2937

3038
try {
31-
const module = (await import(`../lib/tools/${toolName}.js`)) as { default: string };
32-
this.cache.set(toolName, module.default);
33-
return module.default;
39+
const module = (await import(`../lib/tools/${toolName}.js`)) as Record<string, string>;
40+
const exportName = `${toPascalCase(toolName)}Html`;
41+
const html = module[exportName];
42+
if (html === undefined) {
43+
return null;
44+
}
45+
this.cache.set(toolName, html);
46+
return html;
3447
} catch {
3548
return null;
3649
}

vite.ui.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function generateUIModule(): Plugin {
107107
* Tool: ${toolName}
108108
* Component: ${componentName}
109109
*/
110-
export default ${JSON.stringify(html)};
110+
export const ${componentName}Html = ${JSON.stringify(html)};
111111
`;
112112
writeFileSync(join(toolsDir, `${toolName}.ts`), toolModuleContent);
113113
generatedTools.push(toolName);

0 commit comments

Comments
 (0)