mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
58 lines
1.1 KiB
TypeScript
58 lines
1.1 KiB
TypeScript
import { cancel, isCancel, select } from "@clack/prompts";
|
|
import pc from "picocolors";
|
|
import { DEFAULT_CONFIG } from "../constants";
|
|
import type { Backend, Runtime } from "../types";
|
|
|
|
export async function getRuntimeChoice(
|
|
runtime?: Runtime,
|
|
backend?: Backend,
|
|
): Promise<Runtime> {
|
|
if (backend === "convex" || backend === "none") {
|
|
return "none";
|
|
}
|
|
|
|
if (runtime !== undefined) return runtime;
|
|
|
|
if (backend === "next") {
|
|
return "node";
|
|
}
|
|
|
|
const runtimeOptions: Array<{
|
|
value: Runtime;
|
|
label: string;
|
|
hint: string;
|
|
}> = [
|
|
{
|
|
value: "bun",
|
|
label: "Bun",
|
|
hint: "Fast all-in-one JavaScript runtime",
|
|
},
|
|
{
|
|
value: "node",
|
|
label: "Node.js",
|
|
hint: "Traditional Node.js runtime",
|
|
},
|
|
];
|
|
|
|
if (backend === "hono") {
|
|
runtimeOptions.push({
|
|
value: "workers",
|
|
label: "Cloudflare Workers (beta)",
|
|
hint: "Edge runtime on Cloudflare's global network",
|
|
});
|
|
}
|
|
|
|
const response = await select<Runtime>({
|
|
message: "Select runtime",
|
|
options: runtimeOptions,
|
|
initialValue: DEFAULT_CONFIG.runtime,
|
|
});
|
|
|
|
if (isCancel(response)) {
|
|
cancel(pc.red("Operation cancelled"));
|
|
process.exit(0);
|
|
}
|
|
|
|
return response;
|
|
}
|