dont allow examples when api is none (#243)

This commit is contained in:
Aman Varshney
2025-05-10 22:28:05 +05:30
committed by GitHub
parent 2924b817a3
commit 6a339bca1f
12 changed files with 188 additions and 241 deletions

View File

@@ -1,6 +1,5 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectApi, ProjectBackend, ProjectFrontend } from "../types";
export async function getApiChoice(
@@ -29,6 +28,11 @@ export async function getApiChoice(
label: "oRPC",
hint: "End-to-end type-safe APIs that adhere to OpenAPI standards",
},
{
value: "none" as const,
label: "None",
hint: "No API layer (e.g. for full-stack frameworks like Next.js with Route Handlers)",
},
];
if (includesNuxt || includesSvelte || includesSolid) {
@@ -36,20 +40,22 @@ export async function getApiChoice(
{
value: "orpc" as const,
label: "oRPC",
hint: `End-to-end type-safe APIs (Required for ${
hint: `End-to-end type-safe APIs (Recommended for ${
includesNuxt ? "Nuxt" : includesSvelte ? "Svelte" : "Solid"
} frontend)`,
},
{
value: "none" as const,
label: "None",
hint: "No API layer",
},
];
}
const apiType = await select<ProjectApi>({
message: "Select API type",
options: apiOptions,
initialValue:
includesNuxt || includesSvelte || includesSolid
? "orpc"
: DEFAULT_CONFIG.api,
initialValue: apiOptions[0].value,
});
if (isCancel(apiType)) {
@@ -57,9 +63,5 @@ export async function getApiChoice(
process.exit(0);
}
if ((includesNuxt || includesSvelte || includesSolid) && apiType !== "orpc") {
return "orpc";
}
return apiType;
}

View File

@@ -77,6 +77,7 @@ export async function gatherConfig(
results.database,
results.frontend,
results.backend,
results.api,
),
dbSetup: ({ results }) =>
getDBSetupChoice(

View File

@@ -2,6 +2,7 @@ import { cancel, isCancel, multiselect } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type {
ProjectApi,
ProjectBackend,
ProjectDatabase,
ProjectExamples,
@@ -13,7 +14,11 @@ export async function getExamplesChoice(
database?: ProjectDatabase,
frontends?: ProjectFrontend[],
backend?: ProjectBackend,
api?: ProjectApi,
): Promise<ProjectExamples[]> {
if (api === "none") {
return [];
}
if (examples !== undefined) return examples;
if (backend === "convex") {