add cloudflare workers support (#326)

This commit is contained in:
Aman Varshney
2025-06-16 22:55:26 +05:30
committed by GitHub
parent 5fc1ba164e
commit b34e94a09e
34 changed files with 556 additions and 538 deletions

View File

@@ -57,13 +57,14 @@ export async function gatherConfig(
runtime: ({ results }) =>
getRuntimeChoice(flags.runtime, results.backend),
database: ({ results }) =>
getDatabaseChoice(flags.database, results.backend),
getDatabaseChoice(flags.database, results.backend, results.runtime),
orm: ({ results }) =>
getORMChoice(
flags.orm,
results.database !== "none",
results.database,
results.backend,
results.runtime,
),
api: ({ results }) =>
getApiChoice(flags.api, results.frontend, results.backend),

View File

@@ -1,11 +1,12 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { Backend, Database } from "../types";
import type { Backend, Database, Runtime } from "../types";
export async function getDatabaseChoice(
database?: Database,
backend?: Backend,
runtime?: Runtime,
): Promise<Database> {
if (backend === "convex" || backend === "none") {
return "none";
@@ -13,35 +14,44 @@ export async function getDatabaseChoice(
if (database !== undefined) return database;
const databaseOptions: Array<{
value: Database;
label: string;
hint: string;
}> = [
{
value: "none",
label: "None",
hint: "No database setup",
},
{
value: "sqlite",
label: "SQLite",
hint: "lightweight, server-less, embedded relational database",
},
{
value: "postgres",
label: "PostgreSQL",
hint: "powerful, open source object-relational database system",
},
{
value: "mysql",
label: "MySQL",
hint: "popular open-source relational database system",
},
];
if (runtime !== "workers") {
databaseOptions.push({
value: "mongodb",
label: "MongoDB",
hint: "open-source NoSQL database that stores data in JSON-like documents called BSON",
});
}
const response = await select<Database>({
message: "Select database",
options: [
{
value: "none",
label: "None",
hint: "No database setup",
},
{
value: "sqlite",
label: "SQLite",
hint: "lightweight, server-less, embedded relational database",
},
{
value: "postgres",
label: "PostgreSQL",
hint: "powerful, open source object-relational database system",
},
{
value: "mysql",
label: "MySQL",
hint: "popular open-source relational database system",
},
{
value: "mongodb",
label: "MongoDB",
hint: "open-source NoSQL database that stores data in JSON-like documents called BSON",
},
],
options: databaseOptions,
initialValue: DEFAULT_CONFIG.database,
});

View File

@@ -1,7 +1,7 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { Backend, Database, ORM } from "../types";
import type { Backend, Database, ORM, Runtime } from "../types";
const ormOptions = {
prisma: {
@@ -26,6 +26,7 @@ export async function getORMChoice(
hasDatabase: boolean,
database?: Database,
backend?: Backend,
runtime?: Runtime,
): Promise<ORM> {
if (backend === "convex") {
return "none";
@@ -34,6 +35,10 @@ export async function getORMChoice(
if (!hasDatabase) return "none";
if (orm !== undefined) return orm;
if (runtime === "workers") {
return "drizzle";
}
const options = [
...(database === "mongodb"
? [ormOptions.prisma, ormOptions.mongoose]

View File

@@ -17,20 +17,34 @@ export async function getRuntimeChoice(
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: [
{
value: "bun",
label: "Bun",
hint: "Fast all-in-one JavaScript runtime",
},
{
value: "node",
label: "Node.js",
hint: "Traditional Node.js runtime",
},
],
options: runtimeOptions,
initialValue: DEFAULT_CONFIG.runtime,
});