Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var defaultOpts = {
verbose: false,
silent: false,
initial: false,
runonce: false,
command: null
};

Expand Down Expand Up @@ -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 ' +
Expand Down Expand Up @@ -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] + ':';

Expand Down Expand Up @@ -172,6 +178,8 @@ function startWatching(opts) {
if (!opts.silent) {
console.error('Watching', '"' + list + '" ..');
}
// debounce after initial stage
debouncedRun = _.debounce(throttledRun, opts.debounce);
});
}

Expand All @@ -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;

Expand Down