diff --git a/bun.lockb b/bun.lockb index 2f5f0fb..e8c701c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index c9c6aa0..da87450 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "module": "src/main.ts", "type": "module", "scripts": { - "dev": "concurrently \"bun run --hot src/main.ts\" \"bun run uno:dev\"", - "liveReload": "bun run --hot src/dev/liveReload.ts", + "dev": "concurrently \"bun run --hot src/main.ts\" \"bun run uno:dev\" \"bun run liveReload\"", + "liveReload": "bun run src/lib/dev/liveReload.ts", "start": "bun run uno && bun run src/main.ts", "db:push": "bunx drizzle-kit push:sqlite", "db:studio": "bunx drizzle-kit studio", @@ -29,7 +29,6 @@ "@libsql/client": "^0.3.4", "@lucia-auth/adapter-sqlite": "^2.0.0", "@t3-oss/env-core": "^0.6.1", - "chokidar": "^3.5.3", "drizzle-orm": "^0.28.6", "drizzle-typebox": "^0.1.1", "elysia": "^0.6.22", diff --git a/src/components/base.tsx b/src/components/base.tsx index 7d29839..6b9fb35 100644 --- a/src/components/base.tsx +++ b/src/components/base.tsx @@ -24,7 +24,6 @@ export const BaseHtml = ({ children }: Html.PropsWithChildren) => ( }; socket.onmessage = function(event) { - console.log(event.data); location.reload(); }; diff --git a/src/dev/liveReload.ts b/src/lib/dev/liveReload.ts similarity index 80% rename from src/dev/liveReload.ts rename to src/lib/dev/liveReload.ts index 8cf579b..ef2bed5 100644 --- a/src/dev/liveReload.ts +++ b/src/lib/dev/liveReload.ts @@ -1,15 +1,14 @@ import { Elysia, ws } from "elysia"; import { type ElysiaWS } from "elysia/ws"; -import { watch } from "chokidar"; let wsConnections = new Set>(); -watch("src/**/*.{ts,tsx}").on("all", (event, path) => { - console.log("sending event"); +function dispatch() { wsConnections.forEach((connection) => { + console.log("sending refresh"); connection.send("refresh"); }); -}); +} const app = new Elysia() .use(ws()) @@ -26,6 +25,10 @@ const app = new Elysia() console.log("message", message); }, }) + .get("/restart", () => { + console.log("recieved restart"); + dispatch(); + }) .listen(3001); console.log( diff --git a/src/lib/fileBasedRouting/index.ts b/src/lib/fileBasedRouting/index.ts new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/lib/fileBasedRouting/index.ts @@ -0,0 +1 @@ + diff --git a/src/main.ts b/src/main.ts index 29d5e4e..c784919 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,7 @@ import { swagger } from "@elysiajs/swagger"; import { staticPlugin } from "@elysiajs/static"; import { api } from "./controllers"; import { autoroutes } from "elysia-autoroutes"; +import { config } from "./config"; const app = new Elysia({ name: "@app/main", @@ -16,6 +17,12 @@ const app = new Elysia({ routesDir: "./pages", }) ) + .onStart(() => { + if (config.env.NODE_ENV === "development") { + void fetch("http://localhost:3001/restart"); + console.log("🦊 Triggering Live Reload"); + } + }) .listen(3000); export type App = typeof app;