Add runtime selection feature between Bun and Node.js

This commit is contained in:
Aman Varshney
2025-03-26 01:40:39 +05:30
parent 45cd2fc113
commit 88afd53a4d
22 changed files with 10432 additions and 224 deletions

View File

@@ -0,0 +1,30 @@
// import { cancel, isCancel, select } from "@clack/prompts";
// import pc from "picocolors";
import type { BackendFramework } from "../types";
export async function getBackendFrameworkChoice(
backendFramework?: BackendFramework,
): Promise<BackendFramework> {
if (backendFramework !== undefined) return backendFramework;
return "hono";
// const response = await select<BackendFramework>({
// message: "Which backend framework would you like to use?",
// options: [
// {
// value: "hono",
// label: "Hono",
// hint: "Lightweight, ultrafast web framework",
// },
// ],
// initialValue: "hono",
// });
// if (isCancel(response)) {
// cancel(pc.red("Operation cancelled"));
// process.exit(0);
// }
// return response;
}

View File

@@ -1,15 +1,18 @@
import { cancel, group } from "@clack/prompts";
import pc from "picocolors";
import type {
BackendFramework,
PackageManager,
ProjectAddons,
ProjectConfig,
ProjectDatabase,
ProjectExamples,
ProjectOrm,
Runtime,
} from "../types";
import { getAddonsChoice } from "./addons";
import { getAuthChoice } from "./auth";
import { getBackendFrameworkChoice } from "./backend-framework";
import { getDatabaseChoice } from "./database";
import { getExamplesChoice } from "./examples";
import { getGitChoice } from "./git";
@@ -17,9 +20,10 @@ import { getNoInstallChoice } from "./install";
import { getORMChoice } from "./orm";
import { getPackageManagerChoice } from "./package-manager";
import { getProjectName } from "./project-name";
import { getRuntimeChoice } from "./runtime";
import { getTursoSetupChoice } from "./turso";
interface PromptGroupResults {
type PromptGroupResults = {
projectName: string;
database: ProjectDatabase;
orm: ProjectOrm;
@@ -30,7 +34,9 @@ interface PromptGroupResults {
packageManager: PackageManager;
noInstall: boolean;
turso: boolean;
}
backendFramework: BackendFramework;
runtime: Runtime;
};
export async function gatherConfig(
flags: Partial<ProjectConfig>,
@@ -40,6 +46,8 @@ export async function gatherConfig(
projectName: async () => {
return getProjectName(flags.projectName);
},
runtime: () => getRuntimeChoice(flags.runtime),
backendFramework: () => getBackendFrameworkChoice(flags.backendFramework),
database: () => getDatabaseChoice(flags.database),
orm: ({ results }) =>
getORMChoice(flags.orm, results.database !== "none"),
@@ -75,5 +83,7 @@ export async function gatherConfig(
packageManager: result.packageManager,
noInstall: result.noInstall,
turso: result.turso,
backendFramework: result.backendFramework,
runtime: result.runtime,
};
}

View File

@@ -1,6 +1,6 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import type { PackageManager } from "../types";
import type { PackageManager, Runtime } from "../types";
import { getUserPkgManager } from "../utils/get-package-manager";
export async function getPackageManagerChoice(

View File

@@ -0,0 +1,31 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import type { Runtime } from "../types";
export async function getRuntimeChoice(runtime?: Runtime): Promise<Runtime> {
if (runtime !== undefined) return runtime;
const response = await select<Runtime>({
message: "Which runtime would you like to use?",
options: [
{
value: "bun",
label: "Bun",
hint: "Fast all-in-one JavaScript runtime",
},
{
value: "node",
label: "Node.js",
hint: "Traditional Node.js runtime",
},
],
initialValue: "bun",
});
if (isCancel(response)) {
cancel(pc.red("Operation cancelled"));
process.exit(0);
}
return response;
}