Build progress

This commit is contained in:
Alex Gleason committed 2025-07-17 18:15:54 -05:00
1 parent 157ddfdac9
commit 3d8ccdca45
5 files changed
+63 -8

No files matched your search

+7
View File
@@ -45,6 +45,7 @@
"@tanstack/react-query": "^5.56.2",
"@unhead/addons": "^2.0.10",
"@unhead/react": "^2.0.10",
"@webcontainer/api": "^1.6.1",
"ai": "^4.3.19",
"buffer": "^6.0.3",
"class-variance-authority": "^0.7.1",
@@ -4103,6 +4104,12 @@
"url": "https://opencollective.com/vitest"
}
},
"node_modules/@webcontainer/api": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/@webcontainer/api/-/api-1.6.1.tgz",
"integrity": "sha512-2RS2KiIw32BY1Icf6M1DvqSmcon9XICZCDgS29QJb2NmF12ZY2V5Ia+949hMKB3Wno+P/Y8W+sPP59PZeXSELg==",
"license": "MIT"
},
"node_modules/acorn": {
"version": "8.14.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.1.tgz",
+1
View File
@@ -47,6 +47,7 @@
"@tanstack/react-query": "^5.56.2",
"@unhead/addons": "^2.0.10",
"@unhead/react": "^2.0.10",
"@webcontainer/api": "^1.6.1",
"ai": "^4.3.19",
"buffer": "^6.0.3",
"class-variance-authority": "^0.7.1",
+50 -7
View File
@@ -1,15 +1,18 @@
import { FileSystemTree, WebContainer } from '@webcontainer/api';
import { useState, useRef, useEffect } from 'react';
import { CoreMessage, generateText, CoreUserMessage, CoreAssistantMessage, CoreToolMessage, generateId } from 'ai';
import { Button } from '@/components/ui/button';
import { Textarea } from '@/components/ui/textarea';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Card } from '@/components/ui/card';
import { Send, Bot, User, Settings } from 'lucide-react';
import { Send, Bot, User, Settings, Play } from 'lucide-react';
import { cn } from '@/lib/utils';
import { useAISettings } from '@/contexts/AISettingsContext';
import { FsToolSet } from '@/lib/FsToolSet';
import { fsManager } from '@/lib/fs';
const webcontainerPromise = WebContainer.boot();
interface ChatPaneProps {
projectId: string;
projectName: string;
@@ -39,6 +42,49 @@ export function ChatPane({ projectId, projectName }: ChatPaneProps) {
});
};
const runBuild = async () => {
const webcontainer = await webcontainerPromise;
const buildFileTree = async (dirPath: string): Promise<FileSystemTree> => {
const tree: FileSystemTree = {};
const items = await fsManager.fs.promises.readdir(dirPath);
for (const item of items) {
const itemPath = `${dirPath}/${item}`;
const stat = await fsManager.fs.promises.stat(itemPath);
if (stat.isDirectory()) {
tree[item] = {
directory: await buildFileTree(itemPath),
};
} else {
const content = await fsManager.fs.promises.readFile(itemPath, 'utf8');
tree[item] = {
file: {
contents: content,
},
};
}
}
return tree;
};
const fsTree = await buildFileTree(`/projects/${projectId}`);
await webcontainer.mount(fsTree);
// Install dependencies and build
const proc = await webcontainer.spawn('npm', ['i']);
await proc.exit;
console.log(await webcontainer.fs.readdir('.'));
// Copy "node_moudles" out of the webcontainer back to the project directory
// const buildProcess = await webcontainer.spawn('npm', ['run', 'build']);
};
useEffect(() => {
// Add welcome message
addMessage({
@@ -235,13 +281,10 @@ When creating new components or pages, follow the existing patterns in the codeb
variant="outline"
size="sm"
className="gap-2"
onClick={() => {
const event = new CustomEvent('openAISettings');
window.dispatchEvent(event);
}}
onClick={runBuild}
>
<Settings className="h-4 w-4" />
Settings
<Play className="h-4 w-4" />
Build
</Button>
</div>
+1 -1
View File
@@ -43,7 +43,7 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) {
if (!selectedFile) return;
try {
await fsManager.writeFile(projectId, selectedFile, content);
await fsManager.fs.promises.writeFile(`/projects/${projectId}/${selectedFile}`, content);
setFileContent(content);
} catch (error) {
console.error('Failed to save file:', error);
+4
View File
@@ -8,6 +8,10 @@ export default defineConfig(() => ({
server: {
host: "::",
port: 8080,
headers: {
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Opener-Policy': 'same-origin',
},
},
plugins: [
react(),