From 1915e6044fd30540914a334bbbe36ff3fab24ec7 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 3 Jan 2026 18:49:54 -0600 Subject: [PATCH] Deployment providers refactoring --- src/components/AddProviderDialog.tsx | 67 ++------- src/components/ExternalFavicon.tsx | 3 +- src/components/ProviderConfigDialog.tsx | 86 ++--------- src/components/deploy/DeploySteps.tsx | 94 +++++------- src/lib/deploy/types.ts | 16 ++ src/lib/deployProviderPresets.ts | 63 ++++++++ src/pages/DeploySettings.tsx | 187 +++--------------------- 7 files changed, 168 insertions(+), 348 deletions(-) create mode 100644 src/lib/deployProviderPresets.ts diff --git a/src/components/AddProviderDialog.tsx b/src/components/AddProviderDialog.tsx index 59e78bb8..b4507566 100644 --- a/src/components/AddProviderDialog.tsx +++ b/src/components/AddProviderDialog.tsx @@ -19,21 +19,7 @@ import { } from '@/components/ui/dropdown-menu'; import { ExternalFavicon } from '@/components/ExternalFavicon'; import { Link } from 'react-router-dom'; - -interface PresetProvider { - id: string; - type: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno'; - name: string; - description: string; - requiresNostr?: boolean; - apiKeyLabel?: string; - apiKeyURL?: string; - accountIdLabel?: string; - accountIdURL?: string; - organizationIdLabel?: string; - organizationIdURL?: string; - proxy?: boolean; -} +import type { PresetDeployProvider } from '@/lib/deploy/types'; interface OAuthHook { isOAuthConfigured: boolean; @@ -45,7 +31,7 @@ interface OAuthHook { interface AddProviderDialogProps { open: boolean; onOpenChange: (open: boolean) => void; - preset: PresetProvider; + preset: PresetDeployProvider; isLoggedIntoNostr: boolean; oauthHook: OAuthHook | null; forceManualEntry: boolean; @@ -53,25 +39,6 @@ interface AddProviderDialogProps { onAdd: (apiKey: string, accountId?: string, organizationId?: string) => void; } -function getProviderUrl(preset: PresetProvider): string | null { - switch (preset.type) { - case 'shakespeare': - return 'https://shakespeare.diy'; - case 'netlify': - return 'https://netlify.com'; - case 'vercel': - return 'https://vercel.com'; - case 'cloudflare': - return 'https://cloudflare.com'; - case 'deno': - return 'https://deno.com'; - case 'nsite': - return null; - default: - return null; - } -} - export function AddProviderDialog({ open, onOpenChange, @@ -100,22 +67,16 @@ export function AddProviderDialog({ onOpenChange(false); }; - const url = getProviderUrl(preset); - return (
- {url ? ( - } - /> - ) : ( - - )} + } + /> {preset.name}
@@ -152,15 +113,11 @@ export function AddProviderDialog({ ) : ( <> - {url ? ( - } - /> - ) : ( - - )} + } + /> Connect to {preset.name} diff --git a/src/components/ExternalFavicon.tsx b/src/components/ExternalFavicon.tsx index 38868387..4e903c1f 100644 --- a/src/components/ExternalFavicon.tsx +++ b/src/components/ExternalFavicon.tsx @@ -5,7 +5,7 @@ import { ReactNode, useMemo } from 'react'; interface ExternalFaviconProps { /** The URL to fetch the favicon for */ - url: string | URL; + url: string | URL | undefined; /** Size of the favicon in pixels */ size?: number; /** Fallback element to display if favicon fails to load */ @@ -28,6 +28,7 @@ export function ExternalFavicon({ // Generate the favicon URL using the configured template const faviconSrc = useMemo(() => { + if (!url) return; try { // Normalize the URL to ensure it has a protocol return faviconUrl(config.faviconUrl, url); diff --git a/src/components/ProviderConfigDialog.tsx b/src/components/ProviderConfigDialog.tsx index a8031779..69843b98 100644 --- a/src/components/ProviderConfigDialog.tsx +++ b/src/components/ProviderConfigDialog.tsx @@ -15,28 +15,14 @@ import { DialogFooter, } from '@/components/ui/dialog'; import type { DeployProvider } from '@/contexts/DeploySettingsContext'; +import type { PresetDeployProvider } from '@/lib/deploy/types'; import { ExternalFavicon } from '@/components/ExternalFavicon'; -interface PresetProvider { - id: string; - type: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno'; - name: string; - description: string; - requiresNostr?: boolean; - apiKeyLabel?: string; - apiKeyURL?: string; - accountIdLabel?: string; - accountIdURL?: string; - organizationIdLabel?: string; - organizationIdURL?: string; - proxy?: boolean; -} - interface ProviderConfigDialogProps { open: boolean; onOpenChange: (open: boolean) => void; provider: DeployProvider; - preset?: PresetProvider; + preset?: PresetDeployProvider; onUpdate: (provider: DeployProvider) => void; onRemove: () => void; } @@ -56,52 +42,6 @@ function normalizeUrl(url: string): string { return `https://${url}`; } -function getProviderUrl(provider: DeployProvider | PresetProvider): string | null { - switch (provider.type) { - case 'shakespeare': - // For Shakespeare providers, check for custom host first, then use default - if ('host' in provider && provider.host) { - return normalizeUrl(provider.host); - } - return 'https://shakespeare.diy'; - - case 'netlify': - // For Netlify providers, check for custom baseURL first, then use default - if ('baseURL' in provider && provider.baseURL) { - return provider.baseURL; - } - return 'https://netlify.com'; - - case 'vercel': - // For Vercel providers, check for custom baseURL first, then use default - if ('baseURL' in provider && provider.baseURL) { - return provider.baseURL; - } - return 'https://vercel.com'; - - case 'cloudflare': - // For Cloudflare providers, check for custom baseURL first, then use default - if ('baseURL' in provider && provider.baseURL) { - return provider.baseURL; - } - 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; - - default: - return null; - } -} - export function ProviderConfigDialog({ open, onOpenChange, @@ -130,22 +70,24 @@ export function ProviderConfigDialog({ onOpenChange(false); }; - const url = getProviderUrl(localProvider); + // Use baseURL from configured provider, falling back to preset baseURL + const baseURL = ('baseURL' in localProvider && localProvider.baseURL) || preset?.baseURL; + + // For Shakespeare, special handling for host field + const shakespeareUrl = localProvider.type === 'shakespeare' && 'host' in localProvider && localProvider.host + ? normalizeUrl(localProvider.host) + : undefined; return (
- {url ? ( - } - /> - ) : ( - - )} + } + /> {localProvider.name}
diff --git a/src/components/deploy/DeploySteps.tsx b/src/components/deploy/DeploySteps.tsx index 9bffde50..7563dad7 100644 --- a/src/components/deploy/DeploySteps.tsx +++ b/src/components/deploy/DeploySteps.tsx @@ -15,6 +15,8 @@ import { useAppContext } from '@/hooks/useAppContext'; import { useNostr } from '@nostrify/react'; import { Link } from 'react-router-dom'; import type { DeployProvider } from '@/contexts/DeploySettingsContext'; +import type { PresetDeployProvider } from '@/lib/deploy/types'; +import { PRESET_DEPLOY_PROVIDERS } from '@/lib/deployProviderPresets'; import { ShakespeareDeployForm } from '@/components/deploy/ShakespeareDeployForm'; import { NetlifyDeployForm } from '@/components/deploy/NetlifyDeployForm'; import { VercelDeployForm } from '@/components/deploy/VercelDeployForm'; @@ -31,53 +33,28 @@ import { CloudflareAdapter } from '@/lib/deploy/CloudflareAdapter'; import { DenoDeployAdapter } from '@/lib/deploy/DenoDeployAdapter'; /** - * Helper function to get provider URL for favicon + * Normalize a URL string to ensure it has a protocol */ -function getProviderUrl(provider: DeployProvider): string | null { - switch (provider.type) { - case 'shakespeare': - if (provider.host) { - return `https://${provider.host}`; - } - return 'https://shakespeare.diy'; - - case 'netlify': - if (provider.baseURL) { - return provider.baseURL; - } - return 'https://netlify.com'; - - case 'vercel': - if (provider.baseURL) { - return provider.baseURL; - } - return 'https://vercel.com'; - - case 'cloudflare': - if (provider.baseURL) { - return provider.baseURL; - } - return 'https://cloudflare.com'; - - case 'deno': - if (provider.baseURL) { - return provider.baseURL; - } - return 'https://deno.com'; - - case 'nsite': - return null; - - default: - return null; +function normalizeUrl(url: string): string { + if (/^https?:\/\//i.test(url)) { + return url; } + return `https://${url}`; } /** * Render provider icon using favicon or fallback */ -function renderProviderIcon(provider: DeployProvider, size = 14) { - const url = getProviderUrl(provider); +function renderProviderIcon(provider: DeployProvider, preset: PresetDeployProvider | undefined, size = 14) { + // Use baseURL from configured provider, falling back to preset baseURL + const baseURL = ('baseURL' in provider && provider.baseURL) || preset?.baseURL; + + // For Shakespeare, special handling for host field + const shakespeareUrl = provider.type === 'shakespeare' && 'host' in provider && provider.host + ? normalizeUrl(provider.host) + : undefined; + + const url = shakespeareUrl || baseURL; if (url) { return ( @@ -589,23 +566,26 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
- {settings.providers.map((provider) => ( - - ))} + {settings.providers.map((provider) => { + const preset = PRESET_DEPLOY_PROVIDERS.find(p => p.type === provider.type); + return ( + + ); + })}
diff --git a/src/lib/deploy/types.ts b/src/lib/deploy/types.ts index 60222a5d..6c9df61a 100644 --- a/src/lib/deploy/types.ts +++ b/src/lib/deploy/types.ts @@ -74,3 +74,19 @@ export interface DenoDeployConfig { projectName?: string; corsProxy?: string; } + +export interface PresetDeployProvider { + id: string; + type: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno'; + name: string; + description: string; + baseURL?: string; + requiresNostr?: boolean; + apiKeyLabel?: string; + apiKeyURL?: string; + accountIdLabel?: string; + accountIdURL?: string; + organizationIdLabel?: string; + organizationIdURL?: string; + proxy?: boolean; +} diff --git a/src/lib/deployProviderPresets.ts b/src/lib/deployProviderPresets.ts new file mode 100644 index 00000000..5bf6d8a4 --- /dev/null +++ b/src/lib/deployProviderPresets.ts @@ -0,0 +1,63 @@ +import type { PresetDeployProvider } from './deploy/types'; + +export const PRESET_DEPLOY_PROVIDERS: PresetDeployProvider[] = [ + { + id: 'shakespeare', + type: 'shakespeare', + name: 'Shakespeare Deploy', + description: 'Deploy to Shakespeare hosting with Nostr authentication', + baseURL: 'https://shakespeare.diy', + requiresNostr: true, + }, + { + id: 'nsite', + type: 'nsite', + name: 'nsite', + description: 'Deploy to Nostr as a static website', + // No baseURL for nsite - uses Rocket icon fallback + }, + { + id: 'netlify', + type: 'netlify', + name: 'Netlify', + description: 'Deploy to Netlify', + baseURL: 'https://api.netlify.com/api/v1', + apiKeyLabel: 'Personal Access Token', + apiKeyURL: 'https://app.netlify.com/user/applications#personal-access-tokens', + proxy: true, + }, + { + id: 'vercel', + type: 'vercel', + name: 'Vercel', + description: 'Deploy to Vercel', + baseURL: 'https://api.vercel.com', + apiKeyLabel: 'Access Token', + apiKeyURL: 'https://vercel.com/account/tokens', + proxy: true, + }, + { + id: 'cloudflare', + type: 'cloudflare', + name: 'Cloudflare', + description: 'Deploy to Cloudflare Workers', + baseURL: 'https://api.cloudflare.com/client/v4', + apiKeyLabel: 'API Token', + apiKeyURL: 'https://dash.cloudflare.com/profile/api-tokens', + accountIdLabel: 'Account ID', + 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', + baseURL: 'https://api.deno.com/v1', + apiKeyLabel: 'Access Token', + apiKeyURL: 'https://dash.deno.com/account#access-tokens', + organizationIdLabel: 'Organization ID', + organizationIdURL: 'https://dash.deno.com/orgs', + proxy: true, + }, +]; diff --git a/src/pages/DeploySettings.tsx b/src/pages/DeploySettings.tsx index e25fe797..2f458271 100644 --- a/src/pages/DeploySettings.tsx +++ b/src/pages/DeploySettings.tsx @@ -8,6 +8,8 @@ import { useNetlifyOAuth } from '@/hooks/useNetlifyOAuth'; import { useVercelOAuth } from '@/hooks/useVercelOAuth'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import type { DeployProvider } from '@/contexts/DeploySettingsContext'; +import type { PresetDeployProvider } from '@/lib/deploy/types'; +import { PRESET_DEPLOY_PROVIDERS } from '@/lib/deployProviderPresets'; import { ExternalFavicon } from '@/components/ExternalFavicon'; import { ProviderConfigDialog } from '@/components/ProviderConfigDialog'; import { AddProviderDialog } from '@/components/AddProviderDialog'; @@ -30,30 +32,17 @@ import { } from '@dnd-kit/sortable'; import { CSS } from '@dnd-kit/utilities'; -interface PresetProvider { - id: string; - type: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno'; - name: string; - description: string; - requiresNostr?: boolean; - apiKeyLabel?: string; - apiKeyURL?: string; - accountIdLabel?: string; - accountIdURL?: string; - organizationIdLabel?: string; - organizationIdURL?: string; - proxy?: boolean; -} - interface ProviderTileProps { provider: DeployProvider; - preset?: PresetProvider; + preset?: PresetDeployProvider; onClick: () => void; id: string; } -function ProviderTile({ provider, onClick, id }: ProviderTileProps) { - const url = getProviderUrl(provider); +function ProviderTile({ provider, preset, onClick, id }: ProviderTileProps) { + // Use baseURL from configured provider, falling back to preset baseURL + const baseURL = ('baseURL' in provider && provider.baseURL) || preset?.baseURL; + const { attributes, listeners, @@ -75,15 +64,11 @@ function ProviderTile({ provider, onClick, id }: ProviderTileProps) { onClick={onClick} className="flex flex-col items-center justify-center gap-2 p-4 rounded-lg border bg-card hover:bg-muted transition-colors text-center h-[120px] w-full" > - {url ? ( - } - /> - ) : ( - - )} + } + /> {provider.name} @@ -119,27 +104,21 @@ function AddProviderTile({ onClick }: AddProviderTileProps) { } interface PresetProviderTileProps { - preset: PresetProvider; + preset: PresetDeployProvider; onClick: () => void; } function PresetProviderTile({ preset, onClick }: PresetProviderTileProps) { - const url = getProviderUrl(preset); - return (