summaryrefslogtreecommitdiff
path: root/cgithub/scripts/compile-views.ts
diff options
context:
space:
mode:
authorJoe Mou <dev@mou.fo>2026-07-15 02:08:17 -0400
committerJoe Mou <dev@mou.fo>2026-07-15 02:08:29 -0400
commit9b556ffe6c0c0528697e15f7f4f35107de212ce1 (patch)
tree7f87bd7d58c4bc9a640a669fa314fec6c49c82df /cgithub/scripts/compile-views.ts
parent9fbb5f0d68a131b55bc172d46b75705f2842af04 (diff)
Add Cloudflare Workers deployment target
Split routes into a shared createApp() (src/app.ts) used by both the Node entry (src/index.ts) and a new Workers entry (src/worker.ts). Workers disallow runtime code generation, so scripts/compile-views.ts precompiles the Eta templates into src/views.generated.ts and rendering switches from renderAsync to the sync render. Static files move to public/static so Workers Static Assets can serve them; the Node build and serveStatic root are updated to match. Deploy with pnpm run deploy:cf, local dev with pnpm run dev:cf. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'cgithub/scripts/compile-views.ts')
-rw-r--r--cgithub/scripts/compile-views.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/cgithub/scripts/compile-views.ts b/cgithub/scripts/compile-views.ts
new file mode 100644
index 0000000..785efc1
--- /dev/null
+++ b/cgithub/scripts/compile-views.ts
@@ -0,0 +1,29 @@
+// Precompiles views/*.eta into plain functions for the Cloudflare Workers
+// build (src/views.generated.ts). Workers disallow runtime code generation
+// (`new Function`), so Eta cannot compile templates there at request time.
+import { Eta } from "eta";
+import fs from "node:fs";
+import path from "node:path";
+
+const root = path.join(import.meta.dirname, "..");
+const viewsDir = path.join(root, "views");
+const eta = new Eta({ views: viewsDir });
+
+const names = fs
+ .readdirSync(viewsDir)
+ .filter((name) => name.endsWith(".eta"))
+ .sort();
+
+let out = `// @ts-nocheck
+// Generated by scripts/compile-views.ts -- do not edit.
+export const views = {
+`;
+for (const name of names) {
+ const source = fs.readFileSync(path.join(viewsDir, name), "utf8");
+ const body = eta.compileToString(source);
+ out += ` ${JSON.stringify(name)}: function (it, options) {\n${body}\n },\n`;
+}
+out += "};\n";
+
+fs.writeFileSync(path.join(root, "src", "views.generated.ts"), out);
+console.log(`Compiled ${names.length} templates to src/views.generated.ts`);