isaacs/node-supervisor — pull request #108 by newleafdigital (2013-07-18 22:10:55+00:00)
Title: added '--changed-file-arg' param so program knows what caused a restart

Use case: Supervisor is watching for .coffee, .styl, and .jade files, and on any changes, lints them and statically compiles them for the client (using [grunt](http://gruntjs.com)) and runs the app. However, that build process takes 10 seconds, and it doesn't need to do the whole thing on every change. If a .styl file changes, for example, it should only re-compile those files, not the .coffee files, etc.

So, I'd like to pass my program (which supervisor restarts) a flag telling it what caused the restart, so it can be smart about what it builds.
In order to accomplish this, I added a `--changed-file-arg` param to supervisor. So for example, if I run supervisor with `-x node --changed-file-arg=restarted-by -- build_app.js`, when supervisor restarts my program because of a change to /app/some-file.js, it will add that parameter, and run `node build_app.js --restart-by=/app/some-file.js`. Then that script can react accordingly.

The way it's implemented uses a variable in the top-level scope of supervisor, because a) the `exit` event doesn't easily take parameters, and b) supervisor is only managing one program at a time anyway.

Thoughts?