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, 03:37 UTC
| 1 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 2 | import * as GitHub from "@alchemy.run/github"; |
| 3 | import * as Alchemy from "alchemy"; |
| 4 | import * as Output from "alchemy/Output"; |
| 5 | import * as RemovalPolicy from "alchemy/RemovalPolicy"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as Layer from "effect/Layer"; |
| 8 | |
| 9 | export type WorkerEnv = Cloudflare.InferEnv<typeof Website>; |
| 10 | |
| 11 | const Website = Cloudflare.Website.StaticSite( |
| 12 | "Website", |
| 13 | Effect.gen(function* () { |
| 14 | const stack = yield* Alchemy.Stack; |
| 15 | const previewParent = stack.stage.startsWith("pr-") |
| 16 | ? yield* Cloudflare.Worker.ref("Website", { stage: "preview-base" }) |
| 17 | : undefined; |
| 18 | const name = |
| 19 | stack.stage === "preview-base" |
| 20 | ? "alchemy-website-preview" |
| 21 | : stack.stage === "main" |
| 22 | ? "alchemy-website-main" |
| 23 | : stack.stage === "prod" |
| 24 | ? "alchemy-website-prod" |
| 25 | : undefined; |
| 26 | |
| 27 | return { |
| 28 | name, |
| 29 | command: "bun run build", |
| 30 | main: "./src/worker.ts", |
| 31 | outdir: "dist", |
| 32 | preview: previewParent |
| 33 | ? { |
| 34 | of: previewParent, |
| 35 | name: stack.stage, |
| 36 | message: process.env.PULL_REQUEST ? `PR #${process.env.PULL_REQUEST}` : undefined, |
| 37 | } |
| 38 | : undefined, |
| 39 | workersDev: stack.stage === "prod" ? false : undefined, |
| 40 | domain: |
| 41 | stack.stage === "prod" |
| 42 | ? { |
| 43 | name: "alchemy.run", |
| 44 | redirects: ["v2.alchemy.run"], |
| 45 | previews: true, |
| 46 | } |
| 47 | : stack.stage === "main" |
| 48 | ? { name: "main.alchemy.run" } |
| 49 | : undefined, |
| 50 | memo: { |
| 51 | include: [ |
| 52 | "src/**", |
| 53 | "astro.config.mjs", |
| 54 | "package.json", |
| 55 | "plugins/**", |
| 56 | "public/**", |
| 57 | "scripts/**", |
| 58 | "../bun.lock", |
| 59 | ], |
| 60 | }, |
| 61 | compatibility: { |
| 62 | date: "2026-04-02", |
| 63 | flags: ["nodejs_compat"], |
| 64 | }, |
| 65 | assets: { |
| 66 | runWorkerFirst: true, |
| 67 | }, |
| 68 | } satisfies Cloudflare.Website.StaticSiteProps<{}>; |
| 69 | }), |
| 70 | ).pipe( |
| 71 | RemovalPolicy.retain(Alchemy.Stack.pipe(Effect.map(({ stage }) => !stage.startsWith("pr-")))), |
| 72 | ); |
| 73 | |
| 74 | export default Alchemy.Stack( |
| 75 | "AlchemyEffectWebsite", |
| 76 | { |
| 77 | providers: Layer.mergeAll(Cloudflare.providers(), GitHub.providers()), |
| 78 | state: Cloudflare.state(), |
| 79 | }, |
| 80 | Effect.gen(function* () { |
| 81 | const { stage } = yield* Alchemy.Stack; |
| 82 | const website = yield* Website; |
| 83 | |
| 84 | if (stage.startsWith("pr-")) { |
| 85 | yield* GitHub.Comment("preview-comment", { |
| 86 | owner: "alchemy-run", |
| 87 | repository: "alchemy", |
| 88 | issueNumber: Number(process.env.PULL_REQUEST), |
| 89 | body: Output.interpolate` |
| 90 | ## Website Preview Deployed |
| 91 | |
| 92 | **URL:** ${website.url} |
| 93 | |
| 94 | Built from commit ${ |
| 95 | // `BUILD_SHA` is set by .github/workflows/deploy.yml to the |
| 96 | // PR head SHA (or `github.sha` for push deploys). The |
| 97 | // ambient `GITHUB_SHA` would point at the synthetic merge |
| 98 | // commit on `pull_request` events, which is not what |
| 99 | // anyone wants to see in the comment. |
| 100 | process.env.BUILD_SHA |
| 101 | ? `[\`${process.env.BUILD_SHA.slice(0, 7)}\`](https://github.com/alchemy-run/alchemy/commit/${process.env.BUILD_SHA})` |
| 102 | : "unknown" |
| 103 | }. |
| 104 | |
| 105 | --- |
| 106 | _This comment updates automatically with each push._ |
| 107 | `, |
| 108 | }); |
| 109 | } |
| 110 | |
| 111 | return { |
| 112 | url: website.url, |
| 113 | }; |
| 114 | }), |
| 115 | ); |