This commit is contained in:
Aman Varshney
2025-04-14 21:45:28 +05:30
parent 8b03441909
commit 7f441ef670
268 changed files with 3513 additions and 3039 deletions

View File

@@ -0,0 +1,58 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectApi, ProjectFrontend } from "../types";
export async function getApiChoice(
Api?: ProjectApi | undefined,
frontend?: ProjectFrontend[],
): Promise<ProjectApi> {
if (Api) return Api;
const includesNative = frontend?.includes("native");
let apiOptions = [
{
value: "trpc" as const,
label: "tRPC",
hint: "End-to-end typesafe APIs made easy",
},
{
value: "orpc" as const,
label: "oRPC",
hint: "End-to-end type-safe APIs that adhere to OpenAPI standards",
},
{
value: "none" as const,
label: "None",
hint: "No API integration (skip API setup)",
},
];
if (includesNative) {
apiOptions = [
{
value: "trpc" as const,
label: "tRPC",
hint: "End-to-end typesafe APIs made easy (Required for Native frontend)",
},
];
}
const apiType = await select<ProjectApi>({
message: "Select API type",
options: apiOptions,
initialValue: includesNative ? "trpc" : DEFAULT_CONFIG.api,
});
if (isCancel(apiType)) {
cancel(pc.red("Operation cancelled"));
process.exit(0);
}
if (includesNative && apiType !== "trpc") {
return "trpc";
}
return apiType;
}