live reaload

main
Ethan Niser 2023-09-14 16:38:04 -05:00
parent cb6a1d0c6c
commit 80c5863e0b
6 changed files with 17 additions and 8 deletions

Binary file not shown.

@ -3,8 +3,8 @@
"module": "src/main.ts", "module": "src/main.ts",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "concurrently \"bun run --hot src/main.ts\" \"bun run uno:dev\"", "dev": "concurrently \"bun run --hot src/main.ts\" \"bun run uno:dev\" \"bun run liveReload\"",
"liveReload": "bun run --hot src/dev/liveReload.ts", "liveReload": "bun run src/lib/dev/liveReload.ts",
"start": "bun run uno && bun run src/main.ts", "start": "bun run uno && bun run src/main.ts",
"db:push": "bunx drizzle-kit push:sqlite", "db:push": "bunx drizzle-kit push:sqlite",
"db:studio": "bunx drizzle-kit studio", "db:studio": "bunx drizzle-kit studio",
@ -29,7 +29,6 @@
"@libsql/client": "^0.3.4", "@libsql/client": "^0.3.4",
"@lucia-auth/adapter-sqlite": "^2.0.0", "@lucia-auth/adapter-sqlite": "^2.0.0",
"@t3-oss/env-core": "^0.6.1", "@t3-oss/env-core": "^0.6.1",
"chokidar": "^3.5.3",
"drizzle-orm": "^0.28.6", "drizzle-orm": "^0.28.6",
"drizzle-typebox": "^0.1.1", "drizzle-typebox": "^0.1.1",
"elysia": "^0.6.22", "elysia": "^0.6.22",

@ -24,7 +24,6 @@ export const BaseHtml = ({ children }: Html.PropsWithChildren) => (
}; };
socket.onmessage = function(event) { socket.onmessage = function(event) {
console.log(event.data);
location.reload(); location.reload();
}; };

@ -1,15 +1,14 @@
import { Elysia, ws } from "elysia"; import { Elysia, ws } from "elysia";
import { type ElysiaWS } from "elysia/ws"; import { type ElysiaWS } from "elysia/ws";
import { watch } from "chokidar";
let wsConnections = new Set<ElysiaWS<any>>(); let wsConnections = new Set<ElysiaWS<any>>();
watch("src/**/*.{ts,tsx}").on("all", (event, path) => { function dispatch() {
console.log("sending event");
wsConnections.forEach((connection) => { wsConnections.forEach((connection) => {
console.log("sending refresh");
connection.send("refresh"); connection.send("refresh");
}); });
}); }
const app = new Elysia() const app = new Elysia()
.use(ws()) .use(ws())
@ -26,6 +25,10 @@ const app = new Elysia()
console.log("message", message); console.log("message", message);
}, },
}) })
.get("/restart", () => {
console.log("recieved restart");
dispatch();
})
.listen(3001); .listen(3001);
console.log( console.log(

@ -3,6 +3,7 @@ import { swagger } from "@elysiajs/swagger";
import { staticPlugin } from "@elysiajs/static"; import { staticPlugin } from "@elysiajs/static";
import { api } from "./controllers"; import { api } from "./controllers";
import { autoroutes } from "elysia-autoroutes"; import { autoroutes } from "elysia-autoroutes";
import { config } from "./config";
const app = new Elysia({ const app = new Elysia({
name: "@app/main", name: "@app/main",
@ -16,6 +17,12 @@ const app = new Elysia({
routesDir: "./pages", routesDir: "./pages",
}) })
) )
.onStart(() => {
if (config.env.NODE_ENV === "development") {
void fetch("http://localhost:3001/restart");
console.log("🦊 Triggering Live Reload");
}
})
.listen(3000); .listen(3000);
export type App = typeof app; export type App = typeof app;