From c104b37677efd2d794a543293d85d973ce09a47e Mon Sep 17 00:00:00 2001 From: xixixao Date: Wed, 7 May 2025 19:02:17 +0200 Subject: [PATCH] Fix initial codegen for anonymous projects --- src/cli/configure.ts | 13 ++++++------- src/cli/lib/codegen.ts | 12 +++++++++++- src/cli/lib/localDeployment/anonymous.ts | 5 +++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/cli/configure.ts b/src/cli/configure.ts index 363540c6..71d2636d 100644 --- a/src/cli/configure.ts +++ b/src/cli/configure.ts @@ -42,7 +42,11 @@ import { import { writeConvexUrlToEnvFile } from "./lib/envvars.js"; import path from "path"; import { projectDashboardUrl } from "./lib/dashboard.js"; -import { doCodegen, doInitCodegen } from "./lib/codegen.js"; +import { + doCodegen, + doCodegenForNewProject, + doInitCodegen, +} from "./lib/codegen.js"; import { handleLocalDeployment } from "./lib/localDeployment/localDeployment.js"; import { promptOptions, @@ -598,12 +602,7 @@ async function selectNewProject( ); } - const { projectConfig: existingProjectConfig } = await readProjectConfig(ctx); - const configPath = await configFilepath(ctx); - const functionsPath = functionsDir(configPath, existingProjectConfig); - await doInitCodegen(ctx, functionsPath, true); - // Disable typechecking since there isn't any code yet. - await doCodegen(ctx, functionsPath, "disable"); + await doCodegenForNewProject(ctx); return { teamSlug, projectSlug, devDeployment }; } diff --git a/src/cli/lib/codegen.ts b/src/cli/lib/codegen.ts index 472ff961..4f2c6a02 100644 --- a/src/cli/lib/codegen.ts +++ b/src/cli/lib/codegen.ts @@ -20,7 +20,7 @@ import { logVerbose, } from "../../bundler/context.js"; import { typeCheckFunctionsInMode, TypeCheckMode } from "./typecheck.js"; -import { readProjectConfig } from "./config.js"; +import { configFilepath, readProjectConfig } from "./config.js"; import { recursivelyDelete } from "./fsUtils.js"; import { componentServerDTS, @@ -35,6 +35,7 @@ import { componentApiStubDTS, rootComponentApiCJS, } from "../codegen_templates/component_api.js"; +import { functionsDir } from "./utils/utils.js"; export type CodegenOptions = { url?: string; @@ -47,6 +48,15 @@ export type CodegenOptions = { liveComponentSources: boolean; }; +export async function doCodegenForNewProject(ctx: Context) { + const { projectConfig: existingProjectConfig } = await readProjectConfig(ctx); + const configPath = await configFilepath(ctx); + const functionsPath = functionsDir(configPath, existingProjectConfig); + await doInitCodegen(ctx, functionsPath, true); + // Disable typechecking since there isn't any code yet. + await doCodegen(ctx, functionsPath, "disable"); +} + export async function doInitCodegen( ctx: Context, functionsDir: string, diff --git a/src/cli/lib/localDeployment/anonymous.ts b/src/cli/lib/localDeployment/anonymous.ts index b77b7718..b0c1995f 100644 --- a/src/cli/lib/localDeployment/anonymous.ts +++ b/src/cli/lib/localDeployment/anonymous.ts @@ -43,6 +43,8 @@ import { isAnonymousDeployment } from "../deployment.js"; import { createProject } from "../api.js"; import { removeAnonymousPrefix } from "../deployment.js"; import { nodeFs } from "../../../bundler/fs.js"; +import { doCodegenForNewProject, doInitCodegen } from "../codegen.js"; +import { functionsDir } from "../utils/utils.js"; export async function handleAnonymousDeployment( ctx: Context, @@ -174,6 +176,9 @@ export async function handleAnonymousDeployment( } }); + if (deployment.kind === "new") { + await doCodegenForNewProject(ctx); + } return { adminKey, deploymentName: deployment.deploymentName,