mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Deploy with nostrdeploy
This commit is contained in:
5 files changed
+80
-175
No files matched your search
Generated
+6
-9
@@ -57,7 +57,7 @@
|
|||||||
"isomorphic-git": "^1.32.1",
|
"isomorphic-git": "^1.32.1",
|
||||||
"lucide-react": "^0.525.0",
|
"lucide-react": "^0.525.0",
|
||||||
"next-themes": "^0.3.0",
|
"next-themes": "^0.3.0",
|
||||||
"nostr-tools": "^2.13.0",
|
"nostr-tools": "^2.15.1",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-day-picker": "^8.10.1",
|
"react-day-picker": "^8.10.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
@@ -6710,9 +6710,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/nostr-tools": {
|
"node_modules/nostr-tools": {
|
||||||
"version": "2.13.0",
|
"version": "2.15.1",
|
||||||
"resolved": "https://registry.npmjs.org/nostr-tools/-/nostr-tools-2.13.0.tgz",
|
"resolved": "https://registry.npmjs.org/nostr-tools/-/nostr-tools-2.15.1.tgz",
|
||||||
"integrity": "sha512-A1arGsvpULqVK0NmZQqK1imwaCiPm8gcG/lo+cTax2NbNqBEYsuplbqAFdVqcGHEopmkByYbTwF76x25+oEbew==",
|
"integrity": "sha512-LpetHDR9ltnkpJDkva/SONgyKBbsoV+5yLB8DWc0/U3lCWGtoWJw6Nbc2vR2Ai67RIQYrBQeZLyMlhwVZRK/9A==",
|
||||||
"license": "Unlicense",
|
"license": "Unlicense",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@noble/ciphers": "^0.5.1",
|
"@noble/ciphers": "^0.5.1",
|
||||||
@@ -6720,9 +6720,7 @@
|
|||||||
"@noble/hashes": "1.3.1",
|
"@noble/hashes": "1.3.1",
|
||||||
"@scure/base": "1.1.1",
|
"@scure/base": "1.1.1",
|
||||||
"@scure/bip32": "1.3.1",
|
"@scure/bip32": "1.3.1",
|
||||||
"@scure/bip39": "1.2.1"
|
"@scure/bip39": "1.2.1",
|
||||||
},
|
|
||||||
"optionalDependencies": {
|
|
||||||
"nostr-wasm": "0.1.0"
|
"nostr-wasm": "0.1.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
@@ -6738,8 +6736,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/nostr-wasm/-/nostr-wasm-0.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/nostr-wasm/-/nostr-wasm-0.1.0.tgz",
|
||||||
"integrity": "sha512-78BTryCLcLYv96ONU8Ws3Q1JzjlAt+43pWQhIl86xZmWeegYCNLPml7yQ+gG3vR6V5h4XGj+TxO+SS5dsThQIA==",
|
"integrity": "sha512-78BTryCLcLYv96ONU8Ws3Q1JzjlAt+43pWQhIl86xZmWeegYCNLPml7yQ+gG3vR6V5h4XGj+TxO+SS5dsThQIA==",
|
||||||
"license": "MIT",
|
"license": "MIT"
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"node_modules/nwsapi": {
|
"node_modules/nwsapi": {
|
||||||
"version": "2.2.20",
|
"version": "2.2.20",
|
||||||
|
|||||||
+1
-1
@@ -59,7 +59,7 @@
|
|||||||
"isomorphic-git": "^1.32.1",
|
"isomorphic-git": "^1.32.1",
|
||||||
"lucide-react": "^0.525.0",
|
"lucide-react": "^0.525.0",
|
||||||
"next-themes": "^0.3.0",
|
"next-themes": "^0.3.0",
|
||||||
"nostr-tools": "^2.13.0",
|
"nostr-tools": "^2.15.1",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-day-picker": "^8.10.1",
|
"react-day-picker": "^8.10.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import { cn } from '@/lib/utils';
|
|||||||
import { useAISettings } from '@/contexts/AISettingsContext';
|
import { useAISettings } from '@/contexts/AISettingsContext';
|
||||||
import { FsToolSet } from '@/lib/FsToolSet';
|
import { FsToolSet } from '@/lib/FsToolSet';
|
||||||
import { fsManager } from '@/lib/fs';
|
import { fsManager } from '@/lib/fs';
|
||||||
|
import { getPublicKey, nip19 } from 'nostr-tools';
|
||||||
|
import { bytesToHex } from 'nostr-tools/utils';
|
||||||
|
|
||||||
const webcontainerPromise = WebContainer.boot();
|
const webcontainerPromise = WebContainer.boot();
|
||||||
|
|
||||||
@@ -43,8 +45,23 @@ export function ChatPane({ projectId, projectName }: ChatPaneProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const runBuild = async () => {
|
const runBuild = async () => {
|
||||||
|
const project = await fsManager.getProject(projectId);
|
||||||
|
|
||||||
|
if (!project) {
|
||||||
|
console.error('Project not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const decoded = nip19.decode(project.nsec);
|
||||||
|
if (decoded.type !== 'nsec') {
|
||||||
|
console.error('Invalid NSEC key');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const webcontainer = await webcontainerPromise;
|
const webcontainer = await webcontainerPromise;
|
||||||
|
|
||||||
|
console.log('Deploying project');
|
||||||
|
|
||||||
const buildFileTree = async (dirPath: string): Promise<FileSystemTree> => {
|
const buildFileTree = async (dirPath: string): Promise<FileSystemTree> => {
|
||||||
const tree: FileSystemTree = {};
|
const tree: FileSystemTree = {};
|
||||||
const items = await fsManager.fs.promises.readdir(dirPath);
|
const items = await fsManager.fs.promises.readdir(dirPath);
|
||||||
@@ -73,92 +90,45 @@ export function ChatPane({ projectId, projectName }: ChatPaneProps) {
|
|||||||
const fsTree = await buildFileTree(`/projects/${projectId}`);
|
const fsTree = await buildFileTree(`/projects/${projectId}`);
|
||||||
await webcontainer.mount(fsTree);
|
await webcontainer.mount(fsTree);
|
||||||
|
|
||||||
// Install dependencies and build
|
await webcontainer.fs.writeFile('.env.nostr-deploy.local', `# Nostr Deploy CLI Configuration
|
||||||
const proc = await webcontainer.spawn('npm', ['i']);
|
# This file contains sensitive information - do not commit to version control
|
||||||
await proc.exit;
|
|
||||||
|
# Nostr Authentication
|
||||||
|
NOSTR_PRIVATE_KEY=${bytesToHex(decoded.data)}
|
||||||
|
NOSTR_PUBLIC_KEY=${getPublicKey(decoded.data)}
|
||||||
|
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`);
|
||||||
|
|
||||||
|
const proc1 = await webcontainer.spawn('npm', ['install']);
|
||||||
|
proc1.output.pipeTo(new WritableStream({
|
||||||
|
write(data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
await proc1.exit;
|
||||||
|
|
||||||
const proc2 = await webcontainer.spawn('npm', ['run', 'build']);
|
const proc2 = await webcontainer.spawn('npm', ['run', 'build']);
|
||||||
|
proc2.output.pipeTo(new WritableStream({
|
||||||
|
write(data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
}));
|
||||||
await proc2.exit;
|
await proc2.exit;
|
||||||
|
|
||||||
// Copy "dist" out of the webcontainer back to the project directory
|
const proc3 = await webcontainer.spawn('npx', ["-y", "nostr-deploy-cli", "deploy", "--skip-setup"]);
|
||||||
const copyDist = async () => {
|
proc3.output.pipeTo(new WritableStream({
|
||||||
try {
|
write(data) {
|
||||||
// Read the dist directory from webcontainer
|
console.log(data);
|
||||||
const distContents = await webcontainer.fs.readdir('dist', { withFileTypes: true });
|
|
||||||
|
|
||||||
// Create dist directory in project if it doesn't exist
|
|
||||||
const distPath = `/projects/${projectId}/dist`;
|
|
||||||
try {
|
|
||||||
await fsManager.fs.promises.mkdir(distPath);
|
|
||||||
} catch {
|
|
||||||
// Directory might already exist, that's fine
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to copy directory recursively
|
|
||||||
const copyDirectory = async (sourcePath: string, destPath: string) => {
|
|
||||||
try {
|
|
||||||
console.log(`Copying directory: ${sourcePath}`);
|
|
||||||
const items = await webcontainer.fs.readdir(sourcePath, { withFileTypes: true });
|
|
||||||
console.log(`Found ${items.length} items in ${sourcePath}`);
|
|
||||||
|
|
||||||
for (const item of items) {
|
|
||||||
const sourceItemPath = `${sourcePath}/${item.name}`;
|
|
||||||
const destItemPath = `${destPath}/${item.name}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (item.isDirectory()) {
|
|
||||||
console.log(`Creating directory: ${destItemPath}`);
|
|
||||||
try {
|
|
||||||
await fsManager.fs.promises.mkdir(destItemPath);
|
|
||||||
} catch {
|
|
||||||
// Directory might already exist
|
|
||||||
}
|
|
||||||
await copyDirectory(sourceItemPath, destItemPath);
|
|
||||||
} else {
|
|
||||||
console.log(`Copying file: ${sourceItemPath} -> ${destItemPath}`);
|
|
||||||
const content = await webcontainer.fs.readFile(sourceItemPath);
|
|
||||||
await fsManager.fs.promises.writeFile(destItemPath, content);
|
|
||||||
}
|
|
||||||
} catch (itemError) {
|
|
||||||
console.warn(`Failed to copy item ${item.name}:`, itemError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.warn(`Failed to copy ${sourcePath}:`, error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Copy each package in dist
|
|
||||||
for (const item of distContents) {
|
|
||||||
const sourcePath = `dist/${item.name}`;
|
|
||||||
const destPath = `${distPath}/${item.name}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (item.isDirectory()) {
|
|
||||||
console.log(`Processing directory: ${item.name}`);
|
|
||||||
try {
|
|
||||||
await fsManager.fs.promises.mkdir(destPath);
|
|
||||||
} catch {
|
|
||||||
// Directory might already exist
|
|
||||||
}
|
|
||||||
await copyDirectory(sourcePath, destPath);
|
|
||||||
} else {
|
|
||||||
console.log(`Processing file: ${item.name}`);
|
|
||||||
const content = await webcontainer.fs.readFile(sourcePath);
|
|
||||||
await fsManager.fs.promises.writeFile(destPath, content);
|
|
||||||
}
|
|
||||||
} catch (itemError) {
|
|
||||||
console.warn(`Failed to process ${item.name}:`, itemError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Successfully copied node_modules from webcontainer');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to copy node_modules:', error);
|
|
||||||
}
|
}
|
||||||
};
|
}));
|
||||||
|
await proc3.exit;
|
||||||
|
|
||||||
await copyDist();
|
console.log('Project deployed');
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, useCallback } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { fsManager } from '@/lib/fs';
|
import { fsManager } from '@/lib/fs';
|
||||||
import { Tabs, TabsContent } from '@/components/ui/tabs';
|
import { Tabs, TabsContent } from '@/components/ui/tabs';
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
@@ -7,6 +7,7 @@ import { RefreshCw } from 'lucide-react';
|
|||||||
|
|
||||||
import { FileTree } from './FileTree';
|
import { FileTree } from './FileTree';
|
||||||
import { FileEditor } from './FileEditor';
|
import { FileEditor } from './FileEditor';
|
||||||
|
import { getPublicKey, nip19 } from 'nostr-tools';
|
||||||
|
|
||||||
interface PreviewPaneProps {
|
interface PreviewPaneProps {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
@@ -16,88 +17,22 @@ interface PreviewPaneProps {
|
|||||||
export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) {
|
export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) {
|
||||||
const [selectedFile, setSelectedFile] = useState<string | null>(null);
|
const [selectedFile, setSelectedFile] = useState<string | null>(null);
|
||||||
const [fileContent, setFileContent] = useState<string>('');
|
const [fileContent, setFileContent] = useState<string>('');
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [projectUrl, setProjectUrl] = useState('');
|
||||||
const [hasBuiltProject, setHasBuiltProject] = useState(false);
|
|
||||||
const [previewHtml, setPreviewHtml] = useState<string>('');
|
|
||||||
|
|
||||||
const loadFileContent = useCallback(async (filePath: string) => {
|
|
||||||
setIsLoading(true);
|
|
||||||
try {
|
|
||||||
const content = await fsManager.readFile(projectId, filePath);
|
|
||||||
setFileContent(content);
|
|
||||||
} catch (_error) {
|
|
||||||
console.error('Failed to load file:', _error);
|
|
||||||
setFileContent('');
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
}, [projectId]);
|
|
||||||
|
|
||||||
const checkForBuiltProject = useCallback(async () => {
|
|
||||||
try {
|
|
||||||
const exists = await fsManager.fileExists(projectId, 'dist/index.html');
|
|
||||||
setHasBuiltProject(exists);
|
|
||||||
|
|
||||||
if (exists) {
|
|
||||||
// Load the built HTML content
|
|
||||||
const htmlContent = await fsManager.readFile(projectId, 'dist/index.html');
|
|
||||||
|
|
||||||
// Process the HTML to add base tag for asset resolution
|
|
||||||
const processedHtml = processHtmlForPreview(htmlContent, projectId);
|
|
||||||
setPreviewHtml(processedHtml);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to check for built project:', error);
|
|
||||||
setHasBuiltProject(false);
|
|
||||||
}
|
|
||||||
}, [projectId]);
|
|
||||||
|
|
||||||
const processHtmlForPreview = (html: string, projectId: string): string => {
|
|
||||||
try {
|
|
||||||
// Create a temporary DOM to process the HTML
|
|
||||||
const parser = new DOMParser();
|
|
||||||
const doc = parser.parseFromString(html, 'text/html');
|
|
||||||
|
|
||||||
// Rewrite script src attributes
|
|
||||||
const scripts = doc.querySelectorAll('script[src]');
|
|
||||||
scripts.forEach((script) => {
|
|
||||||
const src = script.getAttribute('src');
|
|
||||||
if (src && !src.startsWith('http') && !src.startsWith('//')) {
|
|
||||||
// Convert relative path to raw file path
|
|
||||||
const cleanPath = src.startsWith('./') ? src.slice(2) : src.startsWith('/') ? src.slice(1) : src;
|
|
||||||
const newSrc = `/project/${projectId}/files/dist/${cleanPath}`;
|
|
||||||
script.setAttribute('src', newSrc);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Rewrite link href attributes (for stylesheets and other resources)
|
|
||||||
const links = doc.querySelectorAll('link[href]');
|
|
||||||
links.forEach((link) => {
|
|
||||||
const href = link.getAttribute('href');
|
|
||||||
if (href && !href.startsWith('http') && !href.startsWith('//')) {
|
|
||||||
// Convert relative path to raw file path
|
|
||||||
const cleanPath = href.startsWith('./') ? href.slice(2) : href.startsWith('/') ? href.slice(1) : href;
|
|
||||||
const newHref = `/project/${projectId}/files/dist/${cleanPath}`;
|
|
||||||
link.setAttribute('href', newHref);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return doc.documentElement.outerHTML;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to process HTML for preview:', error);
|
|
||||||
return html; // Return original HTML if processing fails
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedFile) {
|
(async () => {
|
||||||
loadFileContent(selectedFile);
|
const project = await fsManager.getProject(projectId);
|
||||||
}
|
if (!project) return;
|
||||||
}, [selectedFile, loadFileContent]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const decoded = nip19.decode(project.nsec);
|
||||||
checkForBuiltProject();
|
if (decoded.type !== 'nsec') return;
|
||||||
}, [checkForBuiltProject]);
|
|
||||||
|
const pubkey = getPublicKey(decoded.data);
|
||||||
|
const npub = nip19.npubEncode(pubkey);
|
||||||
|
|
||||||
|
setProjectUrl(`https://${npub}.nostrdeploy.com/`);
|
||||||
|
})();
|
||||||
|
}, [projectId]);
|
||||||
|
|
||||||
const handleFileSelect = (filePath: string) => {
|
const handleFileSelect = (filePath: string) => {
|
||||||
setSelectedFile(filePath);
|
setSelectedFile(filePath);
|
||||||
@@ -118,21 +53,21 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) {
|
|||||||
<div className="h-full">
|
<div className="h-full">
|
||||||
<Tabs value={activeTab} className="h-full">
|
<Tabs value={activeTab} className="h-full">
|
||||||
<TabsContent value="preview" className="h-full mt-0">
|
<TabsContent value="preview" className="h-full mt-0">
|
||||||
{hasBuiltProject ? (
|
{projectUrl ? (
|
||||||
<div className="h-full w-full flex flex-col">
|
<div className="h-full w-full flex flex-col">
|
||||||
<div className="flex items-center justify-between p-2 border-b bg-background">
|
<div className="flex items-center justify-between p-2 border-b bg-background">
|
||||||
<span className="text-sm text-muted-foreground">Project Preview</span>
|
<span className="text-sm text-muted-foreground">Project Preview</span>
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={checkForBuiltProject}
|
onClick={() => {}}
|
||||||
className="h-8 w-8 p-0"
|
className="h-8 w-8 p-0"
|
||||||
>
|
>
|
||||||
<RefreshCw className="h-4 w-4" />
|
<RefreshCw className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<iframe
|
<iframe
|
||||||
srcDoc={previewHtml}
|
src={projectUrl}
|
||||||
className="w-full flex-1 border-0"
|
className="w-full flex-1 border-0"
|
||||||
title="Project Preview"
|
title="Project Preview"
|
||||||
/>
|
/>
|
||||||
@@ -151,7 +86,7 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) {
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={checkForBuiltProject}
|
onClick={() => {}}
|
||||||
className="gap-2"
|
className="gap-2"
|
||||||
>
|
>
|
||||||
<RefreshCw className="h-4 w-4" />
|
<RefreshCw className="h-4 w-4" />
|
||||||
@@ -184,7 +119,7 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) {
|
|||||||
filePath={selectedFile}
|
filePath={selectedFile}
|
||||||
content={fileContent}
|
content={fileContent}
|
||||||
onSave={handleFileSave}
|
onSave={handleFileSave}
|
||||||
isLoading={isLoading}
|
isLoading={false} // Replace with actual loading state if needed
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="h-full flex items-center justify-center">
|
<div className="h-full flex items-center justify-center">
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import LightningFS from '@isomorphic-git/lightning-fs';
|
|||||||
import git from 'isomorphic-git';
|
import git from 'isomorphic-git';
|
||||||
import http from 'isomorphic-git/http/web';
|
import http from 'isomorphic-git/http/web';
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
|
import { generateSecretKey, nip19 } from 'nostr-tools';
|
||||||
|
|
||||||
// Polyfill Buffer for browser
|
// Polyfill Buffer for browser
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
@@ -15,6 +16,7 @@ export interface Project {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
path: string;
|
path: string;
|
||||||
|
nsec: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
lastModified: Date;
|
lastModified: Date;
|
||||||
}
|
}
|
||||||
@@ -46,6 +48,7 @@ export class FileSystemManager {
|
|||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
path: projectPath,
|
path: projectPath,
|
||||||
|
nsec: nip19.nsecEncode(generateSecretKey()),
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
lastModified: new Date(),
|
lastModified: new Date(),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user