From eb5620889a7b502194f584a096f28364dae46c41 Mon Sep 17 00:00:00 2001 From: Nelis Bijl Date: Thu, 22 Dec 2016 10:15:59 +0100 Subject: [PATCH 1/3] runonce flag added; same as initial but process exits after initial run --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e638668..eea2d9a 100755 --- a/index.js +++ b/index.js @@ -25,6 +25,7 @@ var defaultOpts = { verbose: false, silent: false, initial: false, + runonce: false, command: null }; @@ -83,6 +84,11 @@ var argv = require('yargs') default: defaultOpts.initial, type: 'boolean' }) + .option('runonce', { + describe: 'When set, command is initially run once and the process is terminated afterwards', + default: defaultOpts.runonce, + type: 'boolean' + }) .option('p', { alias: 'polling', describe: 'Whether to use fs.watchFile(backed by polling) instead of ' + @@ -180,11 +186,12 @@ function createChokidarOpts(opts) { opts.ignore = _resolveIgnoreOpt(opts.ignore); var chokidarOpts = { + persistent: !opts.runonce, followSymlinks: opts.followSymlinks, usePolling: opts.polling, interval: opts.pollInterval, binaryInterval: opts.pollIntervalBinary, - ignoreInitial: !opts.initial + ignoreInitial: !opts.runonce && !opts.initial }; if (opts.ignore) chokidarOpts.ignored = opts.ignore; From 5cb9eb43eb07038ab2b05d79aa9cb3a022fec632 Mon Sep 17 00:00:00 2001 From: Nelis Bijl Date: Wed, 1 Feb 2017 09:39:29 +0100 Subject: [PATCH 2/3] Start debounce after initial stage --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index eea2d9a..b483b37 100755 --- a/index.js +++ b/index.js @@ -146,7 +146,7 @@ function startWatching(opts) { var watcher = chokidar.watch(opts.patterns, chokidarOpts); var throttledRun = _.throttle(run, opts.throttle); - var debouncedRun = _.debounce(throttledRun, opts.debounce); + var debouncedRun = run; // process all requests during initial stage (runonce or initial) watcher.on('all', function(event, path) { var description = EVENT_DESCRIPTIONS[event] + ':'; @@ -178,6 +178,8 @@ function startWatching(opts) { if (!opts.silent) { console.error('Watching', '"' + list + '" ..'); } + // debounce after initial stage + debouncedRun = _.debounce(throttledRun, opts.debounce); }); } From 86485f59b048a08cea5ab8d9f73e8f804a3306a8 Mon Sep 17 00:00:00 2001 From: Nelis Bijl Date: Thu, 22 Dec 2016 10:15:59 +0100 Subject: [PATCH 3/3] runonce flag added; same as initial but process exits after initial run Start debounce after initial stage --- index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e638668..b483b37 100755 --- a/index.js +++ b/index.js @@ -25,6 +25,7 @@ var defaultOpts = { verbose: false, silent: false, initial: false, + runonce: false, command: null }; @@ -83,6 +84,11 @@ var argv = require('yargs') default: defaultOpts.initial, type: 'boolean' }) + .option('runonce', { + describe: 'When set, command is initially run once and the process is terminated afterwards', + default: defaultOpts.runonce, + type: 'boolean' + }) .option('p', { alias: 'polling', describe: 'Whether to use fs.watchFile(backed by polling) instead of ' + @@ -140,7 +146,7 @@ function startWatching(opts) { var watcher = chokidar.watch(opts.patterns, chokidarOpts); var throttledRun = _.throttle(run, opts.throttle); - var debouncedRun = _.debounce(throttledRun, opts.debounce); + var debouncedRun = run; // process all requests during initial stage (runonce or initial) watcher.on('all', function(event, path) { var description = EVENT_DESCRIPTIONS[event] + ':'; @@ -172,6 +178,8 @@ function startWatching(opts) { if (!opts.silent) { console.error('Watching', '"' + list + '" ..'); } + // debounce after initial stage + debouncedRun = _.debounce(throttledRun, opts.debounce); }); } @@ -180,11 +188,12 @@ function createChokidarOpts(opts) { opts.ignore = _resolveIgnoreOpt(opts.ignore); var chokidarOpts = { + persistent: !opts.runonce, followSymlinks: opts.followSymlinks, usePolling: opts.polling, interval: opts.pollInterval, binaryInterval: opts.pollIntervalBinary, - ignoreInitial: !opts.initial + ignoreInitial: !opts.runonce && !opts.initial }; if (opts.ignore) chokidarOpts.ignored = opts.ignore;