schultek / jaspr

Modern web framework for building websites in Dart. Supports SPAs, SSR and SSG.
https://jasprpad.schultek.de
MIT License
1.26k stars 78 forks source link

Use webdev as a daemon #55

Closed Balint66 closed 1 year ago

Balint66 commented 1 year ago

As mentioned in #49 there is other ways of using the webdev package. I had quick a look at the source code of webdev and there is an "undocumented" command line option to use it as a daemon, just like someone can use flutter as described in the documentation.

pro:

con:

Maybe a mixed implementation could be used:


I wanted to create this issue to signal my finding, and start a conversation. Eventually I want to work on this and the mentioned issue's implementation, and I'm curious if creating such feature would be any help. 😄

schultek commented 1 year ago

Thanks for looking into this. Maybe we can combine boach approaches by using webdev as a package and using the deamon api.

schultek commented 1 year ago

When I run webdev as daemon, it serves the page just as the serve command does. The only difference is that the console output is in json.

Balint66 commented 1 year ago

Yes, from the outside it does look like that it does nothing but the same as the serve but with json output. But in the inside, it does more:

  1. Starts the daemon with the daemon domain, so in the beginning, only those commands, and the preregistered ones, like restart, can be executed.
  2. Validates the app, if it can be launched.
  3. Starts the DevWorkflow. This is where it starts the serving.
  4. Adds the app domain.
  5. Waits for the daemon to exit.

What's different, is that you can give it commands via jsonRPC on stdin. So, you can restart the app, stop the daemon, get it's version., and it will respond on stdout. Most things are documented on the flutter page, how one should attach to the process, the communication workflow.

I tried to pass more arguments than specified in the help, because in the code it looks like that the other arguments are passed to the mentioned workflow, so it wouldn't launch chrome, but the args parser wouldn't let me do it.

schultek commented 1 year ago

Fyi the new cli uses the DevWorkflow directly.