Skip to content

Commit

Permalink
Merge pull request #53 from charlesbdudley/add-clear-buffer-option
Browse files Browse the repository at this point in the history
added config flag to clear the buffer on file changes
  • Loading branch information
M-Zuber authored Jan 22, 2019
2 parents f5f5064 + a30560c commit e02147f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
42 changes: 37 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ Possibilty to watch for different tasks

```javascript
{
"watch":
{
"watch": {
"run_android": {
"patterns": [
"app"
Expand All @@ -53,8 +52,7 @@ Possibilty to watch for different tasks
}
```


The keys of the `"watch"` config should match the names of your `"scripts"`, and
The top level keys of the `"watch"` config should match the names of your `"scripts"`, and
the values should be a glob pattern or array of glob patterns to watch.

Also it is now possible to obtain a second parameter to define the script which should be run for watching and not watch all possible scripts at once.
Expand Down Expand Up @@ -124,7 +122,41 @@ EOF

Tests run *perfectly*, ship it to the enterprise!

## Ignore files
### Options

#### `patterns`

Array of paths to watch

#### `extensions`

Array of file extensions to watch

#### `ignore`

String or array of paths to ignore

#### `quiet`

Boolean to hide the script name in any output on stdout and stderr

#### `inherit`

Boolean to preserve the original process' stdout and stderr

#### `legacyWatch`

Boolean to enable [legacy watch](https://github.com/remy/nodemon#application-isnt-restarting)

#### `delay`

Number of milliseconds to [delay](https://github.com/remy/nodemon#delaying-restarting) before checking for new files

#### `clearBuffer`

Boolean to clear the buffer after detecting a new change

#### `Ignore files`

Add an `ignore` property to your `watch` object. The value of `ignore` can be a string if you only want to ignore
a single glob:
Expand Down
16 changes: 16 additions & 0 deletions watch-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var through = require('through2')

var npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
var nodemon = process.platform === 'win32' ? 'nodemon.cmd' : 'nodemon';
var clearCharacter = process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H';

var pkgDir = '';
var stdin = null;
Expand Down Expand Up @@ -94,6 +95,7 @@ function startScript(script, pkg, processes) {
var inherit = null
var legacyWatch = null
var delay = null
var clearBuffer = null
var verbose = null
var runOnChangeOnly = null

Expand All @@ -105,6 +107,7 @@ function startScript(script, pkg, processes) {
inherit = pkg.watch[script].inherit
legacyWatch = pkg.watch[script].legacyWatch
delay = pkg.watch[script].delay
clearBuffer = pkg.watch[script].clearBuffer
verbose = pkg.watch[script].verbose
runOnChangeOnly = pkg.watch[script].runOnChangeOnly
} else {
Expand Down Expand Up @@ -140,6 +143,19 @@ function startScript(script, pkg, processes) {
stdio: inherit === true ? ['pipe', 'inherit', 'pipe'] : 'pipe'
})
if (inherit === true) return;

if (clearBuffer === true) {
proc.stdout.pipe(
through(function(line, _, callback) {
line = line.toString();
if (line.match('restarting due to changes...')) {
stdin.stdout.write(clearCharacter);
}
callback()
})
)
}

if (quiet === true || quiet === 'true') {
proc.stdout.pipe(stdin.stdout)
proc.stderr.pipe(stdin.stderr)
Expand Down

0 comments on commit e02147f

Please # to comment.