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

main
ts 101 lines 3.37 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
20 * Node 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;
29 * `"static"` prerenders every page at build time and deploys
30 * assets-only (no SSR unit). Overrides the `output` in your
31 * `astro.config.*`; leave it unset to use the file's value.
32 * @default the config file's `output`, else `"server"`
33 */
34 output?: "server" | "static";
35 /** Source directory, relative to `rootDir`. @default "./src" */
36 srcDir?: string;
37 /** Public (static passthrough) directory. @default "./public" */
38 publicDir?: string;
39 /** Build output directory. @default "./dist" */
40 outDir?: string;
41 /** Trailing-slash handling for routes. */
42 trailingSlash?: "always" | "never" | "ignore";
43 };
44 }
45
46 /**
47 * Deploy an [Astro](https://astro.build) application to a Hetzner Cloud
48 * Server: the Node adapter bundle as a systemd unit on port 3000, static
49 * assets baked into the unit. Pages render on demand by default
50 * (`output: "server"`); `output: "static"` in your `astro.config.*` or
51 * `astro: { output: "static" }` prerenders every page and deploys
52 * assets-only.
53 *
54 * The build runs through `@alchemy.run/frontend-frameworks/astro` with the
55 * `@alchemy.run/frontend-frameworks/astro/node` deploy target. Your
56 * `astro.config.*` must not declare an adapter.
57 *
58 *
59 * ### Creating Astro Sites
60 * **Example:** Basic Astro App
61 * ```typescript
62 * const site = yield* Hetzner.Website.Astro("Web", {
63 * rootDir: "./app",
64 * });
65 * ```
66 *
67 * **Example:** Custom Domain
68 * ```typescript
69 * const site = yield* Hetzner.Website.Astro("Web", {
70 * rootDir: "./app",
71 * domain: "app.example.com",
72 * zone,
73 * });
74 * ```
75 *
76 * ### Static Sites
77 * **Example:** Fully Static Astro Site
78 * ```typescript
79 * const site = yield* Hetzner.Website.Astro("Docs", {
80 * rootDir: "./docs",
81 * astro: { output: "static" },
82 * assets: { notFoundHandling: "404-page" },
83 * });
84 * ```
85 *
86 * @resource
87 * @product Website
88 */
89 export const Astro = (id: string, props: AstroProps = {}) =>
90 resolveAstroOutput({ rootDir: props.rootDir, output: props.astro?.output }).pipe(
91 Effect.flatMap((output) =>
92 makeFrameworkSite(id, props, {
93 name: "Astro",
94 framework: ASTRO_FRAMEWORK_SPECIFIER,
95 target: ASTRO_NODE_TARGET_SPECIFIER,
96 options: { astro: { ...props.astro, output } },
97 static: output === "static" ? staticConfigFromAssets(props.assets) : undefined,
98 }),
99 ),
100 Namespace.push(id),
101 );