Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Plans for a watch switch/config? #81

Closed
ventaur opened this issue May 10, 2017 · 6 comments
Closed

Plans for a watch switch/config? #81

ventaur opened this issue May 10, 2017 · 6 comments

Comments

@ventaur
Copy link

ventaur commented May 10, 2017

Are there any plans to implement a "watch" switch/config to detect changes to the endpoint files?

@webpro
Copy link
Owner

webpro commented May 10, 2017

Yes, that has been on my mind for a while. Also see #78.

If you or someone else feels like helping me out with this, that would be great.

@ventaur
Copy link
Author

ventaur commented May 10, 2017

I'm game to help. Do you think it's worth trying to find the individual endpoints that change with a file modification to replace each, or just reload the entire service?

If you can point me to a good spot for the following, I can look at getting started:

  1. Where to setup a watch (where each file gets read).
  2. Where/what to reload on a file modification.

I have an idea for each, but want to make sure. Also, do you have any suggestions for setting up a test for this? I'm thinking someway to kick off the service creation (with all the endpoints), edit a file's path property, then verify the new path is loaded into the service (after some delay maybe). Does that sound plausible?

@webpro
Copy link
Owner

webpro commented May 11, 2017

Great!

My first thought was that it would be nice to watch the stubs directory and reload only the modified module (having one or more endpoints). But I also had situations where files in that directory where dependencies of others (not necessarily exporting endpoints), so I guess it's best to just reload everything. Some pointers (other ideas welcome!):

  • cli.execute is where the options (dir and watch) come in. I'd probably install a watcher in there.
  • chokidar is a popular watcher.
  • I don't know how to remove or replace existing route handlers. What you might end up doing: use the return value of dyson.bootstrap(opts), and delete this instance on a file change, and execute dyson.boostrap again.

@ventaur
Copy link
Author

ventaur commented May 12, 2017

OK. Thanks for the tips and direction. I'll see where this gets me when I get some time. ;-)

@ventaur
Copy link
Author

ventaur commented Aug 1, 2017

@webpro, I just wanted to post an update on this to save you some time/effort on my PR. I switched over to nodemon to get restarts on changes with Dyson. It works really well and doesn't require any changes to the Dyson codebase. That said, if you want me to cancel the PR, I will; otherwise, feel free to just kill it. Maybe you could add some documentation on how to use nodemon with Dyson for others.

To get things working properly, I installed nodemon and changed my NPM script to something like the following:

"scripts": {
  "start-api": "nodemon --watch api --exec dyson api"
}

This command tells nodemon to watch the api sub-directory recursively (it defaults to the CWD), and to wrap/execute "dyson api". I had to use the --exec switch when Dyson is only installed locally as a dev dependency; otherwise, you don't need that switch.

@webpro webpro closed this as completed in c2577aa Aug 1, 2017
@webpro
Copy link
Owner

webpro commented Aug 1, 2017

Thanks a ton for this and the PR, @ventaur! Very valuable to find out that the npm script is probably the best way to go. I've just updated the readme (with a maintenance release).

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

No branches or pull requests

2 participants