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
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

[**]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
trim_trailing_whitespace = true
indent_size = 2
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ This module includes a simple command line interface, which you can install with
Usage: watch <command> [...directory] [OPTIONS]

OPTIONS:
--wait=<seconds>
Duration, in seconds, that watching will be disabled
after running <command>. Setting this option will
throttle calls to <command> for the specified duration.
--wait
Wait for the previous instance of <command> to finish
before spawning another.

--filter=<file>
Path to a require-able .js file that exports a filter
Expand Down
35 changes: 23 additions & 12 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var watch = require('./main.js')
if(argv._.length === 0) {
console.error([
'Usage: watch <command> [...directory]',
'[--wait=<seconds>]',
'[--wait]',
'[--filter=<file>]',
'[--interval=<seconds>]',
'[--ignoreDotFiles]',
Expand All @@ -32,7 +32,7 @@ if (argLen > 1) {
dirs.push(process.cwd())
}

var waitTime = Number(argv.wait || argv.w)
var waitForCommand = Number(argv.wait || argv.w)
if (argv.interval || argv.i) {
watchTreeOpts.interval = Number(argv.interval || argv.i || 0.2);
}
Expand All @@ -57,7 +57,26 @@ if(argv.filter || argv.f) {
}
}

var wait = false
var commandIsRunning = false
var needToRunCommand = false

function execCommand() {
if(waitForCommand && commandIsRunning) {
needToRunCommand = true
return
}

needToRunCommand = false
commandIsRunning = true

execshell(command, function () {
commandIsRunning = false

if (needToRunCommand) {
execCommand();
}
})
}

var dirLen = dirs.length
var skip = dirLen - 1
Expand All @@ -69,15 +88,7 @@ for(i = 0; i < dirLen; i++) {
skip--
return
}
if(wait) return

execshell(command)

if(waitTime > 0) {
wait = true
setTimeout(function () {
wait = false
}, waitTime * 1000)
}
execCommand()
})
}