Deployment providers refactoring

This commit is contained in:
Alex Gleason committed 2026-01-03 18:49:54 -06:00
1 parent cb3fb88a75
commit 1915e6044f
7 files changed
+168 -348

No files matched your search

+12 -55
View File
@@ -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 (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-md">
<DialogHeader>
<div className="flex items-center gap-2">
{url ? (
<ExternalFavicon
url={url}
size={20}
fallback={<Rocket size={20} />}
/>
) : (
<Rocket size={20} />
)}
<ExternalFavicon
url={preset.baseURL}
size={20}
fallback={<Rocket size={20} />}
/>
<DialogTitle>{preset.name}</DialogTitle>
</div>
<DialogDescription>
@@ -152,15 +113,11 @@ export function AddProviderDialog({
</>
) : (
<>
{url ? (
<ExternalFavicon
url={url}
size={16}
fallback={<Rocket size={16} />}
/>
) : (
<Rocket size={16} />
)}
<ExternalFavicon
url={preset.baseURL}
size={16}
fallback={<Rocket size={16} />}
/>
<span className="truncate text-ellipsis overflow-hidden">
Connect to {preset.name}
</span>
+2 -1
View File
@@ -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);
+14 -72
View File
@@ -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 (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-md">
<DialogHeader>
<div className="flex items-center gap-2">
{url ? (
<ExternalFavicon
url={url}
size={20}
fallback={<Rocket size={20} />}
/>
) : (
<Rocket size={20} />
)}
<ExternalFavicon
url={shakespeareUrl || baseURL}
size={20}
fallback={<Rocket size={20} />}
/>
<DialogTitle>{localProvider.name}</DialogTitle>
</div>
<DialogDescription>
+37 -57
View File
@@ -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
<div className="space-y-2">
<Label>Select Provider</Label>
<div className="flex flex-wrap gap-2">
{settings.providers.map((provider) => (
<button
key={provider.id}
type="button"
onClick={() => setSelectedProviderId(provider.id)}
className={cn(
"inline-flex items-center gap-2 px-3 py-1.5 rounded-full text-sm font-medium transition-all",
"border-2 hover:scale-105 active:scale-95",
selectedProviderId === provider.id
? "bg-primary text-primary-foreground border-primary shadow-sm"
: "bg-background text-foreground border-border hover:border-primary/50"
)}
>
{renderProviderIcon(provider, 14)}
<span>{provider.name}</span>
</button>
))}
{settings.providers.map((provider) => {
const preset = PRESET_DEPLOY_PROVIDERS.find(p => p.type === provider.type);
return (
<button
key={provider.id}
type="button"
onClick={() => setSelectedProviderId(provider.id)}
className={cn(
"inline-flex items-center gap-2 px-3 py-1.5 rounded-full text-sm font-medium transition-all",
"border-2 hover:scale-105 active:scale-95",
selectedProviderId === provider.id
? "bg-primary text-primary-foreground border-primary shadow-sm"
: "bg-background text-foreground border-border hover:border-primary/50"
)}
>
{renderProviderIcon(provider, preset, 14)}
<span>{provider.name}</span>
</button>
);
})}
</div>
</div>
+16
View File
@@ -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;
}
+63
View File
@@ -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,
},
];
+24 -163
View File
@@ -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 ? (
<ExternalFavicon
url={url}
size={32}
fallback={<Rocket size={32} />}
/>
) : (
<Rocket size={32} />
)}
<ExternalFavicon
url={baseURL}
size={32}
fallback={<Rocket size={32} />}
/>
<span className="text-sm font-medium line-clamp-2 overflow-hidden max-w-full text-ellipsis">
{provider.name}
</span>
@@ -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 (
<button
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 min-h-[100px]"
>
{url ? (
<ExternalFavicon
url={url}
size={32}
fallback={<Rocket size={32} />}
/>
) : (
<Rocket size={32} />
)}
<ExternalFavicon
url={preset.baseURL}
size={32}
fallback={<Rocket size={32} />}
/>
<span className="text-sm font-medium line-clamp-2 overflow-hidden max-w-full text-ellipsis">
{preset.name}
</span>
@@ -147,62 +126,6 @@ function PresetProviderTile({ preset, onClick }: PresetProviderTileProps) {
);
}
const PRESET_PROVIDERS: PresetProvider[] = [
{
id: 'shakespeare',
type: 'shakespeare',
name: 'Shakespeare Deploy',
description: 'Deploy to Shakespeare hosting with Nostr authentication',
requiresNostr: true,
},
{
id: 'nsite',
type: 'nsite',
name: 'nsite',
description: 'Deploy to Nostr as a static website',
},
{
id: 'netlify',
type: 'netlify',
name: 'Netlify',
description: 'Deploy to Netlify',
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',
apiKeyLabel: 'Access Token',
apiKeyURL: 'https://vercel.com/account/tokens',
proxy: true,
},
{
id: 'cloudflare',
type: 'cloudflare',
name: 'Cloudflare',
description: 'Deploy to Cloudflare Workers',
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',
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
function generateCustomProviderId(type: string): string {
const uuid = crypto.randomUUID();
@@ -210,68 +133,6 @@ function generateCustomProviderId(type: string): string {
return `${type}-${randomSegment}`;
}
/**
* Normalize a URL string to ensure it has a protocol
* @param url - The URL string to normalize
* @returns A fully-qualified URL string
*/
function normalizeUrl(url: string): string {
// If it already has a protocol, return as-is
if (/^https?:\/\//i.test(url)) {
return url;
}
// Add https:// prefix
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 DeploySettings() {
const { t } = useTranslation();
const { settings, removeProvider, setProviders, isInitialized } = useDeploySettings();
@@ -286,7 +147,7 @@ export function DeploySettings() {
// Dialog state
const [selectedProviderIndex, setSelectedProviderIndex] = useState<number | null>(null);
const [dialogOpen, setDialogOpen] = useState(false);
const [selectedPreset, setSelectedPreset] = useState<PresetProvider | null>(null);
const [selectedPreset, setSelectedPreset] = useState<PresetDeployProvider | null>(null);
const [addDialogOpen, setAddDialogOpen] = useState(false);
const [customProviderDialogOpen, setCustomProviderDialogOpen] = useState(false);
@@ -315,12 +176,12 @@ export function DeploySettings() {
setDialogOpen(true);
};
const handleOpenAddDialog = (preset: PresetProvider) => {
const handleOpenAddDialog = (preset: PresetDeployProvider) => {
setSelectedPreset(preset);
setAddDialogOpen(true);
};
const handleAddPresetProvider = (preset: PresetProvider, apiKey: string, accountId?: string, organizationId?: string) => {
const handleAddPresetProvider = (preset: PresetDeployProvider, apiKey: string, accountId?: string, organizationId?: string) => {
// For Shakespeare, just check if user is logged in
if (preset.requiresNostr && !user) {
return;
@@ -426,7 +287,7 @@ export function DeploySettings() {
};
const configuredProviderIds = settings.providers.map(p => p.id);
const availablePresets = PRESET_PROVIDERS.filter(preset => !configuredProviderIds.includes(preset.id));
const availablePresets = PRESET_DEPLOY_PROVIDERS.filter(preset => !configuredProviderIds.includes(preset.id));
return (
<SettingsPageLayout
@@ -475,7 +336,7 @@ export function DeploySettings() {
>
<div className="grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3">
{settings.providers.map((provider, index) => {
const preset = PRESET_PROVIDERS.find(p => p.type === provider.type);
const preset = PRESET_DEPLOY_PROVIDERS.find(p => p.type === provider.type);
return (
<ProviderTile
@@ -499,7 +360,7 @@ export function DeploySettings() {
open={dialogOpen}
onOpenChange={setDialogOpen}
provider={settings.providers[selectedProviderIndex]}
preset={PRESET_PROVIDERS.find(p => p.type === settings.providers[selectedProviderIndex].type)}
preset={PRESET_DEPLOY_PROVIDERS.find(p => p.type === settings.providers[selectedProviderIndex].type)}
onUpdate={(updatedProvider) => handleUpdateProvider(selectedProviderIndex, updatedProvider)}
onRemove={() => handleRemoveProvider(selectedProviderIndex)}
/>