napcs/node-livereload

Expose `Server` and `filterRefresh` so that I can use http/https/ws/chokidar on my own

Closed this issue · 4 comments

I'd like to be able to create an instance of livereload that does not depend on the built-in createServer

https://github.com/napcs/node-livereload/blob/master/lib/livereload.coffee#L167

I'd also like to be able to close and re-open the watcher at will to add or remove directories on the fly. I believe if filterRefresh were expose I could do this easily.

I think I should be able to do something like this:

var lrServer = require('livereload');
var lr = new lrServer({
  httpServer: myHttpsServer
, wsServer: myWsServer
});
var lrFilterRefresh = lr.filterRefresh.bind(lr);
var watcher = chokidar.watch(paths, {
      ignoreInitial: true
    , ignored: config.exclusions
    , usePolling: config.usePolling
    })
    .on('add', lrFilterRefresh)
    .on('change', lrFilterRefresh)
    .on 'unlink', lrFilterRefresh)
    ;

If I understand the code correctly I think that should also allow me to run multiple separate instances of livereload within the same process too.

Would you be open to a PR for this?

napcs commented

I just can't see the usecase for something like this that would apply to everyone. This tool was designed to be incredibly lightweight and self-contained, and we've already had to replace the internals twice, so I'm not too keen on exposing more of it to the outside world.

Can you make a general-case argument why lots of users would want this functionality? You may be happy to make the PR, but I'll be the one maintaining it :)

Well, it stays just as lightweight (4 extra lines or so - two exports and an if to not run the server?) but then it becomes a library rather than a binary.

Currently this can't be controlled programmatically. Once it's called, it's done.

My use case is to include it in a webserver that can be updated simply by moving files into a directory - it doesn't need to be restarted.

napcs commented

Ahh so you're looking to decouple the core websocket bits from the server so you can swap out the server.

I guess I'd like to see what you think a PR for this would look like.

napcs commented

Closing as abandoned.