mathquill/mathquill — pull request #222 by laughinghan (2013-11-25 05:08:35+00:00)
Title: `make server` auto-rebuilds without restarting server

Before, the `test` make target was a dependency of running the server
and node-supervisor killed and re-ran `make run-server` whenever any
source files changed, so the server would be down while `make test` ran
and you had to keep Refreshing until `make test` finished and the server
came back up.

Now, we still re-run `make test` whenever source (or test) files change,
but the server never goes down, it just puts all incoming HTTP requests
on hold until `make test` finishes.

This way, as soon as you write a change to disk you can switch to Chrome
and Refresh just once, and it'll take as long as it takes `make test` to
complete for the page to load, rather than the connection being refused
because the server isn't running so making you keep Refreshing until the
server comes back up.

[node-supervisor apparently defaults to fs.watchFile rather than
fs.watch][1], but [the fs.watchFile docs][2] specifically recommend
[fs.watch][3] instead. As a bonus, [node-supervisor apparently only watches
individual files, the list of which is determined when launched][4], so
if new source files were added then `make server` would have to be
killed and re-run, whereas we now watch the entire `src/` and `test/`
directories.

[1]: https://github.com/isaacs/node-supervisor/blob/v0.5.6/lib/supervisor.js#L285-L288
[2]: http://nodejs.org/docs/v0.10.22/api/fs.html#fs_fs_watchfile_filename_options_listener
[3]: http://nodejs.org/docs/v0.10.22/api/fs.html#fs_fs_watch_filename_options_listener
[4]: https://github.com/isaacs/node-supervisor/blob/v0.5.6/lib/supervisor.js#L144

Also, one less dependency!