The best way to control Claude Code, Codex and more from any computer or phone

main
ts 109 lines 3.8 KB
Raw
1 import * as Namespace from "alchemy/Namespace";
2 import { resolveAstroOutput } from "alchemy/Website/AstroOutput";
3 import * as Effect from "effect/Effect";
4 import {
5 makeFrameworkSite,
6 staticConfigFromAssets,
7 type FrameworkSiteProps,
8 } from "./FrameworkSite.ts";
9
10 /** The framework-integration package that drives the Astro build. */
11 export const ASTRO_FRAMEWORK_SPECIFIER = "@alchemy.run/frontend-frameworks/astro";
12
13 /** The Node container deploy target for the Astro build. */
14 export const ASTRO_NODE_TARGET_SPECIFIER = "@alchemy.run/frontend-frameworks/astro/node";
15
16 export interface AstroProps extends FrameworkSiteProps {
17 /**
18 * Serializable Astro config merged OVER the project's own
19 * `astro.config.*` (which loads natively). `adapter` is owned by the Node
20 * deploy target and may not be set here.
21 */
22 astro?: {
23 /** The full URL the site deploys to (`Astro.site`). */
24 site?: string;
25 /** Base path the site deploys under. */
26 base?: string;
27 /**
28 * Astro output target. `"server"` renders pages on demand in the
29 * container; individual pages opt into prerendering with
30 * `export const prerender = true`. `"static"` prerenders every page at
31 * build time and deploys assets-only (no framework handler). Overrides
32 * the `output` in your `astro.config.*`; leave it unset to use the
33 * file's value.
34 * @default the config file's `output`, else `"server"`
35 */
36 output?: "server" | "static";
37 /** Source directory, relative to `rootDir`. @default "./src" */
38 srcDir?: string;
39 /** Public (static passthrough) directory. @default "./public" */
40 publicDir?: string;
41 /** Build output directory. @default "./dist" */
42 outDir?: string;
43 /** Trailing-slash handling for routes. */
44 trailingSlash?: "always" | "never" | "ignore";
45 };
46 }
47
48 /**
49 * Deploy an [Astro](https://astro.build) application to Railway: the Node
50 * SSR bundle (assets first, then the Astro fetch handler) on one
51 * `Railway.Service`. Pages render on demand by default
52 * (`output: "server"`); pages that `export const prerender = true` are
53 * prerendered at build time and served as static files. When your
54 * `astro.config.*` or `astro: { output: "static" }` declares a static
55 * site, every page is prerendered and the deploy is assets-only.
56 *
57 * The build runs through `@alchemy.run/frontend-frameworks/astro` with the
58 * `@alchemy.run/frontend-frameworks/astro/node` deploy target (a Node
59 * adapter is injected — your `astro.config.*` must not declare one).
60 *
61 * During `alchemy dev` the site is Astro's own dev server and no cloud
62 * resources are created. `Alchemy.remote()` opts back into the live
63 * Service path.
64 *
65 * ### Creating Astro Sites
66 * **Example:** Basic Astro App
67 * ```typescript
68 * const site = yield* Railway.Website.Astro("Web", {
69 * rootDir: "./app",
70 * });
71 * ```
72 *
73 * ### Static Sites
74 * **Example:** Fully Static Astro Site
75 * ```typescript
76 * const site = yield* Railway.Website.Astro("Docs", {
77 * rootDir: "./docs",
78 * astro: { output: "static" },
79 * errorPage: "404.html",
80 * });
81 * ```
82 *
83 * ### Server Configuration
84 * **Example:** Process Environment
85 * ```typescript
86 * const site = yield* Railway.Website.Astro("Web", {
87 * rootDir: "./app",
88 * env: {
89 * API_BASE: "https://api.example.com",
90 * },
91 * });
92 * ```
93 *
94 * @resource
95 * @product Website
96 */
97 export const Astro = (id: string, props: AstroProps = {}) =>
98 resolveAstroOutput({ rootDir: props.rootDir, output: props.astro?.output }).pipe(
99 Effect.flatMap((output) =>
100 makeFrameworkSite(id, props, {
101 name: "Astro",
102 framework: ASTRO_FRAMEWORK_SPECIFIER,
103 target: ASTRO_NODE_TARGET_SPECIFIER,
104 options: { astro: { ...props.astro, output } },
105 static: output === "static" ? staticConfigFromAssets(props.assets) : undefined,
106 }),
107 ),
108 Namespace.push(id),
109 );