Skip to content

Commit 4baeb68

Browse files
ianmacartneyConvex, Inc.
authored andcommitted
Ian/drop existing codegen (#43588)
- I might be missing something, but when doing `npx convex configure` and getting an existing project, I'm not sure codegen is necessary at all, and this can help reduce the number of ways it can be invoked. This is an alternate to #43587 GitOrigin-RevId: 058fcab33f82b9e379b89fc41d6d5aba82706baf
1 parent 2bbbcc4 commit 4baeb68

File tree

4 files changed

+22
-49
lines changed

4 files changed

+22
-49
lines changed

src/cli/configure.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
import { writeConvexUrlToEnvFile } from "./lib/envvars.js";
4242
import path from "path";
4343
import { projectDashboardUrl } from "./lib/dashboard.js";
44-
import { doInitialCodegen } from "./lib/codegen.js";
44+
import { doInitConvexFolder } from "./lib/codegen.js";
4545
import { handleLocalDeployment } from "./lib/localDeployment/localDeployment.js";
4646
import {
4747
promptOptions,
@@ -587,7 +587,7 @@ async function selectNewProject(
587587
);
588588
}
589589

590-
await doInitialCodegen(ctx, { init: true });
590+
await doInitConvexFolder(ctx);
591591
return { teamSlug, projectSlug, devDeployment };
592592
}
593593

@@ -640,9 +640,6 @@ async function selectExistingProject(
640640
: undefined,
641641
});
642642

643-
showSpinner(`Reinitializing project ${projectSlug}...\n`);
644-
// TODO: Do we need to do codegen for existing projects? (-Ian)
645-
await doInitialCodegen(ctx, { init: false });
646643
logFinishedStep(`Reinitialized project ${chalkStderr.bold(projectSlug)}`);
647644
return { teamSlug, projectSlug, devDeployment };
648645
}

src/cli/lib/codegen.ts

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@ import {
2424
} from "../../bundler/log.js";
2525
import { typeCheckFunctionsInMode, TypeCheckMode } from "./typecheck.js";
2626
import {
27-
configFilepath,
2827
readProjectConfig,
2928
usesTypeScriptCodegen,
3029
usesComponentApiImports,
3130
} from "./config.js";
3231
import { recursivelyDelete } from "./fsUtils.js";
3332
import { componentServerTS } from "../codegen_templates/component_server.js";
34-
import {
35-
ComponentDirectory,
36-
isComponentDirectory,
37-
} from "./components/definition/directoryStructure.js";
33+
import { ComponentDirectory } from "./components/definition/directoryStructure.js";
3834
import { StartPushResponse } from "./deployApi/startPush.js";
3935
import {
4036
componentApiDTS,
@@ -63,46 +59,26 @@ export type CodegenOptions = {
6359
codegenOnlyThisComponent?: string | undefined;
6460
};
6561

66-
export async function doInitialCodegen(
62+
export async function doInitConvexFolder(
6763
ctx: Context,
68-
options: { init: boolean },
64+
functionsFolder?: string,
65+
opts?: {
66+
dryRun?: boolean;
67+
debug?: boolean;
68+
},
6969
) {
70-
const { projectConfig: existingProjectConfig } = await readProjectConfig(ctx);
71-
const configPath = await configFilepath(ctx);
72-
const functionsPath = functionsDir(configPath, existingProjectConfig);
73-
if (options.init) {
74-
await doInitCodegen(ctx, functionsPath, true);
75-
}
76-
77-
const componentDir = isComponentDirectory(ctx, functionsPath, true);
78-
if (componentDir.kind === "err") {
79-
return await ctx.crash({
80-
exitCode: 1,
81-
errorType: "invalid filesystem data",
82-
printedMessage: `Invalid component directory: ${componentDir.why}`,
83-
});
84-
}
85-
86-
if (componentDir.component.isRootWithoutConfig) {
87-
// Disable typechecking since there isn't any code yet.
88-
await doCodegen(ctx, functionsPath, "disable");
70+
const skipIfExists = false; // Not currently configured
71+
let folder: string;
72+
if (functionsFolder) {
73+
folder = functionsFolder;
8974
} else {
90-
await withTmpDir(async (tmpDir) => {
91-
await doInitialComponentCodegen(ctx, tmpDir, componentDir.component);
92-
});
75+
const { projectConfig, configPath } = await readProjectConfig(ctx);
76+
folder = functionsDir(configPath, projectConfig);
9377
}
94-
}
95-
96-
export async function doInitCodegen(
97-
ctx: Context,
98-
functionsDir: string,
99-
skipIfExists: boolean,
100-
opts?: { dryRun?: boolean; debug?: boolean },
101-
): Promise<void> {
102-
await prepareForCodegen(ctx, functionsDir, opts);
78+
await prepareForCodegen(ctx, folder, opts);
10379
await withTmpDir(async (tmpDir) => {
104-
await doReadmeCodegen(ctx, tmpDir, functionsDir, skipIfExists, opts);
105-
await doTsconfigCodegen(ctx, tmpDir, functionsDir, skipIfExists, opts);
80+
await doReadmeCodegen(ctx, tmpDir, folder, skipIfExists, opts);
81+
await doTsconfigCodegen(ctx, tmpDir, folder, skipIfExists, opts);
10682
});
10783
}
10884

src/cli/lib/components.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
doFinalComponentCodegen,
3333
doInitialComponentCodegen,
3434
CodegenOptions,
35-
doInitCodegen,
35+
doInitConvexFolder,
3636
doCodegen,
3737
} from "./codegen.js";
3838
import {
@@ -87,7 +87,7 @@ export async function runCodegen(
8787
const functionsDirectoryPath = functionsDir(configPath, projectConfig);
8888

8989
if (options.init) {
90-
await doInitCodegen(ctx, functionsDirectoryPath, false, {
90+
await doInitConvexFolder(ctx, functionsDirectoryPath, {
9191
dryRun: options.dryRun,
9292
debug: options.debug,
9393
});

src/cli/lib/localDeployment/anonymous.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { isAnonymousDeployment } from "../deployment.js";
4343
import { createProject } from "../api.js";
4444
import { removeAnonymousPrefix } from "../deployment.js";
4545
import { nodeFs } from "../../../bundler/fs.js";
46-
import { doInitialCodegen } from "../codegen.js";
46+
import { doInitConvexFolder } from "../codegen.js";
4747

4848
export async function handleAnonymousDeployment(
4949
ctx: Context,
@@ -178,7 +178,7 @@ export async function handleAnonymousDeployment(
178178
});
179179

180180
if (deployment.kind === "new") {
181-
await doInitialCodegen(ctx, { init: true });
181+
await doInitConvexFolder(ctx);
182182
}
183183
return {
184184
adminKey,

0 commit comments

Comments
 (0)