import type { Tool } from "./Tool"; import type { JSRuntimeFS } from "../JSRuntime"; import { buildProject } from "../build"; export class BuildProjectTool implements Tool { private fs: JSRuntimeFS; private cwd: string; readonly description = "Build the project using esbuild. Creates optimized production files in the dist directory."; constructor(fs: JSRuntimeFS, cwd: string) { this.fs = fs; this.cwd = cwd; } async execute(): Promise { try { // Build and write the project files const result = await buildProject({ 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 `āœ… 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)}`); } } }