add convex

This commit is contained in:
Aman Varshney
2025-04-28 11:42:11 +05:30
parent 7ef3cfce9e
commit 2a5358a105
70 changed files with 2330 additions and 1139 deletions

View File

@@ -1,12 +1,17 @@
import { cancel, isCancel, select } from "@clack/prompts";
import { cancel, isCancel, log, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectApi, ProjectFrontend } from "../types";
import type { ProjectApi, ProjectBackend, ProjectFrontend } from "../types";
export async function getApiChoice(
Api?: ProjectApi | undefined,
frontend?: ProjectFrontend[],
backend?: ProjectBackend,
): Promise<ProjectApi> {
if (backend === "convex") {
return "none";
}
if (Api) return Api;
const includesNuxt = frontend?.includes("nuxt");

View File

@@ -1,11 +1,17 @@
import { cancel, confirm, isCancel } from "@clack/prompts";
import { cancel, confirm, isCancel, log } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectBackend } from "../types";
export async function getAuthChoice(
auth: boolean | undefined,
hasDatabase: boolean,
backend?: ProjectBackend,
): Promise<boolean> {
if (backend === "convex") {
return false;
}
if (!hasDatabase) return false;
if (auth !== undefined) return auth;

View File

@@ -31,6 +31,11 @@ export async function getBackendFrameworkChoice(
label: "Elysia",
hint: "Ergonomic web framework for building backend servers",
},
{
value: "convex",
label: "Convex",
hint: "Reactive backend-as-a-service platform",
},
],
initialValue: DEFAULT_CONFIG.backend,
});

View File

@@ -30,19 +30,19 @@ import { getRuntimeChoice } from "./runtime";
type PromptGroupResults = {
projectName: string;
frontend: ProjectFrontend[];
backend: ProjectBackend;
runtime: ProjectRuntime;
database: ProjectDatabase;
orm: ProjectOrm;
api: ProjectApi;
auth: boolean;
addons: ProjectAddons[];
examples: ProjectExamples[];
dbSetup: ProjectDBSetup;
git: boolean;
packageManager: ProjectPackageManager;
install: boolean;
dbSetup: ProjectDBSetup;
backend: ProjectBackend;
runtime: ProjectRuntime;
frontend: ProjectFrontend[];
api: ProjectApi;
};
export async function gatherConfig(
@@ -57,12 +57,19 @@ export async function gatherConfig(
backend: () => getBackendFrameworkChoice(flags.backend),
runtime: ({ results }) =>
getRuntimeChoice(flags.runtime, results.backend),
database: () => getDatabaseChoice(flags.database),
database: ({ results }) =>
getDatabaseChoice(flags.database, results.backend),
orm: ({ results }) =>
getORMChoice(flags.orm, results.database !== "none", results.database),
api: ({ results }) => getApiChoice(flags.api, results.frontend),
getORMChoice(
flags.orm,
results.database !== "none",
results.database,
results.backend,
),
api: ({ results }) =>
getApiChoice(flags.api, results.frontend, results.backend),
auth: ({ results }) =>
getAuthChoice(flags.auth, results.database !== "none"),
getAuthChoice(flags.auth, results.database !== "none", results.backend),
addons: ({ results }) => getAddonsChoice(flags.addons, results.frontend),
examples: ({ results }) =>
getExamplesChoice(
@@ -76,6 +83,7 @@ export async function gatherConfig(
results.database ?? "none",
flags.dbSetup,
results.orm,
results.backend,
),
git: () => getGitChoice(flags.git),
packageManager: () => getPackageManagerChoice(flags.packageManager),
@@ -89,9 +97,20 @@ export async function gatherConfig(
},
);
if (result.backend === "convex") {
result.runtime = "none";
result.database = "none";
result.orm = "none";
result.api = "none";
result.auth = false;
result.dbSetup = "none";
}
return {
projectName: result.projectName,
frontend: result.frontend,
backend: result.backend,
runtime: result.runtime,
database: result.database,
orm: result.orm,
auth: result.auth,
@@ -101,8 +120,6 @@ export async function gatherConfig(
packageManager: result.packageManager,
install: result.install,
dbSetup: result.dbSetup,
backend: result.backend,
runtime: result.runtime,
api: result.api,
};
}

View File

@@ -1,11 +1,16 @@
import { cancel, isCancel, select } from "@clack/prompts";
import { cancel, isCancel, log, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectDatabase } from "../types";
import type { ProjectBackend, ProjectDatabase } from "../types";
export async function getDatabaseChoice(
database?: ProjectDatabase,
backend?: ProjectBackend,
): Promise<ProjectDatabase> {
if (backend === "convex") {
return "none";
}
if (database !== undefined) return database;
const response = await select<ProjectDatabase>({

View File

@@ -1,14 +1,23 @@
import { cancel, isCancel, select } from "@clack/prompts";
import { cancel, isCancel, log, select } from "@clack/prompts";
import pc from "picocolors";
import type { ProjectDBSetup, ProjectOrm } from "../types";
import type { ProjectBackend, ProjectDBSetup, ProjectOrm } from "../types";
export async function getDBSetupChoice(
databaseType: string,
dbSetup: ProjectDBSetup | undefined,
orm?: ProjectOrm,
backend?: ProjectBackend,
): Promise<ProjectDBSetup> {
if (backend === "convex") {
return "none";
}
if (dbSetup !== undefined) return dbSetup as ProjectDBSetup;
if (databaseType === "none") {
return "none";
}
if (databaseType === "sqlite" && orm === "prisma") {
return "none";
}

View File

@@ -1,4 +1,4 @@
import { cancel, isCancel, multiselect } from "@clack/prompts";
import { cancel, isCancel, log, multiselect } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type {
@@ -16,17 +16,32 @@ export async function getExamplesChoice(
): Promise<ProjectExamples[]> {
if (examples !== undefined) return examples;
if (backend === "convex") {
return ["todo"];
}
if (database === "none") return [];
const hasWebFrontend =
frontends?.includes("react-router") ||
frontends?.includes("tanstack-router") ||
frontends?.includes("tanstack-start") ||
frontends?.includes("next") ||
frontends?.includes("nuxt") ||
frontends?.includes("svelte");
const onlyNative =
frontends && frontends.length === 1 && frontends[0] === "native";
if (onlyNative) {
return [];
}
if (!hasWebFrontend) return [];
const hasWebFrontend =
frontends?.some((f) =>
[
"react-router",
"tanstack-router",
"tanstack-start",
"next",
"nuxt",
"svelte",
].includes(f),
) ?? false;
const noFrontendSelected = !frontends || frontends.length === 0;
if (!hasWebFrontend && !noFrontendSelected) return [];
let response: ProjectExamples[] | symbol = [];
const options: { value: ProjectExamples; label: string; hint: string }[] = [

View File

@@ -1,13 +1,18 @@
import { cancel, isCancel, log, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectDatabase, ProjectOrm } from "../types";
import type { ProjectBackend, ProjectDatabase, ProjectOrm } from "../types";
export async function getORMChoice(
orm: ProjectOrm | undefined,
hasDatabase: boolean,
database?: ProjectDatabase,
backend?: ProjectBackend,
): Promise<ProjectOrm> {
if (backend === "convex") {
return "none";
}
if (!hasDatabase) return "none";
if (orm !== undefined) return orm;

View File

@@ -1,4 +1,4 @@
import { cancel, isCancel, select } from "@clack/prompts";
import { cancel, isCancel, log, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectBackend, ProjectRuntime } from "../types";
@@ -7,6 +7,10 @@ export async function getRuntimeChoice(
runtime?: ProjectRuntime,
backend?: ProjectBackend,
): Promise<ProjectRuntime> {
if (backend === "convex") {
return "none";
}
if (runtime !== undefined) return runtime;
if (backend === "next") {