Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--runonce flag added; same as --initial but process exits after initial run #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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