mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add Deno Deploy adapter
This commit is contained in:
9 files changed
+716
-14
No files matched your search
@@ -27,14 +27,15 @@ import { useFS } from '@/hooks/useFS';
|
||||
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { useNostr } from '@nostrify/react';
|
||||
import { ShakespeareAdapter, NetlifyAdapter, VercelAdapter, NsiteAdapter, CloudflareAdapter, DeployAdapter } from '@/lib/deploy';
|
||||
import { ShakespeareAdapter, NetlifyAdapter, VercelAdapter, NsiteAdapter, CloudflareAdapter, DenoDeployAdapter, DeployAdapter } from '@/lib/deploy';
|
||||
import { Link } from 'react-router-dom';
|
||||
import type { DeployProvider, ShakespeareDeployProvider, NetlifyProvider, VercelProvider, CloudflareProvider } from '@/contexts/DeploySettingsContext';
|
||||
import type { DeployProvider, ShakespeareDeployProvider, NetlifyProvider, VercelProvider, CloudflareProvider, DenoDeployProvider } from '@/contexts/DeploySettingsContext';
|
||||
import { ShakespeareDeployForm } from '@/components/deploy/ShakespeareDeployForm';
|
||||
import { NetlifyDeployForm } from '@/components/deploy/NetlifyDeployForm';
|
||||
import { VercelDeployForm } from '@/components/deploy/VercelDeployForm';
|
||||
import { NsiteDeployForm } from '@/components/deploy/NsiteDeployForm';
|
||||
import { CloudflareDeployForm } from '@/components/deploy/CloudflareDeployForm';
|
||||
import { DenoDeployForm } from '@/components/deploy/DenoDeployForm';
|
||||
|
||||
/**
|
||||
* Helper function to get provider URL for favicon
|
||||
@@ -65,6 +66,12 @@ function getProviderUrl(provider: DeployProvider): string | null {
|
||||
}
|
||||
return 'https://cloudflare.com';
|
||||
|
||||
case 'deno':
|
||||
if (provider.baseURL) {
|
||||
return provider.baseURL;
|
||||
}
|
||||
return 'https://deno.com';
|
||||
|
||||
case 'nsite':
|
||||
return null;
|
||||
|
||||
@@ -121,6 +128,10 @@ interface CloudflareFormData {
|
||||
projectName: string;
|
||||
}
|
||||
|
||||
interface DenoDeployFormData {
|
||||
projectName: string;
|
||||
}
|
||||
|
||||
export function DeployDialog({ projectId, projectName, open, onOpenChange }: DeployDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const { settings } = useDeploySettings();
|
||||
@@ -155,6 +166,9 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
const [cloudflareForm, setCloudflareForm] = useState<CloudflareFormData>({
|
||||
projectName: projectName || projectId,
|
||||
});
|
||||
const [denoDeployForm, setDenoDeployForm] = useState<DenoDeployFormData>({
|
||||
projectName: projectName || projectId,
|
||||
});
|
||||
|
||||
// Load project settings when dialog opens
|
||||
useEffect(() => {
|
||||
@@ -261,6 +275,23 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
projectName: cloudflareForm.projectName || undefined,
|
||||
corsProxy: cloudflareProvider.proxy ? config.corsProxy : undefined,
|
||||
});
|
||||
} else if (selectedProvider.type === 'deno') {
|
||||
const denoProvider = selectedProvider as DenoDeployProvider;
|
||||
if (!denoProvider.apiKey) {
|
||||
throw new Error('Deno Deploy access token is required');
|
||||
}
|
||||
if (!denoProvider.organizationId) {
|
||||
throw new Error('Deno Deploy organization ID is required');
|
||||
}
|
||||
|
||||
adapter = new DenoDeployAdapter({
|
||||
fs,
|
||||
apiKey: denoProvider.apiKey,
|
||||
organizationId: denoProvider.organizationId,
|
||||
baseURL: denoProvider.baseURL,
|
||||
projectName: denoDeployForm.projectName || undefined,
|
||||
corsProxy: denoProvider.proxy ? config.corsProxy : undefined,
|
||||
});
|
||||
} else {
|
||||
throw new Error('Unknown provider type');
|
||||
}
|
||||
@@ -307,6 +338,13 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
projectName: cloudflareForm.projectName || undefined,
|
||||
},
|
||||
});
|
||||
} else if (selectedProvider.type === 'deno') {
|
||||
await updateProjectSettings(selectedProviderId, {
|
||||
type: 'deno',
|
||||
data: {
|
||||
projectName: denoDeployForm.projectName || undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
setDeployResult(result);
|
||||
@@ -327,6 +365,7 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
setNetlifyForm({ siteId: '', siteName: '' });
|
||||
setVercelForm({ projectName: projectName || projectId, teamId: '' });
|
||||
setCloudflareForm({ projectName: projectName || projectId });
|
||||
setDenoDeployForm({ projectName: projectName || projectId });
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
@@ -354,6 +393,10 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
setCloudflareForm({ projectName });
|
||||
}, []);
|
||||
|
||||
const handleDenoDeployProjectChange = useCallback((projectName: string) => {
|
||||
setDenoDeployForm({ projectName });
|
||||
}, []);
|
||||
|
||||
const renderProviderFields = () => {
|
||||
if (!selectedProvider) return null;
|
||||
|
||||
@@ -435,6 +478,25 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
);
|
||||
}
|
||||
|
||||
if (selectedProvider.type === 'deno') {
|
||||
const denoProvider = selectedProvider as DenoDeployProvider;
|
||||
const savedConfig = projectSettings.providers[selectedProviderId];
|
||||
const savedProjectName = savedConfig?.type === 'deno' ? savedConfig.data.projectName : undefined;
|
||||
|
||||
return (
|
||||
<DenoDeployForm
|
||||
apiKey={denoProvider.apiKey}
|
||||
organizationId={denoProvider.organizationId}
|
||||
baseURL={denoProvider.baseURL}
|
||||
projectId={projectId}
|
||||
projectName={projectName}
|
||||
savedProjectName={savedProjectName}
|
||||
onProjectChange={handleDenoDeployProjectChange}
|
||||
corsProxy={denoProvider.proxy ? config.corsProxy : undefined}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -566,7 +628,8 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
(selectedProvider.type === 'shakespeare' && !isShakespeareFormValid) ||
|
||||
(selectedProvider.type === 'nsite' && !nsiteForm.nsec) ||
|
||||
(selectedProvider.type === 'netlify' && !netlifyForm.siteId && !netlifyForm.siteName) ||
|
||||
(selectedProvider.type === 'cloudflare' && !cloudflareForm.projectName)
|
||||
(selectedProvider.type === 'cloudflare' && !cloudflareForm.projectName) ||
|
||||
(selectedProvider.type === 'deno' && !denoDeployForm.projectName)
|
||||
}
|
||||
>
|
||||
{isDeploying ? (
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { Plus, ExternalLink } from 'lucide-react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { proxyUrl } from '@/lib/proxyUrl';
|
||||
|
||||
interface DenoProject {
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
interface DenoDeployFormProps {
|
||||
apiKey: string;
|
||||
organizationId: string;
|
||||
baseURL?: string;
|
||||
projectId: string;
|
||||
projectName?: string;
|
||||
savedProjectName?: string;
|
||||
onProjectChange: (projectName: string) => void;
|
||||
corsProxy?: string;
|
||||
}
|
||||
|
||||
export function DenoDeployForm({
|
||||
apiKey,
|
||||
organizationId,
|
||||
baseURL = 'https://api.deno.com/v1',
|
||||
projectId,
|
||||
projectName,
|
||||
savedProjectName,
|
||||
onProjectChange,
|
||||
corsProxy,
|
||||
}: DenoDeployFormProps) {
|
||||
const [projects, setProjects] = useState<DenoProject[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [selectedProjectName, setSelectedProjectName] = useState<string>('');
|
||||
const [newProjectName, setNewProjectName] = useState(projectName || projectId);
|
||||
|
||||
const fetchProjects = useCallback(async () => {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const url = `${baseURL}/organizations/${organizationId}/projects?limit=100`;
|
||||
const targetUrl = corsProxy ? proxyUrl(corsProxy, url) : url;
|
||||
|
||||
const response = await fetch(targetUrl, {
|
||||
headers: { 'Authorization': `Bearer ${apiKey}` },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch projects: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data: DenoProject[] = await response.json();
|
||||
setProjects(data);
|
||||
|
||||
// If there's a saved project name and it exists in the list, select it
|
||||
// Otherwise leave it empty (showing placeholder)
|
||||
if (savedProjectName && data.some((p: DenoProject) => p.name === savedProjectName)) {
|
||||
setSelectedProjectName(savedProjectName);
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to fetch projects');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [apiKey, organizationId, baseURL, savedProjectName, corsProxy]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchProjects();
|
||||
}, [fetchProjects]);
|
||||
|
||||
// Update newProjectName when switching to "new" if it's empty
|
||||
useEffect(() => {
|
||||
if (selectedProjectName === 'new' && !newProjectName) {
|
||||
setNewProjectName(projectName || projectId);
|
||||
}
|
||||
}, [selectedProjectName, newProjectName, projectName, projectId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedProjectName === '') {
|
||||
// No selection yet - don't call onProjectChange
|
||||
return;
|
||||
} else if (selectedProjectName === 'new') {
|
||||
onProjectChange(newProjectName);
|
||||
} else {
|
||||
onProjectChange(selectedProjectName);
|
||||
}
|
||||
}, [selectedProjectName, newProjectName, onProjectChange]);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Project</Label>
|
||||
<Skeleton className="h-10 w-full" />
|
||||
</div>
|
||||
<Skeleton className="h-4 w-3/4" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const selectedProject = projects.find(p => p.name === selectedProjectName);
|
||||
|
||||
// Construct the URL preview
|
||||
const getProjectUrl = (name: string) => {
|
||||
return `https://${name}.deno.dev`;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{error && (
|
||||
<Alert variant="destructive">
|
||||
<AlertDescription>{error}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="deno-project">Select Project</Label>
|
||||
<Select value={selectedProjectName} onValueChange={setSelectedProjectName}>
|
||||
<SelectTrigger id="deno-project">
|
||||
<SelectValue placeholder="Select a project or create new..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="new">
|
||||
<div className="flex items-center gap-2">
|
||||
<Plus className="h-4 w-4" />
|
||||
Create new project
|
||||
</div>
|
||||
</SelectItem>
|
||||
{projects.map((project) => (
|
||||
<SelectItem key={project.id} value={project.name}>
|
||||
{project.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{selectedProjectName === 'new' ? (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="new-project-name">New Project Name</Label>
|
||||
<Input
|
||||
id="new-project-name"
|
||||
value={newProjectName}
|
||||
onChange={(e) => setNewProjectName(e.target.value)}
|
||||
placeholder={projectName || projectId}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
URL: <span className="font-mono">{getProjectUrl(newProjectName || projectId)}</span>
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
A new project will be created when you deploy
|
||||
</p>
|
||||
</div>
|
||||
) : selectedProject ? (
|
||||
<div className="space-y-2">
|
||||
<div className="rounded-lg border p-3 space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm font-medium">{selectedProject.name}</p>
|
||||
<p className="text-xs text-muted-foreground font-mono">
|
||||
{getProjectUrl(selectedProject.name)}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => window.open(`https://dash.deno.com/projects/${selectedProject.name}`, '_blank')}
|
||||
>
|
||||
<ExternalLink className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Deployment will create a new version for this project
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,3 +3,4 @@ export { NetlifyDeployForm } from './NetlifyDeployForm';
|
||||
export { VercelDeployForm } from './VercelDeployForm';
|
||||
export { NsiteDeployForm } from './NsiteDeployForm';
|
||||
export { CloudflareDeployForm } from './CloudflareDeployForm';
|
||||
export { DenoDeployForm } from './DenoDeployForm';
|
||||
@@ -40,7 +40,15 @@ export interface CloudflareProvider extends BaseDeployProvider {
|
||||
proxy?: boolean;
|
||||
}
|
||||
|
||||
export type DeployProvider = ShakespeareDeployProvider | NetlifyProvider | VercelProvider | NsiteProvider | CloudflareProvider;
|
||||
export interface DenoDeployProvider extends BaseDeployProvider {
|
||||
type: 'deno';
|
||||
apiKey: string;
|
||||
organizationId: string;
|
||||
baseURL?: string;
|
||||
proxy?: boolean;
|
||||
}
|
||||
|
||||
export type DeployProvider = ShakespeareDeployProvider | NetlifyProvider | VercelProvider | NsiteProvider | CloudflareProvider | DenoDeployProvider;
|
||||
|
||||
export interface DeploySettings {
|
||||
providers: DeployProvider[];
|
||||
|
||||
@@ -38,7 +38,14 @@ export interface CloudflareProjectConfig {
|
||||
};
|
||||
}
|
||||
|
||||
export type ProjectProviderConfig = ShakespeareProjectConfig | NsiteProjectConfig | NetlifyProjectConfig | VercelProjectConfig | CloudflareProjectConfig;
|
||||
export interface DenoDeployProjectConfig {
|
||||
type: 'deno';
|
||||
data: {
|
||||
projectName?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type ProjectProviderConfig = ShakespeareProjectConfig | NsiteProjectConfig | NetlifyProjectConfig | VercelProjectConfig | CloudflareProjectConfig | DenoDeployProjectConfig;
|
||||
|
||||
export interface ProjectDeploySettings {
|
||||
providers: Record<string, ProjectProviderConfig>;
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
import type { JSRuntimeFS } from '../JSRuntime';
|
||||
import type { DeployAdapter, DeployOptions, DeployResult, DenoDeployConfig } from './types';
|
||||
import { proxyUrl } from '../proxyUrl';
|
||||
|
||||
interface Project {
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
interface Deployment {
|
||||
id: string;
|
||||
projectId: string;
|
||||
status: string;
|
||||
domains: string[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deno Deploy Adapter
|
||||
* Uses Deno Deploy API to deploy static sites
|
||||
*
|
||||
* Implements the Deno Deploy workflow:
|
||||
* 1. Create or find existing project
|
||||
* 2. Build asset manifest with file contents
|
||||
* 3. Create deployment with assets
|
||||
* 4. Attach domain to deployment
|
||||
*/
|
||||
export class DenoDeployAdapter implements DeployAdapter {
|
||||
private fs: JSRuntimeFS;
|
||||
private apiKey: string;
|
||||
private organizationId: string;
|
||||
private baseURL: string;
|
||||
private projectName?: string;
|
||||
private corsProxy?: string;
|
||||
|
||||
constructor(config: DenoDeployConfig) {
|
||||
this.fs = config.fs;
|
||||
this.apiKey = config.apiKey;
|
||||
this.organizationId = config.organizationId;
|
||||
this.baseURL = config.baseURL || 'https://api.deno.com/v1';
|
||||
this.projectName = config.projectName;
|
||||
this.corsProxy = config.corsProxy;
|
||||
}
|
||||
|
||||
async deploy(options: DeployOptions): Promise<DeployResult> {
|
||||
const { projectId, projectPath } = options;
|
||||
|
||||
// Check if dist directory exists and contains index.html
|
||||
const distPath = `${projectPath}/dist`;
|
||||
try {
|
||||
await this.fs.readFile(`${distPath}/index.html`, 'utf8');
|
||||
} catch {
|
||||
throw new Error('No index.html found in dist directory. Please build the project first.');
|
||||
}
|
||||
|
||||
const projectName = this.projectName || projectId;
|
||||
|
||||
// Step 1: Get or create project
|
||||
const project = await this.getOrCreateProject(projectName);
|
||||
|
||||
// Step 2: Collect all files and build assets
|
||||
const assets: Record<string, { kind: string; content: string; encoding: string }> = {};
|
||||
await this.collectFiles(distPath, '', assets);
|
||||
|
||||
// Step 3: Create deployment with assets
|
||||
const deployment = await this.createDeployment(project.id, assets);
|
||||
|
||||
// Step 4: Attach the deno.dev domain to the deployment
|
||||
const domain = `${project.name}.deno.dev`;
|
||||
await this.attachDomain(deployment.id, `{project.name}.deno.dev`);
|
||||
|
||||
return {
|
||||
url: `https://${domain}`,
|
||||
metadata: {
|
||||
deploymentId: deployment.id,
|
||||
projectId: project.id,
|
||||
projectName: project.name,
|
||||
provider: 'deno-deploy',
|
||||
status: deployment.status,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private async getOrCreateProject(projectName: string): Promise<Project> {
|
||||
// First, try to find existing project
|
||||
const existingProject = await this.findProject(projectName);
|
||||
if (existingProject) {
|
||||
return existingProject;
|
||||
}
|
||||
|
||||
// Create new project
|
||||
return this.createProject(projectName);
|
||||
}
|
||||
|
||||
private async findProject(projectName: string): Promise<Project | null> {
|
||||
const url = `${this.baseURL}/organizations/${this.organizationId}/projects?q=${encodeURIComponent(projectName)}`;
|
||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
||||
|
||||
const response = await fetch(targetUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.apiKey}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
// If we can't list projects, just return null and try to create
|
||||
return null;
|
||||
}
|
||||
|
||||
const projects: Project[] = await response.json();
|
||||
return projects.find(p => p.name === projectName) || null;
|
||||
}
|
||||
|
||||
private async createProject(projectName: string): Promise<Project> {
|
||||
const url = `${this.baseURL}/organizations/${this.organizationId}/projects`;
|
||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
||||
|
||||
const response = await fetch(targetUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: projectName,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text().catch(() => 'Unknown error');
|
||||
throw new Error(`Failed to create project: ${response.status} ${response.statusText}. ${errorText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
private async createDeployment(
|
||||
projectId: string,
|
||||
assets: Record<string, { kind: string; content: string; encoding: string }>
|
||||
): Promise<Deployment> {
|
||||
const url = `${this.baseURL}/projects/${projectId}/deployments`;
|
||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
||||
|
||||
// Create a minimal server script that serves static files
|
||||
// For static sites, we use a simple file server entry point
|
||||
const entryPointUrl = 'file:///src/main.ts';
|
||||
|
||||
// Add the entry point script that serves static files
|
||||
const serverScript = `
|
||||
import { serveDir } from "https://deno.land/[email protected]/http/file_server.ts";
|
||||
|
||||
Deno.serve((req) => {
|
||||
return serveDir(req, {
|
||||
fsRoot: ".",
|
||||
showIndex: true,
|
||||
enableCors: true,
|
||||
});
|
||||
});
|
||||
`;
|
||||
|
||||
// Add the server script to assets
|
||||
assets['src/main.ts'] = {
|
||||
kind: 'file',
|
||||
content: serverScript,
|
||||
encoding: 'utf-8',
|
||||
};
|
||||
|
||||
const response = await fetch(targetUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
entryPointUrl,
|
||||
assets,
|
||||
importMapUrl: null,
|
||||
lockFileUrl: null,
|
||||
compilerOptions: null,
|
||||
envVars: {},
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text().catch(() => 'Unknown error');
|
||||
throw new Error(`Failed to create deployment: ${response.status} ${response.statusText}. ${errorText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
private async attachDomain(deploymentId: string, domain: string): Promise<void> {
|
||||
const url = `${this.baseURL}/deployments/${deploymentId}/domains/${encodeURIComponent(domain)}`;
|
||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
||||
|
||||
const response = await fetch(targetUrl, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text().catch(() => 'Unknown error');
|
||||
// Don't throw on domain attachment failure - deployment still succeeded
|
||||
console.warn(`Failed to attach domain: ${response.status} ${response.statusText}. ${errorText}`);
|
||||
}
|
||||
}
|
||||
|
||||
private async collectFiles(
|
||||
dirPath: string,
|
||||
relativePath: string,
|
||||
assets: Record<string, { kind: string; content: string; encoding: string }>
|
||||
): Promise<void> {
|
||||
try {
|
||||
const entries = await this.fs.readdir(dirPath, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = `${dirPath}/${entry.name}`;
|
||||
const entryRelativePath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
await this.collectFiles(fullPath, entryRelativePath, assets);
|
||||
} else if (entry.isFile()) {
|
||||
try {
|
||||
const fileContent = await this.fs.readFile(fullPath);
|
||||
|
||||
// Determine if file is text or binary based on extension
|
||||
const isText = this.isTextFile(entry.name);
|
||||
|
||||
let content: string;
|
||||
let encoding: 'utf-8' | 'base64';
|
||||
|
||||
if (isText) {
|
||||
if (typeof fileContent === 'string') {
|
||||
content = fileContent;
|
||||
} else {
|
||||
content = new TextDecoder().decode(fileContent);
|
||||
}
|
||||
encoding = 'utf-8';
|
||||
} else {
|
||||
// Binary file - encode as base64
|
||||
let bytes: Uint8Array;
|
||||
if (typeof fileContent === 'string') {
|
||||
bytes = new TextEncoder().encode(fileContent);
|
||||
} else {
|
||||
bytes = fileContent;
|
||||
}
|
||||
content = this.uint8ArrayToBase64(bytes);
|
||||
encoding = 'base64';
|
||||
}
|
||||
|
||||
assets[entryRelativePath] = {
|
||||
kind: 'file',
|
||||
content,
|
||||
encoding,
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn(`Failed to read file ${fullPath}:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`Failed to read directory ${dirPath}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
private isTextFile(filename: string): boolean {
|
||||
const textExtensions = [
|
||||
'html', 'htm', 'css', 'js', 'mjs', 'cjs', 'ts', 'tsx', 'jsx',
|
||||
'json', 'xml', 'svg', 'txt', 'md', 'yaml', 'yml', 'toml',
|
||||
'sh', 'bash', 'zsh', 'fish', 'bat', 'cmd', 'ps1',
|
||||
'py', 'rb', 'php', 'java', 'c', 'cpp', 'h', 'hpp',
|
||||
'rs', 'go', 'swift', 'kt', 'scala', 'clj', 'ex', 'exs',
|
||||
'vue', 'svelte', 'astro', 'njk', 'ejs', 'pug', 'hbs',
|
||||
'graphql', 'gql', 'sql', 'csv', 'tsv', 'log', 'ini', 'cfg',
|
||||
'env', 'gitignore', 'dockerignore', 'editorconfig',
|
||||
'prettierrc', 'eslintrc', 'babelrc', 'npmrc',
|
||||
'map', // source maps
|
||||
];
|
||||
|
||||
const ext = filename.split('.').pop()?.toLowerCase() || '';
|
||||
// Also check if filename itself is a known text file
|
||||
const textFilenames = [
|
||||
'dockerfile', 'makefile', 'gemfile', 'rakefile', 'procfile',
|
||||
'license', 'readme', 'changelog', 'authors', 'contributors',
|
||||
];
|
||||
|
||||
return textExtensions.includes(ext) || textFilenames.includes(filename.toLowerCase());
|
||||
}
|
||||
|
||||
private uint8ArrayToBase64(bytes: Uint8Array): string {
|
||||
let binary = '';
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
binary += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return btoa(binary);
|
||||
}
|
||||
}
|
||||
@@ -4,3 +4,4 @@ export * from './NetlifyAdapter';
|
||||
export * from './VercelAdapter';
|
||||
export * from './NsiteAdapter';
|
||||
export * from './CloudflareAdapter';
|
||||
export * from './DenoDeployAdapter';
|
||||
@@ -63,3 +63,12 @@ export interface CloudflareDeployConfig {
|
||||
projectName?: string;
|
||||
corsProxy?: string;
|
||||
}
|
||||
|
||||
export interface DenoDeployConfig {
|
||||
fs: JSRuntimeFS;
|
||||
apiKey: string;
|
||||
organizationId: string;
|
||||
baseURL?: string;
|
||||
projectName?: string;
|
||||
corsProxy?: string;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ import { normalizeUrl } from '@/lib/faviconUrl';
|
||||
|
||||
interface PresetProvider {
|
||||
id: string;
|
||||
type: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare';
|
||||
type: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno';
|
||||
name: string;
|
||||
description: string;
|
||||
requiresNostr?: boolean;
|
||||
@@ -54,6 +54,8 @@ interface PresetProvider {
|
||||
apiKeyURL?: string;
|
||||
accountIdLabel?: string;
|
||||
accountIdURL?: string;
|
||||
organizationIdLabel?: string;
|
||||
organizationIdURL?: string;
|
||||
proxy?: boolean;
|
||||
}
|
||||
|
||||
@@ -202,6 +204,19 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{provider.type === 'deno' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`provider-${index}-organizationId`}>
|
||||
{preset?.organizationIdLabel || 'Organization ID'} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id={`provider-${index}-organizationId`}
|
||||
placeholder="Enter Organization ID"
|
||||
value={provider.organizationId}
|
||||
onChange={(e) => onUpdate(index, { ...provider, organizationId: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`provider-${index}-apiKey`}>
|
||||
{preset?.apiKeyLabel || t('apiKey')} <span className="text-destructive">*</span>
|
||||
@@ -217,6 +232,8 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
||||
onUpdate(index, { ...provider, apiKey: e.target.value });
|
||||
} else if (provider.type === 'cloudflare') {
|
||||
onUpdate(index, { ...provider, apiKey: e.target.value });
|
||||
} else if (provider.type === 'deno') {
|
||||
onUpdate(index, { ...provider, apiKey: e.target.value });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
@@ -231,7 +248,8 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
||||
provider.type === 'netlify' ? 'https://api.netlify.com/api/v1' :
|
||||
provider.type === 'vercel' ? 'https://api.vercel.com' :
|
||||
provider.type === 'cloudflare' ? 'https://api.cloudflare.com/client/v4' :
|
||||
'Base URL'
|
||||
provider.type === 'deno' ? 'https://api.deno.com/v1' :
|
||||
'Base URL'
|
||||
}
|
||||
value={provider.baseURL || ''}
|
||||
onChange={(e) => {
|
||||
@@ -241,6 +259,8 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
||||
onUpdate(index, { ...provider, baseURL: e.target.value });
|
||||
} else if (provider.type === 'cloudflare') {
|
||||
onUpdate(index, { ...provider, baseURL: e.target.value });
|
||||
} else if (provider.type === 'deno') {
|
||||
onUpdate(index, { ...provider, baseURL: e.target.value });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
@@ -317,6 +337,17 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
accountIdURL: 'https://developers.cloudflare.com/fundamentals/account/find-account-and-zone-ids/',
|
||||
proxy: true,
|
||||
},
|
||||
{
|
||||
id: 'deno',
|
||||
type: 'deno',
|
||||
name: 'Deno Deploy',
|
||||
description: 'Deploy to Deno Deploy',
|
||||
apiKeyLabel: 'Access Token',
|
||||
apiKeyURL: 'https://dash.deno.com/account#access-tokens',
|
||||
organizationIdLabel: 'Organization ID',
|
||||
organizationIdURL: 'https://dash.deno.com/orgs',
|
||||
proxy: true,
|
||||
},
|
||||
];
|
||||
|
||||
// Helper function to generate custom provider ID
|
||||
@@ -356,6 +387,13 @@ function getProviderUrl(provider: DeployProvider | PresetProvider): string | nul
|
||||
}
|
||||
return 'https://cloudflare.com';
|
||||
|
||||
case 'deno':
|
||||
// For Deno Deploy providers, check for custom baseURL first, then use default
|
||||
if ('baseURL' in provider && provider.baseURL) {
|
||||
return provider.baseURL;
|
||||
}
|
||||
return 'https://deno.com';
|
||||
|
||||
case 'nsite':
|
||||
// nsite uses Rocket icon fallback
|
||||
return null;
|
||||
@@ -380,10 +418,11 @@ export function DeploySettings() {
|
||||
const [forceManualEntry, setForceManualEntry] = useState<Record<string, boolean>>({});
|
||||
|
||||
// Custom provider form state
|
||||
const [customProviderType, setCustomProviderType] = useState<'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | ''>('');
|
||||
const [customProviderType, setCustomProviderType] = useState<'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno' | ''>('');
|
||||
const [customName, setCustomName] = useState('');
|
||||
const [customApiKey, setCustomApiKey] = useState('');
|
||||
const [customAccountId, setCustomAccountId] = useState('');
|
||||
const [customOrganizationId, setCustomOrganizationId] = useState('');
|
||||
const [customBaseURL, setCustomBaseURL] = useState('');
|
||||
const [customHost, setCustomHost] = useState('');
|
||||
const [customProxy, setCustomProxy] = useState(false);
|
||||
@@ -480,6 +519,19 @@ export function DeploySettings() {
|
||||
accountId: accountId.trim(),
|
||||
...(preset.proxy && { proxy: true }),
|
||||
};
|
||||
} else if (preset.type === 'deno') {
|
||||
const organizationId = presetApiKeys[`${preset.id}-organizationId`];
|
||||
if (!organizationId?.trim()) {
|
||||
return;
|
||||
}
|
||||
newProvider = {
|
||||
id: preset.id, // Use preset ID for presets
|
||||
name: preset.name,
|
||||
type: 'deno',
|
||||
apiKey: apiKey.trim(),
|
||||
organizationId: organizationId.trim(),
|
||||
...(preset.proxy && { proxy: true }),
|
||||
};
|
||||
} else {
|
||||
return; // Unknown type
|
||||
}
|
||||
@@ -551,6 +603,17 @@ export function DeploySettings() {
|
||||
...(customBaseURL?.trim() && { baseURL: customBaseURL.trim() }),
|
||||
...(customProxy && { proxy: true }),
|
||||
};
|
||||
} else if (customProviderType === 'deno') {
|
||||
if (!customApiKey.trim() || !customOrganizationId.trim()) return;
|
||||
newProvider = {
|
||||
id: generateCustomProviderId(customProviderType), // Generate custom ID
|
||||
name: customName.trim(),
|
||||
type: 'deno',
|
||||
apiKey: customApiKey.trim(),
|
||||
organizationId: customOrganizationId.trim(),
|
||||
...(customBaseURL?.trim() && { baseURL: customBaseURL.trim() }),
|
||||
...(customProxy && { proxy: true }),
|
||||
};
|
||||
} else {
|
||||
return; // Unknown type
|
||||
}
|
||||
@@ -562,6 +625,7 @@ export function DeploySettings() {
|
||||
setCustomName('');
|
||||
setCustomApiKey('');
|
||||
setCustomAccountId('');
|
||||
setCustomOrganizationId('');
|
||||
setCustomBaseURL('');
|
||||
setCustomHost('');
|
||||
setCustomProxy(false);
|
||||
@@ -794,6 +858,34 @@ export function DeploySettings() {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{preset.type === 'deno' && (
|
||||
<div className="relative">
|
||||
<Input
|
||||
placeholder={preset.organizationIdLabel || 'Organization ID'}
|
||||
value={presetApiKeys[`${preset.id}-organizationId`] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[`${preset.id}-organizationId`]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim() &&
|
||||
presetApiKeys[`${preset.id}-organizationId`]?.trim()) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{preset.organizationIdURL && !presetApiKeys[`${preset.id}-organizationId`] && (
|
||||
<button
|
||||
type="button"
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 inline-flex items-center gap-1 px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors rounded-md hover:bg-muted"
|
||||
onClick={() => window.open(preset.organizationIdURL, '_blank')}
|
||||
>
|
||||
Find ID
|
||||
<ExternalLink className="h-3 w-3" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="relative">
|
||||
<PasswordInput
|
||||
placeholder={preset.apiKeyLabel || t('enterApiKey')}
|
||||
@@ -804,7 +896,8 @@ export function DeploySettings() {
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim() &&
|
||||
(preset.type !== 'cloudflare' || presetApiKeys[`${preset.id}-accountId`]?.trim())) {
|
||||
(preset.type !== 'cloudflare' || presetApiKeys[`${preset.id}-accountId`]?.trim()) &&
|
||||
(preset.type !== 'deno' || presetApiKeys[`${preset.id}-organizationId`]?.trim())) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
@@ -828,7 +921,8 @@ export function DeploySettings() {
|
||||
disabled={
|
||||
(preset.requiresNostr && !isLoggedIntoNostr) ||
|
||||
(!preset.requiresNostr && preset.type !== 'nsite' && !presetApiKeys[preset.id]?.trim()) ||
|
||||
(preset.type === 'cloudflare' && !presetApiKeys[`${preset.id}-accountId`]?.trim())
|
||||
(preset.type === 'cloudflare' && !presetApiKeys[`${preset.id}-accountId`]?.trim()) ||
|
||||
(preset.type === 'deno' && !presetApiKeys[`${preset.id}-organizationId`]?.trim())
|
||||
}
|
||||
className="w-full"
|
||||
>
|
||||
@@ -862,11 +956,12 @@ export function DeploySettings() {
|
||||
</Label>
|
||||
<Select
|
||||
value={customProviderType}
|
||||
onValueChange={(value: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare') => {
|
||||
onValueChange={(value: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno') => {
|
||||
setCustomProviderType(value);
|
||||
// Reset form when provider type changes
|
||||
setCustomApiKey('');
|
||||
setCustomAccountId('');
|
||||
setCustomOrganizationId('');
|
||||
setCustomBaseURL('');
|
||||
setCustomHost('');
|
||||
setCustomProxy(false);
|
||||
@@ -884,6 +979,7 @@ export function DeploySettings() {
|
||||
<SelectItem value="netlify">Netlify</SelectItem>
|
||||
<SelectItem value="vercel">Vercel</SelectItem>
|
||||
<SelectItem value="cloudflare">Cloudflare</SelectItem>
|
||||
<SelectItem value="deno">Deno Deploy</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
@@ -965,11 +1061,25 @@ export function DeploySettings() {
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{customProviderType === 'deno' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-organizationid">
|
||||
Organization ID <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-organizationid"
|
||||
placeholder="Enter Organization ID"
|
||||
value={customOrganizationId}
|
||||
onChange={(e) => setCustomOrganizationId(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-apikey">
|
||||
{customProviderType === 'netlify' ? 'Personal Access Token' :
|
||||
customProviderType === 'cloudflare' ? 'API Token' :
|
||||
'Access Token'} <span className="text-destructive">*</span>
|
||||
customProviderType === 'deno' ? 'Access Token' :
|
||||
'Access Token'} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<PasswordInput
|
||||
id="custom-apikey"
|
||||
@@ -987,7 +1097,9 @@ export function DeploySettings() {
|
||||
? 'https://api.netlify.com/api/v1'
|
||||
: customProviderType === 'vercel'
|
||||
? 'https://api.vercel.com'
|
||||
: 'https://api.cloudflare.com/client/v4'
|
||||
: customProviderType === 'deno'
|
||||
? 'https://api.deno.com/v1'
|
||||
: 'https://api.cloudflare.com/client/v4'
|
||||
}
|
||||
value={customBaseURL}
|
||||
onChange={(e) => setCustomBaseURL(e.target.value)}
|
||||
@@ -1013,7 +1125,8 @@ export function DeploySettings() {
|
||||
!customProviderType ||
|
||||
!customName.trim() ||
|
||||
(customProviderType !== 'shakespeare' && customProviderType !== 'nsite' && !customApiKey.trim()) ||
|
||||
(customProviderType === 'cloudflare' && !customAccountId.trim())
|
||||
(customProviderType === 'cloudflare' && !customAccountId.trim()) ||
|
||||
(customProviderType === 'deno' && !customOrganizationId.trim())
|
||||
}
|
||||
className="gap-2 ml-auto"
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user