Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload code on refresh without server restart #20

Open
swlkr opened this issue Dec 18, 2019 · 5 comments
Open

Reload code on refresh without server restart #20

swlkr opened this issue Dec 18, 2019 · 5 comments

Comments

@swlkr
Copy link
Collaborator

swlkr commented Dec 18, 2019

No description provided.

@swlkr swlkr changed the title Reload code without server restart Reload code on refresh without server restart Dec 18, 2019
@swlkr swlkr closed this as completed Feb 14, 2020
@onemanstartup
Copy link

onemanstartup commented Sep 17, 2020

Does this implemented? I tried and it didn't work.
However I can use external tool like entr - ls *.janet | entr -r janet main.janet, but I wouldn't want to rely on external tools if it could be avoided.

Ok. LOL. Found in the code that do the same thing with the same tool.

@swlkr
Copy link
Collaborator Author

swlkr commented Sep 17, 2020

Yeah entr is great!

I'm still not quite sure how I'd do this. It would be nice to start a websocket server and push updated html to the page you're working on, something like "hot reload" but I'm not sure if I care about the server reloading without restarting since restarts are so fast.

@aliaksandr-s
Copy link

Are there any updates on this? Maybe there is a way to at least refresh a browser tab when the code changes.

@swlkr
Copy link
Collaborator Author

swlkr commented Nov 30, 2020

I did manage to whip something up to refresh the tab, but the websockets thing would be cross platform/cross browser.

Here is what I did on macOS. I created two files, watch with chmod +x and refresh-tab.scptd:

watch looks like this:

#!/usr/bin/env sh

pkill -xf "janet src/app.janet"
sleep .5
janet src/app.janet &
osascript refresh-tab.scptd

refresh-tab looks like this:

#!/usr/bin/osascript

tell application "Safari"
    set docUrl to URL of document 1
    set URL of document 1 to docUrl
end tell

and then it gets called via fswatch which I wrapped up in a phony in project.janet:

(phony "watch" []
  (os/shell "fswatch -o . --exclude='.git' --exclude='.sqlite3' | xargs -n1 -I{} ./watch"))

I think I will take another shot at using websockets to reload html on the page with https://github.com/joy-framework/halo2 now that janet master has some async things so it might be possible to get websockets working in pure janet.

@swlkr swlkr reopened this Nov 30, 2020
@matthewmcgarvey
Copy link

I noticed that generating a fresh app contains entr in the server command. I was surprised to find that the app wasn't reloading when I made changes though.

(phony "server" []
  (if (= "development" (os/getenv "JOY_ENV"))
    (os/shell "find . -name '*.janet' | entr janet main.janet")
    (os/shell "janet main.janet")))

I'm pretty sure that it is because when it calls os/getenv the .env file hasn't been loaded yet so it always evaluates to false. I got it working by changing it to this

(use joy)

(phony "server" []
  (if (= "development" (env :joy_env))
    (os/shell "find . -name '*.janet' | entr -r janet main.janet")
    (os/shell "janet main.janet")))

Instead of using os/getenv I use joy's env and there was a missing -r flag on the entr command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants