import path from "node:path"; import type { Assets } from "./assets.js"; import type { Bindings } from "./bindings.js"; import { Website, type WebsiteProps } from "./website.js"; import type { Worker } from "./worker.js"; export interface RedwoodProps extends WebsiteProps {} // don't allow the ASSETS to be overridden export type Redwood = B extends { ASSETS: any } ? never : Worker; /** * Deploy a RedwoodJS application to Cloudflare Pages with automatically configured defaults. * * This resource handles the deployment of RedwoodJS applications with optimized settings for * Cloudflare Workers, including proper build commands and compatibility flags. * * @example * // Deploy a basic RedwoodJS application with default settings * const redwoodApp = await Redwood("my-redwood-app"); * * @example * // Deploy with a database binding * import { D1Database } from alchemy/cloudflare"; * * const database = await D1Database("redwood-db"); * * const redwoodApp = await Redwood("redwood-with-db", { * bindings: { * DB: database * } * }); * * @param id - Unique identifier for the RedwoodJS application * @param props - Configuration properties for the RedwoodJS deployment * @returns A Cloudflare Worker resource representing the deployed RedwoodJS application */ export async function Redwood( id: string, props?: Partial> ): Promise> { return Website(id, { ...props, command: props?.command ?? "bun run clean && RWSDK_DEPLOY=1 bun run build", wrangler: props?.wrangler === false ? false : { main: props?.main ?? path.join("src", "worker.tsx"), }, main: props?.main ?? path.join("dist", "worker", "worker.js"), assets: props?.assets ?? path.join("dist", "client"), compatibilityFlags: ["nodejs_compat", ...(props?.compatibilityFlags ?? [])], compatibilityDate: props?.compatibilityDate ?? "2025-04-02", }); }