diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..98e560c --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/README.md b/README.md index c645689..5a37fbe 100644 --- a/README.md +++ b/README.md @@ -91,10 +91,9 @@ This module includes a simple command line interface, which you can install with Usage: watch [...directory] [OPTIONS] OPTIONS: - --wait= - Duration, in seconds, that watching will be disabled - after running . Setting this option will - throttle calls to for the specified duration. + --wait + Wait for the previous instance of to finish + before spawning another. --filter= Path to a require-able .js file that exports a filter diff --git a/cli.js b/cli.js index 8299e4f..142affd 100755 --- a/cli.js +++ b/cli.js @@ -8,7 +8,7 @@ var watch = require('./main.js') if(argv._.length === 0) { console.error([ 'Usage: watch [...directory]', - '[--wait=]', + '[--wait]', '[--filter=]', '[--interval=]', '[--ignoreDotFiles]', @@ -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); } @@ -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 @@ -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() }) }