import type { Tool, ToolResult } from "./Tool"; import type { JSRuntimeFS } from "../JSRuntime"; import { buildProject } from "../build"; export class BuildProjectTool implements Tool { private fs: JSRuntimeFS; private cwd: string; private esmUrl: string; readonly description = "Build the project using esbuild. Creates optimized production files in the dist directory."; constructor(fs: JSRuntimeFS, cwd: string, esmUrl: string) { this.fs = fs; this.cwd = cwd; this.esmUrl = esmUrl; } async execute(): Promise { try { // Build and write the project files const result = await buildProject({ esmUrl: this.esmUrl, fs: this.fs, projectPath: this.cwd, domParser: new DOMParser(), }); const fileCount = Object.keys(result.files).length; const fileList = Object.keys(result.files).map(file => ` šŸ“„ ${file}`).join('\n'); return { content: `āœ… Successfully built project!\n\nšŸ“ Output: ${result.outputPath}\nšŸ“¦ Files generated: ${fileCount}\n\n${fileList}\n\nšŸš€ Your project is ready for deployment!` }; } catch (error) { throw new Error(`āŒ Build failed: ${String(error)}`); } } }