@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 06:00 UTC

main
ts 64 lines 2.34 KB
Raw
1 import { defineScene, edit } from "../capture/scene.ts";
2
3 export default defineScene({
4 title: "A Stack and a website",
5 chapter: "00-website",
6 notes: "Chapter 0: declare a Stack with one Vite website and run it locally with alchemy dev.",
7 async run(s) {
8 await s.sync({ except: ["alchemy.run.ts"] });
9
10 s.step(
11 "Start from a plain Vite + React app",
12 "An ordinary Vite + React dashboard. Nothing Alchemy-specific in it yet.",
13 );
14 await s.editor.open("src/main.tsx");
15 s.pause(1);
16
17 const stack = await s.chapterLines("alchemy.run.ts");
18 await s.editor.patch(
19 "alchemy.run.ts",
20 "Create alchemy.run.ts",
21 edit.set(stack(1, 3)),
22 "alchemy.run.ts is the whole infrastructure program. It's plain TypeScript: Alchemy, the Cloudflare provider, and Effect.",
23 );
24 await s.editor.patch(
25 "alchemy.run.ts",
26 "Declare the Stack",
27 edit.append(`\n${stack(5, 11)} }),\n);\n`),
28 "A Stack has a name, the providers it can use, and where it keeps its state. Its body is an Effect: every resource is something we yield.",
29 );
30 await s.editor.patch(
31 "alchemy.run.ts",
32 "Add the Vite website as a resource",
33 edit.after(stack(11), stack(12, 14)),
34 "Cloudflare.Website.Vite builds the Vite app and serves it from a Cloudflare Worker. dev pins the port alchemy dev serves it on.",
35 );
36 await s.editor.patch(
37 "alchemy.run.ts",
38 "Output the website's URL",
39 edit.after(stack(14), stack(15, 16)),
40 "Whatever the Stack returns is its output: printed by alchemy dev and after every deploy.",
41 );
42
43 s.step(
44 "Run the Stack locally with alchemy dev",
45 "alchemy dev runs the whole Stack on this machine and hot-reloads it on every save. It stays up in its own tab while we build; nothing is deployed until the end.",
46 );
47 await s.terminal(async (t) => {
48 await t.type("dev", "alchemy dev");
49 await t.waitDev();
50 await t.sleep(1000);
51 });
52
53 s.step(
54 "One resource, running locally",
55 "The architecture so far: a single website, running in alchemy dev's local simulator.",
56 );
57 await s.diagram({ stage: `dev_${process.env.USER}`, nodes: ["Web"] });
58 s.pause(1);
59
60 s.step("The website, served by alchemy dev");
61 await s.browser.open("http://localhost:5173", { waitFor: /Your links/ });
62 s.pause(1.5);
63 },
64 });