The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import { initialCwd } from "../Util/Node.ts"; |
| 3 | |
| 4 | export interface AstroOutputProps { |
| 5 | /** Project root, relative to the initial working directory. */ |
| 6 | readonly rootDir?: string | undefined; |
| 7 | /** Alternate astro config file, relative to {@link rootDir}. */ |
| 8 | readonly config?: string | undefined; |
| 9 | /** The composite's `astro.output` prop. */ |
| 10 | readonly output?: "server" | "static" | undefined; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * Resolves the Astro `output` a website composite deploys: the |
| 15 | * `astro.output` prop, else the `output` declared in the project's |
| 16 | * `astro.config.*`, else `"server"`. Composites decide at plan time whether |
| 17 | * a site is assets-only, so the config file is read here rather than left |
| 18 | * to the build. |
| 19 | * |
| 20 | * `@alchemy.run/frontend-frameworks` is an optional peer dependency, so it |
| 21 | * is imported lazily. When it is missing or the config cannot be loaded the |
| 22 | * site falls back to `"server"` (the build reports the real error). |
| 23 | */ |
| 24 | export const resolveAstroOutput = Effect.fn("Website.resolveAstroOutput")(function* ( |
| 25 | props: AstroOutputProps, |
| 26 | ) { |
| 27 | if (props.output !== undefined) return props.output; |
| 28 | const declared = yield* Effect.tryPromise( |
| 29 | () => import("@alchemy.run/frontend-frameworks/astro/config"), |
| 30 | ).pipe( |
| 31 | Effect.flatMap((astro) => |
| 32 | astro.readConfigOutput({ cwd: initialCwd, rootDir: props.rootDir, config: props.config }), |
| 33 | ), |
| 34 | Effect.catch((error) => |
| 35 | Effect.logWarning( |
| 36 | `Could not read \`output\` from the Astro config in "${props.rootDir ?? "."}"; deploying with "server"`, |
| 37 | error, |
| 38 | ).pipe(Effect.as(undefined)), |
| 39 | ), |
| 40 | ); |
| 41 | return declared ?? "server"; |
| 42 | }); |
| 43 | |
| 44 | export interface AstroSettings { |
| 45 | /** The resolved `output` (see {@link resolveAstroOutput}). */ |
| 46 | readonly output: "server" | "static"; |
| 47 | /** |
| 48 | * Whether the Astro config routes caching through the Cloudflare cache |
| 49 | * provider (`cacheCloudflare()`), so the Worker needs Workers Cache on. |
| 50 | */ |
| 51 | readonly workerCache: boolean; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Resolves the Astro settings a Cloudflare composite deploys from one read |
| 56 | * of the project's `astro.config.*`: the `output` (as |
| 57 | * {@link resolveAstroOutput}) and whether the config uses the Cloudflare |
| 58 | * cache provider. When the config cannot be loaded the site falls back to |
| 59 | * `"server"` without Workers Cache (the build reports the real error). |
| 60 | */ |
| 61 | export const resolveAstroSettings = Effect.fn("Website.resolveAstroSettings")(function* ( |
| 62 | props: AstroOutputProps, |
| 63 | ) { |
| 64 | const declared = yield* Effect.tryPromise( |
| 65 | () => import("@alchemy.run/frontend-frameworks/astro/config"), |
| 66 | ).pipe( |
| 67 | Effect.flatMap((astro) => |
| 68 | astro.readConfigSettings({ cwd: initialCwd, rootDir: props.rootDir, config: props.config }), |
| 69 | ), |
| 70 | Effect.catch((error) => |
| 71 | Effect.logWarning( |
| 72 | `Could not read the Astro config in "${props.rootDir ?? "."}"; deploying with ${ |
| 73 | props.output === undefined ? '"server"' : `"${props.output}"` |
| 74 | } and without Workers Cache`, |
| 75 | error, |
| 76 | ).pipe(Effect.as(undefined)), |
| 77 | ), |
| 78 | ); |
| 79 | return { |
| 80 | output: props.output ?? declared?.output ?? "server", |
| 81 | workerCache: declared?.workerCache ?? false, |
| 82 | } satisfies AstroSettings; |
| 83 | }); |