From 20ca4070119ddca4ecacc43001d39f04660fd285 Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Thu, 27 Nov 2025 22:20:15 +0530 Subject: [PATCH] added quick mode to skip wizard --- .../functions/create-function/deploy/+page.ts | 105 ++++++++++++++- .../sites/create-site/deploy/+page.ts | 121 +++++++++++++++++- .../(public)/functions/deploy/+page.svelte | 3 + src/routes/(public)/sites/deploy/+page.svelte | 3 + 4 files changed, 226 insertions(+), 6 deletions(-) diff --git a/src/routes/(console)/project-[region]-[project]/functions/create-function/deploy/+page.ts b/src/routes/(console)/project-[region]-[project]/functions/create-function/deploy/+page.ts index 504371be3..7b9f6ff25 100644 --- a/src/routes/(console)/project-[region]-[project]/functions/create-function/deploy/+page.ts +++ b/src/routes/(console)/project-[region]-[project]/functions/create-function/deploy/+page.ts @@ -1,11 +1,22 @@ import { sdk } from '$lib/stores/sdk'; -import { redirect } from '@sveltejs/kit'; +import { redirect, isRedirect } from '@sveltejs/kit'; import { base } from '$app/paths'; import type { PageLoad } from './$types'; -import { getNestedRootDirectory, getRepositoryInfo } from '$lib/helpers/github'; +import { + getNestedRootDirectory, + getRepositoryInfo, + getDefaultBranch, + validateBranch +} from '$lib/helpers/github'; +import { ID, Runtime, Type } from '@appwrite.io/console'; export const load: PageLoad = async ({ url, params, parent }) => { - const { installations: vcsInstallations, runtimesList, specificationsList } = await parent(); + const { + installations: vcsInstallations, + runtimesList, + specificationsList, + regionalConsoleVariables + } = await parent(); const repository = url.searchParams.get('repo') || url.searchParams.get('repository'); @@ -37,6 +48,94 @@ export const load: PageLoad = async ({ url, params, parent }) => { const runtime = url.searchParams.get('runtime'); + // Quick mode - create function and redirect directly to function page + const quickMode = url.searchParams.get('quick') === 'true'; + + if (quickMode) { + try { + const runtimeParam = runtime || 'node-18.0'; + const selectedRuntime = runtimeParam as Runtime; + + const entrypoint = url.searchParams.get('entrypoint') || ''; + const installCommand = url.searchParams.get('install') || ''; + const rootDir = + getNestedRootDirectory(repository) || url.searchParams.get('rootDir') || '.'; + + // Get branch - validate provided or use default + const branchParam = url.searchParams.get('branch'); + let selectedBranch: string; + + if (branchParam) { + const isValid = await validateBranch(info.owner, info.name, branchParam); + if (isValid) { + selectedBranch = branchParam; + } else { + selectedBranch = (await getDefaultBranch(info.owner, info.name)) || 'main'; + } + } else { + selectedBranch = (await getDefaultBranch(info.owner, info.name)) || 'main'; + } + + // Get first available specification + const specification = + specificationsList?.specifications?.[0]?.slug || 's-0.5vcpu-512mb'; + + // Create function + const func = await sdk.forProject(params.region, params.project).functions.create({ + functionId: ID.unique(), + name: info.name, + runtime: selectedRuntime, + execute: ['any'], + entrypoint: entrypoint || undefined, + commands: installCommand || undefined, + providerSilentMode: false, + specification + }); + + // Add auto-generated domain + await sdk.forProject(params.region, params.project).proxy.createFunctionRule({ + domain: `${ID.unique()}.${regionalConsoleVariables._APP_DOMAIN_FUNCTIONS}`, + functionId: func.$id + }); + + // Add variables (empty values used as empty strings) + await Promise.all( + envVars.map((variable) => + sdk.forProject(params.region, params.project).functions.createVariable({ + functionId: func.$id, + key: variable.key, + value: variable.value, + secret: false + }) + ) + ); + + // Create deployment + await sdk.forProject(params.region, params.project).functions.createTemplateDeployment({ + functionId: func.$id, + repository: info.name, + owner: info.owner, + rootDirectory: rootDir, + type: Type.Branch, + reference: selectedBranch, + activate: true + }); + + // Redirect to function page + redirect( + 302, + `${base}/project-${params.region}-${params.project}/functions/function-${func.$id}` + ); + } catch (e) { + // Re-throw redirects (they're not errors) + if (isRedirect(e)) { + throw e; + } + // On error, fall through to show the wizard + console.error('Quick deploy failed:', e); + } + } + let installations = vcsInstallations || null; if (!installations) { try { diff --git a/src/routes/(console)/project-[region]-[project]/sites/create-site/deploy/+page.ts b/src/routes/(console)/project-[region]-[project]/sites/create-site/deploy/+page.ts index dc38b502f..30206adcf 100644 --- a/src/routes/(console)/project-[region]-[project]/sites/create-site/deploy/+page.ts +++ b/src/routes/(console)/project-[region]-[project]/sites/create-site/deploy/+page.ts @@ -1,10 +1,16 @@ import { sdk } from '$lib/stores/sdk'; -import { redirect } from '@sveltejs/kit'; +import { redirect, isRedirect } from '@sveltejs/kit'; import { base } from '$app/paths'; import type { PageLoad } from './$types'; -import { getNestedRootDirectory, getRepositoryInfo } from '$lib/helpers/github'; +import { + getNestedRootDirectory, + getRepositoryInfo, + getDefaultBranch, + validateBranch +} from '$lib/helpers/github'; +import { Adapter, BuildRuntime, Framework, ID, Type } from '@appwrite.io/console'; -export const load: PageLoad = async ({ url, params }) => { +export const load: PageLoad = async ({ url, params, parent }) => { const repository = url.searchParams.get('repo') || url.searchParams.get('repository'); if (!repository) { @@ -33,6 +39,115 @@ export const load: PageLoad = async ({ url, params }) => { }) : []; + // Quick mode - create site and redirect directly to deploying page + const quickMode = url.searchParams.get('quick') === 'true'; + + if (quickMode) { + try { + const { regionalConsoleVariables } = await parent(); + + const preset = url.searchParams.get('preset') || 'nextjs'; + const framework = (Object.values(Framework) as string[]).includes(preset.toLowerCase()) + ? (preset.toLowerCase() as Framework) + : Framework.Nextjs; + + // Get framework defaults + const frameworks = await sdk + .forProject(params.region, params.project) + .sites.listFrameworks(); + const fw = frameworks.frameworks.find((f) => f.key === framework); + + let installCommand = url.searchParams.get('install') || ''; + let buildCommand = url.searchParams.get('build') || ''; + let outputDirectory = url.searchParams.get('output') || ''; + + // Use framework defaults if not provided + if (!installCommand && !buildCommand && !outputDirectory && fw?.adapters?.length > 0) { + const adapter = fw.adapters[0]; + installCommand = adapter.installCommand || ''; + buildCommand = adapter.buildCommand || ''; + outputDirectory = adapter.outputDirectory || ''; + } + + // Get branch - validate provided or use default + const branchParam = url.searchParams.get('branch'); + let selectedBranch: string; + + if (branchParam) { + const isValid = await validateBranch(info.owner, info.name, branchParam); + if (isValid) { + selectedBranch = branchParam; + } else { + selectedBranch = (await getDefaultBranch(info.owner, info.name)) || 'main'; + } + } else { + selectedBranch = (await getDefaultBranch(info.owner, info.name)) || 'main'; + } + + const rootDir = + getNestedRootDirectory(repository) || url.searchParams.get('rootDir') || '.'; + const buildRuntime = + framework === Framework.Other ? BuildRuntime.Static1 : BuildRuntime.Node210; + + // Create site + const site = await sdk.forProject(params.region, params.project).sites.create({ + siteId: ID.unique(), + name: info.name, + framework, + buildRuntime, + installCommand: installCommand || undefined, + buildCommand: buildCommand || undefined, + outputDirectory: outputDirectory || undefined, + adapter: framework === Framework.Other ? Adapter.Static : undefined, + providerSilentMode: false + }); + + // Add auto-generated domain + await sdk.forProject(params.region, params.project).proxy.createSiteRule({ + domain: `${ID.unique()}.${regionalConsoleVariables._APP_DOMAIN_SITES}`, + siteId: site.$id + }); + + // Add variables (empty values used as empty strings) + await Promise.all( + envVars.map((variable) => + sdk.forProject(params.region, params.project).sites.createVariable({ + siteId: site.$id, + key: variable.key, + value: variable.value, + secret: false + }) + ) + ); + + // Create deployment + const deployment = await sdk + .forProject(params.region, params.project) + .sites.createTemplateDeployment({ + siteId: site.$id, + repository: info.name, + owner: info.owner, + rootDirectory: rootDir, + type: Type.Branch, + reference: selectedBranch, + activate: true + }); + + // Redirect to deploying page + redirect( + 302, + `${base}/project-${params.region}-${params.project}/sites/create-site/deploying?site=${site.$id}&deployment=${deployment.$id}` + ); + } catch (e) { + // Re-throw redirects (they're not errors) + if (isRedirect(e)) { + throw e; + } + // On error, fall through to show the wizard + console.error('Quick deploy failed:', e); + } + } + const [frameworks, installations] = await Promise.all([ sdk.forProject(params.region, params.project).sites.listFrameworks(), sdk diff --git a/src/routes/(public)/functions/deploy/+page.svelte b/src/routes/(public)/functions/deploy/+page.svelte index 4f2b5eeb8..2da5c21bc 100644 --- a/src/routes/(public)/functions/deploy/+page.svelte +++ b/src/routes/(public)/functions/deploy/+page.svelte @@ -117,6 +117,8 @@ const branch = currentUrl.searchParams.get('branch') || data.deploymentData.repository.branch; + const quick = currentUrl.searchParams.get('quick'); + if (entrypoint) url.searchParams.set('entrypoint', entrypoint); if (install) url.searchParams.set('install', install); if (build) url.searchParams.set('build', build); @@ -126,6 +128,7 @@ rootDir || data.deploymentData.repository.rootDirectory ); if (branch) url.searchParams.set('branch', branch); + if (quick === 'true') url.searchParams.set('quick', 'true'); if (data.envVars.length > 0) { // Preserve KEY=value format for prefilled values diff --git a/src/routes/(public)/sites/deploy/+page.svelte b/src/routes/(public)/sites/deploy/+page.svelte index 32d09c370..a8364205b 100644 --- a/src/routes/(public)/sites/deploy/+page.svelte +++ b/src/routes/(public)/sites/deploy/+page.svelte @@ -124,11 +124,14 @@ const branch = currentUrl.searchParams.get('branch') || data.deploymentData.repository.branch; + const quick = currentUrl.searchParams.get('quick'); + if (preset) url.searchParams.set('preset', preset); if (install) url.searchParams.set('install', install); if (build) url.searchParams.set('build', build); if (output) url.searchParams.set('output', output); if (branch) url.searchParams.set('branch', branch); + if (quick === 'true') url.searchParams.set('quick', 'true'); } if (data.envVars.length > 0) {