Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 58 additions & 4 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cancel, intro, isCancel, log, select, spinner, text } from "@clack/prompts";
import { cancel, intro, isCancel, log, outro, select, spinner, text } from "@clack/prompts";
import fs from "fs-extra";
import path from "node:path";

Expand All @@ -18,6 +18,12 @@ import {
collectCreateAddonSetupContext,
executeCreateAddonSetupContext,
} from "../tasks/setup-addons";
import {
collectComputeDeployContext,
executeComputeDeployContext,
type ComputeDeployContext,
type ComputeDeployResult,
} from "../tasks/deploy-to-compute";
import {
trackCreateCompleted,
trackCreateFailed,
Expand All @@ -43,6 +49,7 @@ export type CreatePromptContext = {
projectPackageName: string;
prismaSetupContext: PrismaSetupContext;
addonSetupContext?: CreateAddonSetupContext;
computeDeployContext?: ComputeDeployContext;
};

type ExecuteCreateContextResult =
Expand Down Expand Up @@ -305,14 +312,27 @@ async function collectCreateContext(
return;
}

const projectPackageName = toPackageName(path.basename(targetDirectory));

const computeDeployContext = await collectComputeDeployContext(input, {
template,
packageManager: prismaSetupContext.packageManager,
useDefaults,
defaultServiceName: projectPackageName,
});
if (computeDeployContext === undefined) {
return;
}

return {
targetDirectory,
targetPathState,
force,
template,
projectPackageName: toPackageName(path.basename(targetDirectory)),
projectPackageName,
prismaSetupContext,
addonSetupContext: addonSetupContext ?? undefined,
computeDeployContext: computeDeployContext ?? undefined,
};
}

Expand All @@ -329,6 +349,7 @@ async function executeCreateContext(
schemaPreset: context.prismaSetupContext.schemaPreset,
provider: context.prismaSetupContext.databaseProvider,
packageManager: context.prismaSetupContext.packageManager,
compute: Boolean(context.computeDeployContext),
});
scaffoldSpinner.stop("Project files scaffolded.");
} catch (error) {
Expand Down Expand Up @@ -385,14 +406,15 @@ async function executeCreateContext(
}
}

let prismaResult: Awaited<ReturnType<typeof executePrismaSetupContext>>;
try {
const didSetupPrisma = await executePrismaSetupContext(context.prismaSetupContext, {
prismaResult = await executePrismaSetupContext(context.prismaSetupContext, {
prependNextSteps: nextSteps,
projectDir: context.targetDirectory,
includeDevNextStep: true,
});

if (!didSetupPrisma) {
if (!prismaResult.ok) {
return {
ok: false,
stage: "prisma_setup",
Expand All @@ -406,5 +428,37 @@ async function executeCreateContext(
};
}

let deployResult: ComputeDeployResult | undefined;
if (context.computeDeployContext) {
const result = await executeComputeDeployContext({
context: context.computeDeployContext,
projectDir: context.targetDirectory,
envFilePath: prismaResult.databaseUrl ? ".env" : undefined,
});
Comment thread
AmanVarshney01 marked this conversation as resolved.
Outdated
if (!result.ok && !result.cancelled) {
return {
ok: false,
stage: "compute_deploy",
error: result.error,
};
}
if (result.ok) {
deployResult = result.result;
}
}
Comment thread
AmanVarshney01 marked this conversation as resolved.

const summaryLines: string[] = [];
summaryLines.push(`Setup complete.${prismaResult.warningSection}`);
if (deployResult) {
summaryLines.push(
"",
"Deployed to Prisma Compute:",
`- Service URL: ${deployResult.serviceUrl}`,
`- Version URL: ${deployResult.versionUrl}`,
);
}
summaryLines.push("", "Next steps:", prismaResult.nextSteps.join("\n"));
outro(summaryLines.join("\n"));

return { ok: true };
}
Loading
Loading