From aefeebf009b4186d0fa868f3d9bd4c6daa730536 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Tue, 13 Jun 2023 15:19:06 +0200 Subject: [PATCH] feat(deploy): push initial deployment to prod (#158) This tweaks `deploy` behavior on empty projects, pushing the initial deployment to prod and telling the user about futher updates requiring `--prod` flag usage. It also enhances the final status message in order to record which environment got updated (production or preview). --- src/subcommands/deploy.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/subcommands/deploy.ts b/src/subcommands/deploy.ts index 6b5384a6..ae2d83c9 100644 --- a/src/subcommands/deploy.ts +++ b/src/subcommands/deploy.ts @@ -128,7 +128,21 @@ async function deploy(opts: DeployOpts): Promise { projectSpinner.fail("Project not found."); Deno.exit(1); } - projectSpinner.succeed(`Project: ${project.name}`); + + const deploymentsListing = await api.getDeployments(project!.id); + if (deploymentsListing === null) { + projectSpinner.fail("Project deployments details not found."); + Deno.exit(1); + } + const [projectDeployments, _pagination] = deploymentsListing!; + projectSpinner.succeed(`Project: ${project!.name}`); + + if (projectDeployments.length === 0) { + wait("").start().info( + "Empty project detected, automatically pushing initial deployment to production (use --prod for further updates).", + ); + opts.prod = true; + } let url = opts.entrypoint; const cwd = Deno.cwd(); @@ -234,13 +248,15 @@ async function deploy(opts: DeployOpts): Promise { case "uploadComplete": deploySpinner!.text = `Finishing deployment...`; break; - case "success": - deploySpinner!.succeed(`Deployment complete.`); + case "success": { + const deploymentKind = opts.prod ? "Production" : "Preview"; + deploySpinner!.succeed(`${deploymentKind} deployment complete.`); console.log("\nView at:"); for (const { domain } of event.domainMappings) { console.log(` - https://${domain}`); } break; + } case "error": if (uploadSpinner) { uploadSpinner.fail(`Upload failed.`);