mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
add orpc
This commit is contained in:
58
apps/cli/src/prompts/api.ts
Normal file
58
apps/cli/src/prompts/api.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user