Add deploy button

This commit is contained in:
Alex Gleason committed 2025-07-20 19:11:41 -05:00
1 parent 68d852b5b8
commit b6275fc33e
5 files changed
+82 -18

No files matched your search

+6 -9
View File
@@ -57,7 +57,7 @@
"isomorphic-git": "^1.32.1",
"lucide-react": "^0.525.0",
"next-themes": "^0.3.0",
"nostr-tools": "^2.13.0",
"nostr-tools": "^2.15.1",
"react": "^18.3.1",
"react-day-picker": "^8.10.1",
"react-dom": "^18.3.1",
@@ -6686,9 +6686,9 @@
}
},
"node_modules/nostr-tools": {
"version": "2.13.0",
"resolved": "https://registry.npmjs.org/nostr-tools/-/nostr-tools-2.13.0.tgz",
"integrity": "sha512-A1arGsvpULqVK0NmZQqK1imwaCiPm8gcG/lo+cTax2NbNqBEYsuplbqAFdVqcGHEopmkByYbTwF76x25+oEbew==",
"version": "2.15.1",
"resolved": "https://registry.npmjs.org/nostr-tools/-/nostr-tools-2.15.1.tgz",
"integrity": "sha512-LpetHDR9ltnkpJDkva/SONgyKBbsoV+5yLB8DWc0/U3lCWGtoWJw6Nbc2vR2Ai67RIQYrBQeZLyMlhwVZRK/9A==",
"license": "Unlicense",
"dependencies": {
"@noble/ciphers": "^0.5.1",
@@ -6696,9 +6696,7 @@
"@noble/hashes": "1.3.1",
"@scure/base": "1.1.1",
"@scure/bip32": "1.3.1",
"@scure/bip39": "1.2.1"
},
"optionalDependencies": {
"@scure/bip39": "1.2.1",
"nostr-wasm": "0.1.0"
},
"peerDependencies": {
@@ -6714,8 +6712,7 @@
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/nostr-wasm/-/nostr-wasm-0.1.0.tgz",
"integrity": "sha512-78BTryCLcLYv96ONU8Ws3Q1JzjlAt+43pWQhIl86xZmWeegYCNLPml7yQ+gG3vR6V5h4XGj+TxO+SS5dsThQIA==",
"license": "MIT",
"optional": true
"license": "MIT"
},
"node_modules/nwsapi": {
"version": "2.2.20",
+1 -1
View File
@@ -59,7 +59,7 @@
"isomorphic-git": "^1.32.1",
"lucide-react": "^0.525.0",
"next-themes": "^0.3.0",
"nostr-tools": "^2.13.0",
"nostr-tools": "^2.15.1",
"react": "^18.3.1",
"react-day-picker": "^8.10.1",
"react-dom": "^18.3.1",
+58 -5
View File
@@ -5,13 +5,15 @@ 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, Play } from 'lucide-react';
import { Send, Bot, User, Settings, Play, CloudUpload } from 'lucide-react';
import { cn } from '@/lib/utils';
import { useAISettings } from '@/hooks/useAISettings';
import { FsToolSet } from '@/lib/FsToolSet';
import { useFS } from '@/hooks/useFS';
import { useJSRuntime } from '@/hooks/useJSRuntime';
import { copyDirectory } from '@/lib/copyFiles';
import { generateSecretKey, getPublicKey, nip19 } from 'nostr-tools';
import { bytesToHex } from 'nostr-tools/utils';
interface ChatPaneProps {
projectId: string;
@@ -26,7 +28,7 @@ export function ChatPane({ projectId, projectName }: ChatPaneProps) {
const [isLoading, setIsLoading] = useState(false);
const scrollAreaRef = useRef<HTMLDivElement>(null);
const { settings, isConfigured } = useAISettings();
const { fs } = useFS();
const { fs: browserFS } = useFS();
const { runtime } = useJSRuntime();
const addMessage = (message: AIMessage) => {
@@ -51,7 +53,7 @@ export function ChatPane({ projectId, projectName }: ChatPaneProps) {
// Copy project files to runtime filesystem
const projectPath = `/projects/${projectId}`;
try {
await copyDirectory(fs, runtimeFS, projectPath, '.');
await copyDirectory(browserFS, runtimeFS, projectPath, '.');
console.log('Successfully copied project to runtime');
} catch (error) {
console.error('Failed to copy project to runtime:', error);
@@ -68,13 +70,55 @@ export function ChatPane({ projectId, projectName }: ChatPaneProps) {
// Copy "dist" directory from runtime back to project filesystem
const distPath = `/projects/${projectId}/dist`;
try {
await copyDirectory(runtimeFS, fs, 'dist', distPath);
await copyDirectory(runtimeFS, browserFS, 'dist', distPath);
console.log('Successfully copied dist from runtime');
} catch (error) {
console.error('Failed to copy dist:', error);
}
};
const runDeploy = async () => {
const runtimeFS = await runtime.fs();
const sk = generateSecretKey();
const pubkey = getPublicKey(sk);
const npub = nip19.npubEncode(pubkey);
const projectUrl = `https://${npub}.nostrdeploy.com`;
console.log('Running deploy for project:', projectId, 'at', projectUrl);
await runtimeFS.mkdir('dist', { recursive: true });
await runtimeFS.writeFile('.env.nostr-deploy.local', `# Nostr Deploy CLI Configuration
# This file contains sensitive information - do not commit to version control
# Nostr Authentication
NOSTR_PRIVATE_KEY=${bytesToHex(sk)}
NOSTR_PUBLIC_KEY=${pubkey}
NOSTR_RELAYS=wss://relay.nostr.band,wss://relay.primal.net,wss://ditto.pub/relay
# Blossom File Storage
BLOSSOM_SERVERS=https://cdn.hzrd149.com,https://blossom.primal.net,https://blossom.band,https://blossom.f7z.io
# Deployment Settings
BASE_DOMAIN=nostrdeploy.com`);
// Copy "dist" files to runtime filesystem
const distPath = `/projects/${projectId}/dist`;
try {
await copyDirectory(browserFS, runtimeFS, distPath, 'dist');
console.log('Successfully copied dist to runtime');
} catch (error) {
console.error('Failed to copy dist to runtime:', error);
return;
}
const proc = await runtime.spawn('npx', ["-y", "nostr-deploy-cli", "deploy"]);
await proc.exit;
console.log('Project deployed:', projectUrl);
};
useEffect(() => {
// Add welcome message
addMessage({
@@ -115,7 +159,7 @@ export function ChatPane({ projectId, projectName }: ChatPaneProps) {
});
const provider = openai(settings.model);
const toolSet = new FsToolSet(fs, `/projects/${projectId}`);
const toolSet = new FsToolSet(browserFS, `/projects/${projectId}`);
return generateText({
model: provider,
@@ -276,6 +320,15 @@ When creating new components or pages, follow the existing patterns in the codeb
<Play className="h-4 w-4" />
Build
</Button>
<Button
variant="outline"
size="sm"
className="gap-2"
onClick={runDeploy}
>
<CloudUpload className="h-4 w-4" />
Deploy
</Button>
</div>
<ScrollArea className="flex-1 p-4" ref={scrollAreaRef}>
+15 -1
View File
@@ -14,7 +14,7 @@ export interface JSRuntime {
* @param options Spawn options
* @returns Process handle
*/
spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<JSRuntimeChildProcess>;
spawn(command: string, args?: string[], options?: SpawnOptions): Promise<JSRuntimeChildProcess>;
}
/**
@@ -87,4 +87,18 @@ export interface JSRuntimeChildProcess {
* Kills the process.
*/
kill(): void;
}
/**
* Options that control process spawning.
*/
export interface SpawnOptions {
/**
* Current working directory for the process, relative to the workdir of this instance.
*/
cwd?: string;
/**
* Environment variables to set for the process.
*/
env?: Record<string, string | number | boolean>;
}
+2 -2
View File
@@ -1,5 +1,5 @@
import { WebContainer } from '@webcontainer/api';
import type { JSRuntime, JSRuntimeFS, JSRuntimeChildProcess, DirectoryEntry } from './JSRuntime';
import type { JSRuntime, JSRuntimeFS, JSRuntimeChildProcess, DirectoryEntry, SpawnOptions } from './JSRuntime';
/**
* WebContainer adapter that implements the JSRuntime interface
@@ -36,7 +36,7 @@ export class WebContainerAdapter implements JSRuntime {
* Spawn a process in the WebContainer
* Automatically boots the container on first call
*/
async spawn(command: string, args: string[] = [], options: Record<string, unknown> = {}): Promise<JSRuntimeChildProcess> {
async spawn(command: string, args: string[] = [], options: SpawnOptions = {}): Promise<JSRuntimeChildProcess> {
const webcontainer = await this.ensureBooted();
return webcontainer.spawn(command, args, options);
}