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:
@@ -29,6 +29,11 @@ export async function getAddonsChoice(
|
||||
label: "Husky",
|
||||
hint: "Add Git hooks with Husky, lint-staged (requires Biome)",
|
||||
},
|
||||
{
|
||||
value: "turborepo" as const,
|
||||
label: "Turborepo",
|
||||
hint: "Optimize builds for monorepos",
|
||||
},
|
||||
];
|
||||
|
||||
const webAddonOptions = [
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import type { ProjectFrontend } from "../types";
|
||||
export async function getAuthChoice(
|
||||
auth: boolean | undefined,
|
||||
hasDatabase: boolean,
|
||||
frontends?: ProjectFrontend[],
|
||||
): Promise<boolean> {
|
||||
if (!hasDatabase) return false;
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { cancel, group, log } from "@clack/prompts";
|
||||
import { cancel, group } from "@clack/prompts";
|
||||
import pc from "picocolors";
|
||||
import type {
|
||||
ProjectAddons,
|
||||
ProjectApi,
|
||||
ProjectBackend,
|
||||
ProjectConfig,
|
||||
ProjectDBSetup,
|
||||
@@ -13,6 +14,7 @@ import type {
|
||||
ProjectRuntime,
|
||||
} from "../types";
|
||||
import { getAddonsChoice } from "./addons";
|
||||
import { getApiChoice } from "./api";
|
||||
import { getAuthChoice } from "./auth";
|
||||
import { getBackendFrameworkChoice } from "./backend-framework";
|
||||
import { getDatabaseChoice } from "./database";
|
||||
@@ -20,7 +22,7 @@ import { getDBSetupChoice } from "./db-setup";
|
||||
import { getExamplesChoice } from "./examples";
|
||||
import { getFrontendChoice } from "./frontend-option";
|
||||
import { getGitChoice } from "./git";
|
||||
import { getNoInstallChoice } from "./install";
|
||||
import { getinstallChoice } from "./install";
|
||||
import { getORMChoice } from "./orm";
|
||||
import { getPackageManagerChoice } from "./package-manager";
|
||||
import { getProjectName } from "./project-name";
|
||||
@@ -35,11 +37,12 @@ type PromptGroupResults = {
|
||||
examples: ProjectExamples[];
|
||||
git: boolean;
|
||||
packageManager: ProjectPackageManager;
|
||||
noInstall: boolean;
|
||||
install: boolean;
|
||||
dbSetup: ProjectDBSetup;
|
||||
backend: ProjectBackend;
|
||||
runtime: ProjectRuntime;
|
||||
frontend: ProjectFrontend[];
|
||||
api: ProjectApi;
|
||||
};
|
||||
|
||||
export async function gatherConfig(
|
||||
@@ -57,12 +60,9 @@ export async function gatherConfig(
|
||||
database: () => getDatabaseChoice(flags.database),
|
||||
orm: ({ results }) =>
|
||||
getORMChoice(flags.orm, results.database !== "none", results.database),
|
||||
api: ({ results }) => getApiChoice(flags.api, results.frontend),
|
||||
auth: ({ results }) =>
|
||||
getAuthChoice(
|
||||
flags.auth,
|
||||
results.database !== "none",
|
||||
results.frontend,
|
||||
),
|
||||
getAuthChoice(flags.auth, results.database !== "none"),
|
||||
addons: ({ results }) => getAddonsChoice(flags.addons, results.frontend),
|
||||
examples: ({ results }) =>
|
||||
getExamplesChoice(
|
||||
@@ -79,7 +79,7 @@ export async function gatherConfig(
|
||||
),
|
||||
git: () => getGitChoice(flags.git),
|
||||
packageManager: () => getPackageManagerChoice(flags.packageManager),
|
||||
noInstall: () => getNoInstallChoice(flags.noInstall),
|
||||
install: () => getinstallChoice(flags.install),
|
||||
},
|
||||
{
|
||||
onCancel: () => {
|
||||
@@ -99,9 +99,10 @@ export async function gatherConfig(
|
||||
examples: result.examples,
|
||||
git: result.git,
|
||||
packageManager: result.packageManager,
|
||||
noInstall: result.noInstall,
|
||||
install: result.install,
|
||||
dbSetup: result.dbSetup,
|
||||
backend: result.backend,
|
||||
runtime: result.runtime,
|
||||
api: result.api,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,14 +2,12 @@ import { cancel, confirm, isCancel } from "@clack/prompts";
|
||||
import pc from "picocolors";
|
||||
import { DEFAULT_CONFIG } from "../constants";
|
||||
|
||||
export async function getNoInstallChoice(
|
||||
noInstall?: boolean,
|
||||
): Promise<boolean> {
|
||||
if (noInstall !== undefined) return noInstall;
|
||||
export async function getinstallChoice(install?: boolean): Promise<boolean> {
|
||||
if (install !== undefined) return install;
|
||||
|
||||
const response = await confirm({
|
||||
message: "Install dependencies?",
|
||||
initialValue: !DEFAULT_CONFIG.noInstall,
|
||||
initialValue: DEFAULT_CONFIG.install,
|
||||
});
|
||||
|
||||
if (isCancel(response)) {
|
||||
@@ -17,5 +15,5 @@ export async function getNoInstallChoice(
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
return !response;
|
||||
return response;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user