From 5d8ac94a194d9ad81747553c5d6b0ef1bea2a337 Mon Sep 17 00:00:00 2001 From: Marcos Candeia Date: Fri, 26 Jul 2024 20:19:23 -0300 Subject: [PATCH 01/14] Use dev server as hono Signed-off-by: Marcos Candeia --- components/Session.tsx | 2 +- deno.json | 19 +++++++++++-------- dev.ts | 18 +++++++----------- hono.ts | 9 +++++++++ main.ts | 11 +---------- routes/_app.tsx | 5 +++-- sections/Animation/Animation.tsx | 2 +- 7 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 hono.ts diff --git a/components/Session.tsx b/components/Session.tsx index 4481bc43..2c70781b 100644 --- a/components/Session.tsx +++ b/components/Session.tsx @@ -1,6 +1,6 @@ -import { Head } from "$fresh/runtime.ts"; import { type Person } from "apps/commerce/types.ts"; import { useScript } from "deco/hooks/useScript.ts"; +import { Head } from "deco/mod.ts"; import { type AppContext } from "../apps/site.ts"; import { MINICART_DRAWER_ID } from "../constants.ts"; import { useComponent } from "../sections/Component.tsx"; diff --git a/deno.json b/deno.json index e0106c7c..ebba9604 100644 --- a/deno.json +++ b/deno.json @@ -1,17 +1,19 @@ { "imports": { - "deco/": "https://cdn.jsdelivr.net/gh/deco-cx/deco@1.80.0/", - "apps/": "https://cdn.jsdelivr.net/gh/deco-cx/apps@0.53.0/", "$fresh/": "https://deno.land/x/fresh@1.6.8/", - "preact": "https://esm.sh/preact@10.19.6", - "preact/": "https://esm.sh/preact@10.19.6/", - "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.4.0", + "@hono/hono": "jsr:@hono/hono@^4.5.1", "@preact/signals": "https://esm.sh/*@preact/signals@1.2.2", "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1", - "std/": "https://deno.land/std@0.190.0/", - "daisyui": "npm:daisyui@4.6.0" + "apps/": "https://cdn.jsdelivr.net/gh/deco-cx/apps@e25c559ae36444796ce6011966820ddf7eafcd77/", + "daisyui": "npm:daisyui@4.6.0", + "deco/": "https://cdn.jsdelivr.net/gh/deco-cx/deco@c8c2919745023bc44988f978a198e04bcc27f410/", + "preact": "https://esm.sh/preact@10.19.6", + "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.4.0", + "preact/": "https://esm.sh/preact@10.19.6/", + "std/": "https://deno.land/std@0.203.0/" }, "tasks": { + "hono": "deno task bundle && deno run -A --unstable-http --env --config=deno.json $(deno eval 'console.log(import.meta.resolve(\"deco/hypervisor/main.ts\"))') --build-cmd 'deno task build' -- deno task honodev", "start": "deno task bundle && deno run -A --unstable-http --env --config=deno.json $(deno eval 'console.log(import.meta.resolve(\"deco/hypervisor/main.ts\"))') --build-cmd 'deno task build' -- deno task dev", "gen": "deno run -A dev.ts --gen-only", "play": "USE_LOCAL_STORAGE_ONLY=true deno task start", @@ -26,7 +28,8 @@ "build": "deno run -A dev.ts build", "preview": "deno run -A main.ts", "generate-icons": "deno run -A --unstable static/generate-icons.ts", - "dev": "deno run -A --env --unstable --unstable-hmr dev.ts" + "dev": "deno run -A --env --unstable --unstable-hmr dev.ts", + "honodev": "deno run -A --env --unstable --unstable-hmr hono.ts" }, "githooks": { "pre-commit": "check" diff --git a/dev.ts b/dev.ts index 244fa45f..1dfd955d 100644 --- a/dev.ts +++ b/dev.ts @@ -1,13 +1,9 @@ -import { setupGithooks } from "https://deno.land/x/githooks@0.0.4/githooks.ts"; +import { DecoRouteState, setup } from "deco/mod.ts"; -import dev from "$fresh/dev.ts"; -import config from "./fresh.config.ts"; +import { Hono } from "@hono/hono"; +import type { Manifest } from "./manifest.gen.ts"; -setupGithooks().catch(console.error); - -// Generate manifest and boot server -await dev(import.meta.url, "./main.ts", config); - -if (Deno.args.includes("build")) { - Deno.exit(0); -} +const honoApp = new Hono>(); +await setup(honoApp); +const port = Deno.env.get("PORT") ? +Deno.env.get("PORT")! : 8000; +Deno.serve({ port, handler: honoApp.fetch }); diff --git a/hono.ts b/hono.ts new file mode 100644 index 00000000..1dfd955d --- /dev/null +++ b/hono.ts @@ -0,0 +1,9 @@ +import { DecoRouteState, setup } from "deco/mod.ts"; + +import { Hono } from "@hono/hono"; +import type { Manifest } from "./manifest.gen.ts"; + +const honoApp = new Hono>(); +await setup(honoApp); +const port = Deno.env.get("PORT") ? +Deno.env.get("PORT")! : 8000; +Deno.serve({ port, handler: honoApp.fetch }); diff --git a/main.ts b/main.ts index a440323d..dedb9258 100644 --- a/main.ts +++ b/main.ts @@ -1,10 +1 @@ -/// -/// -/// -/// - -import { start } from "$fresh/server.ts"; -import config from "./fresh.config.ts"; -import manifest from "./fresh.gen.ts"; - -await start(manifest, config); +import "./dev.ts"; diff --git a/routes/_app.tsx b/routes/_app.tsx index 92a56689..4b118da7 100644 --- a/routes/_app.tsx +++ b/routes/_app.tsx @@ -1,7 +1,8 @@ -import { asset, Head } from "$fresh/runtime.ts"; +import { asset } from "$fresh/runtime.ts"; import { defineApp } from "$fresh/server.ts"; -import { useScript } from "deco/hooks/useScript.ts"; import { Context } from "deco/deco.ts"; +import { useScript } from "deco/hooks/useScript.ts"; +import { Head } from "deco/mod.ts"; const serviceWorkerScript = () => addEventListener("load", () => diff --git a/sections/Animation/Animation.tsx b/sections/Animation/Animation.tsx index 19b21a23..500a8daf 100644 --- a/sections/Animation/Animation.tsx +++ b/sections/Animation/Animation.tsx @@ -1,5 +1,5 @@ -import { useScript } from "deco/hooks/useScript.ts"; import { Section } from "deco/blocks/section.ts"; +import { useScript } from "deco/hooks/useScript.ts"; import { useId } from "../../sdk/useId.ts"; interface Children { From bae087aeb721a50671c62e78adc8b3fbfb096f92 Mon Sep 17 00:00:00 2001 From: Marcos Candeia Date: Fri, 26 Jul 2024 20:22:01 -0300 Subject: [PATCH 02/14] Exit on build Signed-off-by: Marcos Candeia --- dev.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dev.ts b/dev.ts index 1dfd955d..35090b65 100644 --- a/dev.ts +++ b/dev.ts @@ -3,6 +3,10 @@ import { DecoRouteState, setup } from "deco/mod.ts"; import { Hono } from "@hono/hono"; import type { Manifest } from "./manifest.gen.ts"; +if (Deno.args.includes("build")) { + Deno.exit(0); +} + const honoApp = new Hono>(); await setup(honoApp); const port = Deno.env.get("PORT") ? +Deno.env.get("PORT")! : 8000; From 32befdf792a3cb46fb362d569f0f1d8dee6889f5 Mon Sep 17 00:00:00 2001 From: Marcos Candeia Date: Fri, 26 Jul 2024 20:28:48 -0300 Subject: [PATCH 03/14] Fix partial mode check Signed-off-by: Marcos Candeia --- deno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno.json b/deno.json index ebba9604..beb6cb3d 100644 --- a/deno.json +++ b/deno.json @@ -6,7 +6,7 @@ "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1", "apps/": "https://cdn.jsdelivr.net/gh/deco-cx/apps@e25c559ae36444796ce6011966820ddf7eafcd77/", "daisyui": "npm:daisyui@4.6.0", - "deco/": "https://cdn.jsdelivr.net/gh/deco-cx/deco@c8c2919745023bc44988f978a198e04bcc27f410/", + "deco/": "https://cdn.jsdelivr.net/gh/deco-cx/deco@753ef45931e1f8bc1cbacf77763ad892169179c2/", "preact": "https://esm.sh/preact@10.19.6", "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.4.0", "preact/": "https://esm.sh/preact@10.19.6/", From 184e8d310280ff6a9cc2c36f4573d81cadd222b5 Mon Sep 17 00:00:00 2001 From: Marcos Candeia Date: Thu, 1 Aug 2024 10:26:50 -0300 Subject: [PATCH 04/14] Use hono router Signed-off-by: Marcos Candeia --- _app.tsx | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ deno.json | 4 ++-- hono.ts | 17 ++++++++++------- 3 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 _app.tsx diff --git a/_app.tsx b/_app.tsx new file mode 100644 index 00000000..74500582 --- /dev/null +++ b/_app.tsx @@ -0,0 +1,50 @@ +import { asset } from "$fresh/runtime.ts"; +import { useScript } from "deco/hooks/useScript.ts"; +import { Head } from "deco/runtime/htmx/Renderer.tsx"; +import { ComponentChildren } from "preact"; + +const serviceWorkerScript = () => + addEventListener("load", () => + navigator && navigator.serviceWorker && + navigator.serviceWorker.register("/sw.js?__frsh_c")); + +export const Layout = ( + { children, revision, hmrUniqueId }: { + children: ComponentChildren; + revision: string; + hmrUniqueId: string; + }, +) => { + return ( + <> + {/* Include Icons and manifest */} + + {/* Enable View Transitions API */} +