Skip to content

Commit

Permalink
Merge pull request #57 from bluebrat/master
Browse files Browse the repository at this point in the history
Implement runOnChangeOnly option
  • Loading branch information
M-Zuber committed Sep 13, 2018
2 parents 559606e + e95f172 commit 93effc5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -60,8 +60,11 @@ the values should be a glob pattern or array of glob patterns to watch.
Also it is now possible to obtain a second parameter to define the script which should be run for watching and not watch all possible scripts at once.

If you need to watch files with extensions other than those that `nodemon` watches [by default](https://github.com/remy/nodemon#specifying-extension-watch-list) (`.js`, `.coffee`, `.litcoffee`), you can set the value to an object with `patterns` and `extensions` keys. You can also add an `ignore` key (a list or a string) to ignore specific files. Finally, you can add a `quiet` flag to hide the script name in any output on stdout or stderr, or you can use the `inherit` flag to preserve the original's process stdout or stderr. You can enable `nodemon` [legacy watch](https://github.com/remy/nodemon#application-isnt-restarting) and specify the restart [delay](https://github.com/remy/nodemon#delaying-restarting) in milliseconds with the corresponding flags.

> The `quiet` flag was changed from a `string` to a `boolean` in `0.1.5`. Backwards compatability will be kept for two patch versions.
Use `runOnChangeOnly` to set the nodemon option [--on-change-only](https://github.com/remy/nodemon/blob/master/doc/cli/options.txt "--on-change-only"). Setting this to `true` tells nodemon to execute script on change only, not startup.

```javascript
{
"watch": {
Expand All @@ -71,7 +74,8 @@ If you need to watch files with extensions other than those that `nodemon` watch
"ignore": "src/vendor/external.min.js",
"quiet": true,
"legacyWatch": true,
"delay": 2500
"delay": 2500,
"runOnChangeOnly": false
}
},
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions watch-package.js
Expand Up @@ -94,6 +94,7 @@ function startScript(script, pkg, processes) {
var inherit = null
var legacyWatch = null
var delay = null
var runOnChangeOnly = null

if (typeof pkg.watch[script] === 'object' && !Array.isArray(pkg.watch[script])) {
patterns = pkg.watch[script].patterns
Expand All @@ -103,6 +104,7 @@ function startScript(script, pkg, processes) {
inherit = pkg.watch[script].inherit
legacyWatch = pkg.watch[script].legacyWatch
delay = pkg.watch[script].delay
runOnChangeOnly = pkg.watch[script].runOnChangeOnly
} else {
patterns = pkg.watch[script]
}
Expand All @@ -126,6 +128,7 @@ function startScript(script, pkg, processes) {
if (ignores) { args = args.concat(ignores) }
if (legacyWatch) { args = args.concat(['--legacy-watch']) }
if (delay) { args = args.concat(['--delay', delay + 'ms']) }
if (runOnChangeOnly) { args = args.concat(['--on-change-only']) }
args = args.concat(['--exec', exec])
var proc = processes[script] = spawn(nodemon, args, {
env: process.env,
Expand Down

0 comments on commit 93effc5

Please sign in to comment.