Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 18 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ if(argv._.length === 0) {
'[--interval=<seconds>]',
'[--ignoreDotFiles]',
'[--ignoreUnreadable]',
'[--ignoreDirectoryPattern]'
'[--ignoreDirectoryPattern]',
'[--kill]'
].join(' '))
process.exit()
}
Expand Down Expand Up @@ -61,6 +62,7 @@ var wait = false

var dirLen = dirs.length
var skip = dirLen - 1
var runningPs = null;
for(i = 0; i < dirLen; i++) {
var dir = dirs[i]
console.error('> Watching', dir)
Expand All @@ -71,7 +73,21 @@ for(i = 0; i < dirLen; i++) {
}
if(wait) return

execshell(command)
if(argv.kill && runningPs) {
wait = true;
runningPs.kill(argv.kill);
runningPs.once('close', function() {
runningPs = execshell(command);
wait = false;
});
runningPs.once('error', function() {
console.log('Could not kill the child process :/');
process.exit(1);
});
return;
}

runningPs = execshell(command)

if(waitTime > 0) {
wait = true
Expand Down
3 changes: 3 additions & 0 deletions readme.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ OPTIONS:
--ignoreDirectoryPattern=<regexp>, -p
Silently skips directories that match the regular
expression.

--kill=<signal>, -k
Kill the run command before the new execution.
```

It will watch the given directories (defaults to the current working directory) with `watchTree` and run the given command every time a file changes.
Expand Down