Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
0ed7ec52ee
17
.travis.yml
17
.travis.yml
@ -1,6 +1,17 @@
|
||||
sudo: false
|
||||
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- '5'
|
||||
- '4'
|
||||
- '0.10'
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "4"
|
||||
- "5"
|
||||
- "iojs"
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
|
68
CHANGELOG
68
CHANGELOG
@ -1,20 +1,28 @@
|
||||
v1.0.0:
|
||||
date: 2016-03-12
|
||||
changes:
|
||||
- Updated tiny-lr, gaze, async and lodash dependencies.
|
||||
- Fix endless loop issue with `atBegin`/`nospawn`.
|
||||
- Expose hostname parameter of tiny-lr.
|
||||
- Support `cwd.event` to emit events relative to path.
|
||||
- Removed peerDependencies setting.
|
||||
v0.6.1:
|
||||
date: 2014-03-19
|
||||
changes:
|
||||
- Fix for watch targets named "default"
|
||||
- Fix for watch targets named "default".
|
||||
v0.6.0:
|
||||
date: 2014-03-11
|
||||
changes:
|
||||
- Clear changed files after triggering live reload to ensure they're only triggered once.
|
||||
- cwd option now accepts separate settings for files and spawn.
|
||||
- '`cwd` option now accepts separate settings for files and spawn.'
|
||||
- Fix to make interrupt work more than once.
|
||||
- Enable live reload over HTTPS.
|
||||
- Print newline after initial 'Waiting...'
|
||||
- Remove deprecated grunt.util libs
|
||||
- Print newline after initial 'Waiting...'.
|
||||
- Remove deprecated `grunt.util` libs.
|
||||
- Add reload option to specify files other than Gruntfile files to reload.
|
||||
- Update to gaze@0.5.1
|
||||
- Use fork of tiny-lr (which has quiter operation, support for HTTPS and windows path fixes)
|
||||
- Add livereloadOnError, which if set to false will not trigger live reload if there is an error.
|
||||
- Update to gaze@0.5.1.
|
||||
- Use a fork of tiny-lr (which has quiter operation, support for HTTPS and Windows path fixes).
|
||||
- Add `livereloadOnError`, which if set to `false` will not trigger live reload if there is an error.
|
||||
v0.5.3:
|
||||
date: 2013-08-25
|
||||
changes:
|
||||
@ -32,8 +40,8 @@ v0.5.0:
|
||||
date: 2013-07-18
|
||||
changes:
|
||||
- Added target name to watch event.
|
||||
- Added atBegin option to run tasks when watcher starts.
|
||||
- Changed nospawn option to spawn (nospawn still available for backwards compatibility).
|
||||
- Added `atBegin` option to run tasks when watcher starts.
|
||||
- Changed `nospawn` option to `spawn` (`nospawn` still available for backwards compatibility).
|
||||
- Moved libs/vars into top scope to prevent re-init.
|
||||
- Bumped Gaze version to ~0.4.
|
||||
- Re-grab task/target options upon each task run.
|
||||
@ -42,7 +50,7 @@ v0.4.4:
|
||||
date: 2013-05-27
|
||||
changes:
|
||||
- Remove gracefully closing SIGINT. Not needed and causes problems for Windows.
|
||||
- Ensure tasks are an array to not conflict with cliArgs.
|
||||
- Ensure tasks are an array to not conflict with `cliArgs`.
|
||||
v0.4.3:
|
||||
date: 2013-05-11
|
||||
changes:
|
||||
@ -61,11 +69,11 @@ v0.4.1:
|
||||
v0.4.0:
|
||||
date: 2013-05-03
|
||||
changes:
|
||||
- Option livereload to start live reload servers.
|
||||
- Option `livereload` to start live reload servers.
|
||||
- Will reload a Gruntfile before running tasks if Gruntfile is modified.
|
||||
- Option event to only trigger watch on certain events.
|
||||
- Refactor watch task into separate task runs per target.
|
||||
- Option forever to override grunt.fatal/warn to help keeping the watch alive with nospawn enabled.
|
||||
- Option `forever` to override `grunt.fatal`/`warn` to help keeping the watch alive with `nospawn` enabled.
|
||||
- Emit a beep upon complete.
|
||||
- Logs all watched files with verbose flag set.
|
||||
- If interrupt is off, will run the tasks once more if watch triggered during a previous task run.
|
||||
@ -78,12 +86,12 @@ v0.3.1:
|
||||
v0.3.0:
|
||||
date: 2013-02-27
|
||||
changes:
|
||||
- nospawn option added to run tasks without spawning as child processes.
|
||||
- Watch emits 'watch' events upon files being triggered with grunt.event.
|
||||
- '`nospawn` option added to run tasks without spawning as child processes.'
|
||||
- Watch emits 'watch' events upon files being triggered with `grunt.event`.
|
||||
- Completion time in seconds and date/time shown after tasks ran.
|
||||
- Negate file patterns fixed.
|
||||
- Tasks debounced individually to handle simultaneous triggering for multiple targets.
|
||||
- Errors handled better and viewable with --stack cli option.
|
||||
- Errors handled better and viewable with `--stack` CLI option.
|
||||
- Code complexity reduced making the watch task code easier to read.
|
||||
v0.2.0:
|
||||
date: 2013-02-15
|
||||
@ -102,34 +110,34 @@ v0.2.0a:
|
||||
date: 2012-12-15
|
||||
changes:
|
||||
- Conversion to grunt v0.4 conventions.
|
||||
- Remove node v0.6 and grunt v0.3 support.
|
||||
- Remove Node.js v0.6 and grunt v0.3 support.
|
||||
- Allow watch task to be renamed.
|
||||
- Use grunt.util.spawn "grunt" option.
|
||||
- Updated to gaze@0.3.0, forceWatchMethod option removed.
|
||||
- Use `grunt.util.spawn` "grunt" option.
|
||||
- Updated to gaze@0.3.0, `forceWatchMethod` option removed.
|
||||
v0.1.4:
|
||||
date: 2012-11-01
|
||||
changes:
|
||||
- Prevent watch from spawning duplicate watch tasks
|
||||
- Prevent watch from spawning duplicate watch tasks.
|
||||
v0.1.3:
|
||||
date: 2012-10-28
|
||||
changes:
|
||||
- Better method to spawn the grunt bin
|
||||
- Bump gaze to v0.2.0. Better handles some events and new option forceWatchMethod
|
||||
- Only support Node.js >= v0.8
|
||||
- Better method to spawn the grunt bin.
|
||||
- Bump gaze to v0.2.0. Better handles some events and new option `forceWatchMethod`.
|
||||
- Only support Node.js >= v0.8.
|
||||
v0.1.2:
|
||||
date: 2012-10-17
|
||||
changes:
|
||||
- Only spawn a process per task one at a time
|
||||
- Add interrupt option to cancel previous spawned process
|
||||
- Grunt v0.3 compatibility changes
|
||||
- Only spawn a process per task one at a time.
|
||||
- Add `interrupt` option to cancel previous spawned process.
|
||||
- Grunt v0.3 compatibility changes.
|
||||
v0.1.1:
|
||||
date: 2012-10-16
|
||||
changes:
|
||||
- Fallback to global grunt bin if local doesnt exist. Fatal if bin cannot be found
|
||||
- Update to gaze 0.1.6
|
||||
- Fallback to global grunt bin if local doesn't exist. Fatal if bin cannot be found.
|
||||
- Update to gaze 0.1.6.
|
||||
v0.1.0:
|
||||
date: 2012-10-08
|
||||
changes:
|
||||
- Release watch task
|
||||
- Remove spawn from helper
|
||||
- Run on Grunt v0.4
|
||||
- Release watch task.
|
||||
- Remove spawn from helper.
|
||||
- Run on Grunt v0.4.
|
||||
|
16
Gruntfile.js
16
Gruntfile.js
@ -2,7 +2,7 @@
|
||||
* grunt-contrib-watch
|
||||
* http://gruntjs.com/
|
||||
*
|
||||
* Copyright (c) 2015 "Cowboy" Ben Alman, contributors
|
||||
* Copyright (c) 2016 "Cowboy" Ben Alman, contributors
|
||||
* Licensed under the MIT license.
|
||||
*/
|
||||
|
||||
@ -14,11 +14,11 @@ module.exports = function(grunt) {
|
||||
all: [
|
||||
'Gruntfile.js',
|
||||
'tasks/**/*.js',
|
||||
'<%= nodeunit.tests %>',
|
||||
'<%= nodeunit.tests %>'
|
||||
],
|
||||
options: {
|
||||
jshintrc: '.jshintrc',
|
||||
},
|
||||
jshintrc: '.jshintrc'
|
||||
}
|
||||
},
|
||||
jscs: {
|
||||
src: ['tasks/**/*.js', 'test/tasks/**/*.js'],
|
||||
@ -29,12 +29,12 @@ module.exports = function(grunt) {
|
||||
watch: {
|
||||
all: {
|
||||
files: ['<%= jshint.all %>'],
|
||||
tasks: ['jshint', 'nodeunit'],
|
||||
},
|
||||
tasks: ['jshint', 'nodeunit']
|
||||
}
|
||||
},
|
||||
nodeunit: {
|
||||
tests: ['test/tasks/*_test.js'],
|
||||
},
|
||||
tests: ['test/tasks/*_test.js']
|
||||
}
|
||||
});
|
||||
|
||||
// Dynamic alias task to nodeunit. Run individual tests with: grunt test:events
|
||||
|
@ -1,4 +1,4 @@
|
||||
Copyright (c) 2014 "Cowboy" Ben Alman, contributors
|
||||
Copyright (c) 2016 "Cowboy" Ben Alman, contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
98
README.md
98
README.md
@ -1,11 +1,10 @@
|
||||
# grunt-contrib-watch v0.6.1 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-watch.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-watch)
|
||||
# grunt-contrib-watch v1.0.0 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-watch.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-watch) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/olyu3uhcq59avm8v/branch/master?svg=true)](https://ci.appveyor.com/project/gruntjs/grunt-contrib-watch/branch/master)
|
||||
|
||||
> Run predefined tasks whenever watched file patterns are added, changed or deleted
|
||||
|
||||
|
||||
|
||||
## Getting Started
|
||||
This plugin requires Grunt `>=0.4.0`
|
||||
|
||||
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
|
||||
|
||||
@ -33,7 +32,7 @@ There are a number of options available. Please review the [minimatch options he
|
||||
#### files
|
||||
Type: `String|Array`
|
||||
|
||||
This defines what file patterns this task will watch. Can be a string or an array of files and/or minimatch patterns.
|
||||
This defines what file patterns this task will watch. It can be a string or an array of files and/or minimatch patterns.
|
||||
|
||||
#### tasks
|
||||
Type: `String|Array`
|
||||
@ -41,8 +40,8 @@ Type: `String|Array`
|
||||
This defines which tasks to run when a watched file event occurs.
|
||||
|
||||
#### options.spawn
|
||||
Type: `Boolean`
|
||||
Default: true
|
||||
Type: `Boolean`
|
||||
Default: `true`
|
||||
|
||||
Whether to spawn task runs in a child process. Setting this option to `false` speeds up the reaction time of the watch (usually 500ms faster for most) and allows subsequent task runs to share the same context. Not spawning task runs can make the watch more prone to failing so please use as needed.
|
||||
|
||||
@ -62,8 +61,8 @@ watch: {
|
||||
*For backwards compatibility the option `nospawn` is still available and will do the opposite of `spawn`.*
|
||||
|
||||
#### options.interrupt
|
||||
Type: `Boolean`
|
||||
Default: false
|
||||
Type: `Boolean`
|
||||
Default: `false`
|
||||
|
||||
As files are modified this watch task will spawn tasks in child processes. The default behavior will only spawn a new child process per target when the previous process has finished. Set the `interrupt` option to true to terminate the previous process and spawn a new one upon later changes.
|
||||
|
||||
@ -81,8 +80,8 @@ watch: {
|
||||
```
|
||||
|
||||
#### options.debounceDelay
|
||||
Type: `Integer`
|
||||
Default: 500
|
||||
Type: `Integer`
|
||||
Default: `500`
|
||||
|
||||
How long to wait before emitting events in succession for the same filepath and status. For example if your `Gruntfile.js` file was `changed`, a `changed` event will only fire again after the given milliseconds.
|
||||
|
||||
@ -100,13 +99,13 @@ watch: {
|
||||
```
|
||||
|
||||
#### options.interval
|
||||
Type: `Integer`
|
||||
Default: 100
|
||||
Type: `Integer`
|
||||
Default: `100`
|
||||
|
||||
The `interval` is passed to `fs.watchFile`. Since `interval` is only used by `fs.watchFile` and this watcher also uses `fs.watch`; it is recommended to ignore this option. *Default is 100ms*.
|
||||
|
||||
#### options.event
|
||||
Type: `String|Array`
|
||||
Type: `String|Array`
|
||||
Default: `'all'`
|
||||
|
||||
Specify the type of watch events that triggers the specified task. This option can be one or many of: `'all'`, `'changed'`, `'added'` and `'deleted'`.
|
||||
@ -125,7 +124,7 @@ watch: {
|
||||
```
|
||||
|
||||
#### options.reload
|
||||
Type: `Boolean`
|
||||
Type: `Boolean`
|
||||
Default: `false`
|
||||
|
||||
By default, if `Gruntfile.js` is being watched, then changes to it will trigger the watch task to restart, and reload the `Gruntfile.js` changes.
|
||||
@ -145,8 +144,8 @@ watch: {
|
||||
|
||||
|
||||
#### options.forever
|
||||
Type: `Boolean`
|
||||
Default: true
|
||||
Type: `Boolean`
|
||||
Default: `true`
|
||||
|
||||
This is *only a task level option* and cannot be configured per target. By default the watch task will duck punch `grunt.fatal` and `grunt.warn` to try and prevent them from exiting the watch process. If you don't want `grunt.fatal` and `grunt.warn` to be overridden set the `forever` option to `false`.
|
||||
|
||||
@ -171,14 +170,14 @@ watch: {
|
||||
```
|
||||
|
||||
#### options.atBegin
|
||||
Type: `Boolean`
|
||||
Default: false
|
||||
Type: `Boolean`
|
||||
Default: `false`
|
||||
|
||||
This option will trigger the run of each specified task at startup of the watcher.
|
||||
|
||||
#### options.livereload
|
||||
Type: `Boolean|Number|Object`
|
||||
Default: false
|
||||
Type: `Boolean|Number|Object`
|
||||
Default: `false`
|
||||
|
||||
Set to `true` or set `livereload: 1337` to a port number to enable live reloading. Default and recommended port is `35729`.
|
||||
|
||||
@ -222,19 +221,36 @@ watch: {
|
||||
|
||||
|
||||
#### options.cwd
|
||||
Type: `String|Object`
|
||||
Type: `String|Object`
|
||||
Default: `process.cwd()`
|
||||
|
||||
Ability to set the current working directory. Defaults to `process.cwd()`. Can either be a string to set the cwd to match files and spawn tasks. Or an object to set each independently. Such as `options: { cwd: { files: 'match/files/from/here', spawn: 'but/spawn/files/from/here' } }`.
|
||||
Ability to set the current working directory. Defaults to `process.cwd()`. Can either be a string to set the cwd to match files and spawn tasks or an object to set each independently. Such as:
|
||||
```js
|
||||
options: {
|
||||
cwd: {
|
||||
files: 'match/files/from/here',
|
||||
spawn: 'but/spawn/files/from/here'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Set `options: { cwd: { files: 'a/path', event: 'a/path' }}` to strip off `a/path` before emitting events. This option is useful for specifying the base directory to use with livereload.
|
||||
To strip off a path before emitting events:
|
||||
```js
|
||||
options: {
|
||||
cwd: {
|
||||
files: 'a/path',
|
||||
event: 'a/path'
|
||||
}
|
||||
}
|
||||
```
|
||||
This will strip off `a/path` before emitting events. This option is useful for specifying the base directory to use with livereload.
|
||||
|
||||
|
||||
#### options.livereloadOnError
|
||||
Type: `Boolean`
|
||||
Default: `true`
|
||||
|
||||
Option to prevent the livereload if the executed tasks encountered an error. If set to `false`, the livereload will only be triggered if all tasks completed successfully.
|
||||
Option to prevent the livereload if the executed tasks encountered an error. If set to `false`, the livereload will only be triggered if all tasks completed successfully.
|
||||
|
||||
### Examples
|
||||
|
||||
@ -307,7 +323,7 @@ grunt.initConfig({
|
||||
},
|
||||
});
|
||||
|
||||
// on watch events configure jshint:all to only run on changed file
|
||||
// On watch events configure jshint:all to only run on changed file
|
||||
grunt.event.on('watch', function(action, filepath) {
|
||||
grunt.config('jshint.all.src', filepath);
|
||||
});
|
||||
@ -453,40 +469,46 @@ Likely because of an enthusiastic pattern trying to watch thousands of files. Su
|
||||
Another reason if you're watching a large number of files could be the low default `interval`. Try increasing with `options: { interval: 5007 }`. Please see issues [#35](https://github.com/gruntjs/grunt-contrib-watch/issues/35) and [#145](https://github.com/gruntjs/grunt-contrib-watch/issues/145) for more information.
|
||||
|
||||
#### Why spawn as child processes as a default?
|
||||
The goal of this watch task is as files are changed, run tasks as if they were triggered by the user themself. Each time a user runs `grunt` a process is spawned and tasks are ran in succession. In an effort to keep the experience consistent and continually produce expected results, this watch task spawns tasks as child processes by default.
|
||||
The goal of this watch task is as files are changed, run tasks as if they were triggered by the user himself or herself. Each time a user runs `grunt` a process is spawned and tasks are ran in succession. In an effort to keep the experience consistent and continually produce expected results, this watch task spawns tasks as child processes by default.
|
||||
|
||||
Sandboxing task runs also allows this watch task to run more stable over long periods of time. As well as more efficiently with more complex tasks and file structures.
|
||||
|
||||
Spawning does cause a performance hit (usually 500ms for most environments). It also cripples tasks that rely on the watch task to share the context with each subsequent run (i.e., reload tasks). If you would like a faster watch task or need to share the context please set the `spawn` option to `false`. Just be aware that with this option enabled, the watch task is more prone to failure.
|
||||
|
||||
#### How can I have the browser reload for files listed in a task?
|
||||
Instead of restarting your server each time a static file is changed, start a static web server using (grunt-contrib-connect)[https://github.com/gruntjs/grunt-contrib-connect].
|
||||
|
||||
You'll have the `connect` web server on seperate port ex: port 9000 from your main server. When the 'livereload' option is enabled for 'watch' tasks, it will handle triggerring the live reload server for each tasks and when files are modified, which then server back to main server ex: 3000. The main server must include a script tag or a browser extension to the livereload server in order for the browser automatically.
|
||||
|
||||
|
||||
## Release History
|
||||
|
||||
* 2014-03-19 v0.6.1 Fix for watch targets named "default"
|
||||
* 2014-03-11 v0.6.0 Clear changed files after triggering live reload to ensure they're only triggered once. cwd option now accepts separate settings for files and spawn. Fix to make interrupt work more than once. Enable live reload over HTTPS. Print newline after initial 'Waiting...' Remove deprecated grunt.util libs Add reload option to specify files other than Gruntfile files to reload. Update to gaze@0.5.1 Use fork of tiny-lr (which has quiter operation, support for HTTPS and windows path fixes) Add livereloadOnError, which if set to false will not trigger live reload if there is an error.
|
||||
* 2016-03-12 v1.0.0 Updated tiny-lr, gaze, async and lodash dependencies. Fix endless loop issue with `atBegin`/`nospawn`. Expose hostname parameter of tiny-lr. Support `cwd.event` to emit events relative to path. Removed peerDependencies setting.
|
||||
* 2014-03-19 v0.6.1 Fix for watch targets named "default".
|
||||
* 2014-03-11 v0.6.0 Clear changed files after triggering live reload to ensure they're only triggered once. `cwd` option now accepts separate settings for files and spawn. Fix to make interrupt work more than once. Enable live reload over HTTPS. Print newline after initial 'Waiting...'. Remove deprecated `grunt.util` libs. Add reload option to specify files other than Gruntfile files to reload. Update to gaze@0.5.1. Use a fork of tiny-lr (which has quiter operation, support for HTTPS and Windows path fixes). Add `livereloadOnError`, which if set to `false` will not trigger live reload if there is an error.
|
||||
* 2013-08-25 v0.5.3 Fixed for live reload missing files.
|
||||
* 2013-08-16 v0.5.2 Fixed issue running tasks after gruntfile is reloaded. Ignores empty file paths.
|
||||
* 2013-07-20 v0.5.1 Fixed issue with options resetting.
|
||||
* 2013-07-18 v0.5.0 Added target name to watch event. Added atBegin option to run tasks when watcher starts. Changed nospawn option to spawn (nospawn still available for backwards compatibility). Moved libs/vars into top scope to prevent re-init. Bumped Gaze version to ~0.4. Re-grab task/target options upon each task run. Add dateFormat option to override the date/time output upon completion.
|
||||
* 2013-05-27 v0.4.4 Remove gracefully closing SIGINT. Not needed and causes problems for Windows. Ensure tasks are an array to not conflict with cliArgs.
|
||||
* 2013-07-18 v0.5.0 Added target name to watch event. Added `atBegin` option to run tasks when watcher starts. Changed `nospawn` option to `spawn` (`nospawn` still available for backwards compatibility). Moved libs/vars into top scope to prevent re-init. Bumped Gaze version to ~0.4. Re-grab task/target options upon each task run. Add dateFormat option to override the date/time output upon completion.
|
||||
* 2013-05-27 v0.4.4 Remove gracefully closing SIGINT. Not needed and causes problems for Windows. Ensure tasks are an array to not conflict with `cliArgs`.
|
||||
* 2013-05-11 v0.4.3 Only group changed files per target to send correct files to live reload.
|
||||
* 2013-05-09 v0.4.2 Fix for closing watchers.
|
||||
* 2013-05-09 v0.4.1 Removed "beep" notification. Tasks now optional with livereload option. Reverted "run again" with interrupt off to fix infinite recursion issue. Watchers now close more properly on task run.
|
||||
* 2013-05-03 v0.4.0 Option livereload to start live reload servers. Will reload a Gruntfile before running tasks if Gruntfile is modified. Option event to only trigger watch on certain events. Refactor watch task into separate task runs per target. Option forever to override grunt.fatal/warn to help keeping the watch alive with nospawn enabled. Emit a beep upon complete. Logs all watched files with verbose flag set. If interrupt is off, will run the tasks once more if watch triggered during a previous task run. tasks property is optional for use with watch event. Watchers properly closed when exiting.
|
||||
* 2013-05-03 v0.4.0 Option `livereload` to start live reload servers. Will reload a Gruntfile before running tasks if Gruntfile is modified. Option event to only trigger watch on certain events. Refactor watch task into separate task runs per target. Option `forever` to override `grunt.fatal`/`warn` to help keeping the watch alive with `nospawn` enabled. Emit a beep upon complete. Logs all watched files with verbose flag set. If interrupt is off, will run the tasks once more if watch triggered during a previous task run. tasks property is optional for use with watch event. Watchers properly closed when exiting.
|
||||
* 2013-02-28 v0.3.1 Fix for top level options.
|
||||
* 2013-02-27 v0.3.0 nospawn option added to run tasks without spawning as child processes. Watch emits 'watch' events upon files being triggered with grunt.event. Completion time in seconds and date/time shown after tasks ran. Negate file patterns fixed. Tasks debounced individually to handle simultaneous triggering for multiple targets. Errors handled better and viewable with --stack cli option. Code complexity reduced making the watch task code easier to read.
|
||||
* 2013-02-27 v0.3.0 `nospawn` option added to run tasks without spawning as child processes. Watch emits 'watch' events upon files being triggered with `grunt.event`. Completion time in seconds and date/time shown after tasks ran. Negate file patterns fixed. Tasks debounced individually to handle simultaneous triggering for multiple targets. Errors handled better and viewable with `--stack` CLI option. Code complexity reduced making the watch task code easier to read.
|
||||
* 2013-02-15 v0.2.0 First official release for Grunt 0.4.0.
|
||||
* 2013-01-18 v0.2.0rc7 Updating grunt/gruntplugin dependencies to rc6. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions.
|
||||
* 2013-01-09 v0.2.0rc5 Updating to work with grunt v0.4.0rc5.
|
||||
* 2012-12-15 v0.2.0a Conversion to grunt v0.4 conventions. Remove node v0.6 and grunt v0.3 support. Allow watch task to be renamed. Use grunt.util.spawn "grunt" option. Updated to gaze@0.3.0, forceWatchMethod option removed.
|
||||
* 2012-11-01 v0.1.4 Prevent watch from spawning duplicate watch tasks
|
||||
* 2012-10-28 v0.1.3 Better method to spawn the grunt bin Bump gaze to v0.2.0. Better handles some events and new option forceWatchMethod Only support Node.js >= v0.8
|
||||
* 2012-10-17 v0.1.2 Only spawn a process per task one at a time Add interrupt option to cancel previous spawned process Grunt v0.3 compatibility changes
|
||||
* 2012-10-16 v0.1.1 Fallback to global grunt bin if local doesnt exist. Fatal if bin cannot be found Update to gaze 0.1.6
|
||||
* 2012-10-08 v0.1.0 Release watch task Remove spawn from helper Run on Grunt v0.4
|
||||
* 2012-12-15 v0.2.0a Conversion to grunt v0.4 conventions. Remove Node.js v0.6 and grunt v0.3 support. Allow watch task to be renamed. Use `grunt.util.spawn` "grunt" option. Updated to gaze@0.3.0, `forceWatchMethod` option removed.
|
||||
* 2012-11-01 v0.1.4 Prevent watch from spawning duplicate watch tasks.
|
||||
* 2012-10-28 v0.1.3 Better method to spawn the grunt bin. Bump gaze to v0.2.0. Better handles some events and new option `forceWatchMethod`. Only support Node.js >= v0.8.
|
||||
* 2012-10-17 v0.1.2 Only spawn a process per task one at a time. Add `interrupt` option to cancel previous spawned process. Grunt v0.3 compatibility changes.
|
||||
* 2012-10-16 v0.1.1 Fallback to global grunt bin if local doesn't exist. Fatal if bin cannot be found. Update to gaze 0.1.6.
|
||||
* 2012-10-08 v0.1.0 Release watch task. Remove spawn from helper. Run on Grunt v0.4.
|
||||
|
||||
---
|
||||
|
||||
Task submitted by [Kyle Robinson Young](http://dontkry.com)
|
||||
|
||||
*This file was generated on Sun Oct 11 2015 13:29:21.*
|
||||
*This file was generated on Fri Mar 18 2016 19:24:09.*
|
||||
|
37
appveyor.yml
Normal file
37
appveyor.yml
Normal file
@ -0,0 +1,37 @@
|
||||
clone_depth: 10
|
||||
|
||||
version: "{build}"
|
||||
|
||||
# What combinations to test
|
||||
environment:
|
||||
matrix:
|
||||
- nodejs_version: "0.10"
|
||||
platform: x86
|
||||
- nodejs_version: "0.12"
|
||||
platform: x86
|
||||
- nodejs_version: "4"
|
||||
platform: x64
|
||||
- nodejs_version: "4"
|
||||
platform: x86
|
||||
- nodejs_version: "5"
|
||||
platform: x86
|
||||
|
||||
install:
|
||||
- ps: Install-Product node $env:nodejs_version $env:platform
|
||||
- npm install
|
||||
|
||||
test_script:
|
||||
# Output useful info for debugging
|
||||
- node --version && npm --version
|
||||
# We test multiple Windows shells because of prior stdout buffering issues
|
||||
# filed against Grunt. https://github.com/joyent/node/issues/3584
|
||||
- ps: "npm test # PowerShell" # Pass comment to PS for easier debugging
|
||||
- cmd: npm test
|
||||
|
||||
build: off
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
cache:
|
||||
- node_modules -> package.json
|
29
package.json
29
package.json
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "grunt-contrib-watch",
|
||||
"description": "Run predefined tasks whenever watched file patterns are added, changed or deleted",
|
||||
"version": "0.6.1",
|
||||
"version": "1.0.0",
|
||||
"author": {
|
||||
"name": "Grunt Team",
|
||||
"url": "http://gruntjs.com/"
|
||||
@ -11,26 +11,24 @@
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"main": "tasks/watch.js",
|
||||
"scripts": {
|
||||
"test": "grunt test -v"
|
||||
},
|
||||
"dependencies": {
|
||||
"gaze": "^0.5.1",
|
||||
"tiny-lr": "^0.1.4",
|
||||
"lodash": "^2.4.1",
|
||||
"async": "^0.9.0"
|
||||
"async": "^1.5.0",
|
||||
"gaze": "^1.1.0",
|
||||
"lodash": "^4.0.0",
|
||||
"tiny-lr": "^0.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"grunt": "^0.4.5",
|
||||
"grunt-cli": "^0.1.13",
|
||||
"grunt-contrib-internal": "^0.4.7",
|
||||
"grunt-contrib-jshint": "^0.10.0",
|
||||
"grunt-contrib-nodeunit": "^0.4.1",
|
||||
"grunt-jscs": "^2.1.0",
|
||||
"underscore.string": "^2.3.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"grunt": ">=0.4.0"
|
||||
"grunt-cli": "^1.2.0",
|
||||
"grunt-contrib-internal": "^1.2.0",
|
||||
"grunt-contrib-jshint": "^1.0.0",
|
||||
"grunt-contrib-nodeunit": "^1.0.0",
|
||||
"grunt-jscs": "^3.0.0",
|
||||
"underscore.string": "^3.2.2"
|
||||
},
|
||||
"keywords": [
|
||||
"gruntplugin",
|
||||
@ -39,5 +37,6 @@
|
||||
],
|
||||
"files": [
|
||||
"tasks"
|
||||
]
|
||||
],
|
||||
"appveyor_id": "olyu3uhcq59avm8v"
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* grunt-contrib-watch
|
||||
* http://gruntjs.com/
|
||||
*
|
||||
* Copyright (c) 2015 "Cowboy" Ben Alman, contributors
|
||||
* Copyright (c) 2016 "Cowboy" Ben Alman, contributors
|
||||
* Licensed under the MIT license.
|
||||
*/
|
||||
|
||||
@ -43,7 +43,9 @@ module.exports = function(grunt) {
|
||||
process.exit(1);
|
||||
});
|
||||
this.server.listen(options.port, options.host, function(err) {
|
||||
if (err) { return grunt.fatal(err); }
|
||||
if (err) {
|
||||
return grunt.fatal(err);
|
||||
}
|
||||
grunt.log.verbose.writeln('Live reload server started on ' + host);
|
||||
});
|
||||
servers[host] = this.server;
|
||||
|
@ -2,7 +2,7 @@
|
||||
* grunt-contrib-watch
|
||||
* http://gruntjs.com/
|
||||
*
|
||||
* Copyright (c) 2015 "Cowboy" Ben Alman, contributors
|
||||
* Copyright (c) 2016 "Cowboy" Ben Alman, contributors
|
||||
* Licensed under the MIT license.
|
||||
*/
|
||||
|
||||
@ -41,7 +41,9 @@ module.exports = function(grunt) {
|
||||
var self = this;
|
||||
|
||||
// Dont run if already running
|
||||
if (self.startedAt !== false) { return; }
|
||||
if (self.startedAt !== false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Start this task run
|
||||
self.startedAt = Date.now();
|
||||
@ -57,7 +59,9 @@ module.exports = function(grunt) {
|
||||
}
|
||||
|
||||
// If no tasks just call done to trigger potential livereload
|
||||
if (self.tasks.length < 1) { return done(); }
|
||||
if (self.tasks.length < 1) {
|
||||
return done();
|
||||
}
|
||||
|
||||
if (self.options.spawn === false || self.options.nospawn === true) {
|
||||
grunt.task.run(self.tasks);
|
||||
@ -78,7 +82,7 @@ module.exports = function(grunt) {
|
||||
// Run from current working dir and inherit stdio from process
|
||||
opts: {
|
||||
cwd: self.options.cwd.spawn,
|
||||
stdio: 'inherit',
|
||||
stdio: 'inherit'
|
||||
},
|
||||
// Run grunt this process uses, append the task to be run and any cli options
|
||||
args: self.tasks.concat(cliArgs || []),
|
||||
|
@ -2,7 +2,7 @@
|
||||
* grunt-contrib-watch
|
||||
* http://gruntjs.com/
|
||||
*
|
||||
* Copyright (c) 2015 "Cowboy" Ben Alman, contributors
|
||||
* Copyright (c) 2016 "Cowboy" Ben Alman, contributors
|
||||
* Licensed under the MIT license.
|
||||
*/
|
||||
|
||||
@ -57,7 +57,7 @@ module.exports = function(grunt) {
|
||||
self.name = name || grunt.task.current.name || 'watch';
|
||||
self.options = self._options(grunt.config([self.name, 'options']) || {}, defaults || {});
|
||||
self.reload = false;
|
||||
self.nameArgs = (grunt.task.current.nameArgs) ? grunt.task.current.nameArgs : self.name;
|
||||
self.nameArgs = grunt.task.current.nameArgs ? grunt.task.current.nameArgs : self.name;
|
||||
|
||||
// Normalize cwd option
|
||||
if (typeof self.options.cwd === 'string') {
|
||||
@ -121,10 +121,12 @@ module.exports = function(grunt) {
|
||||
|
||||
grunt.task.current.requiresConfig(name);
|
||||
var config = grunt.config(name);
|
||||
var onlyTarget = (self.options.target) ? self.options.target : false;
|
||||
var onlyTarget = self.options.target ? self.options.target : false;
|
||||
|
||||
var targets = (onlyTarget ? [onlyTarget] : Object.keys(config)).filter(function(key) {
|
||||
if (key === 'options') { return false; }
|
||||
if (key === 'options') {
|
||||
return false;
|
||||
}
|
||||
return typeof config[key] !== 'string' && !Array.isArray(config[key]);
|
||||
}).map(function(target) {
|
||||
// Fail if any required config properties have been omitted
|
||||
@ -142,7 +144,7 @@ module.exports = function(grunt) {
|
||||
files: config.files,
|
||||
tasks: config.tasks,
|
||||
name: defaultTargetName,
|
||||
options: self._options(config.options || {}, self.options),
|
||||
options: self._options(config.options || {}, self.options)
|
||||
};
|
||||
targets.push(cfg);
|
||||
self.add(cfg);
|
||||
@ -163,7 +165,7 @@ module.exports = function(grunt) {
|
||||
spawn: true,
|
||||
atBegin: false,
|
||||
event: ['all'],
|
||||
target: null,
|
||||
target: null
|
||||
});
|
||||
return _.defaults.apply(_, args);
|
||||
};
|
||||
@ -198,7 +200,9 @@ module.exports = function(grunt) {
|
||||
}
|
||||
|
||||
// If we should reload
|
||||
if (self.reload) { return self.reloadTask(); }
|
||||
if (self.reload) {
|
||||
return self.reloadTask();
|
||||
}
|
||||
|
||||
// Trigger that tasks runs have started
|
||||
self.emit('start');
|
||||
@ -208,7 +212,9 @@ module.exports = function(grunt) {
|
||||
var shouldComplete = true;
|
||||
async.forEachSeries(self.queue, function(name, next) {
|
||||
var tr = self.targets[name];
|
||||
if (!tr) { return next(); }
|
||||
if (!tr) {
|
||||
return next();
|
||||
}
|
||||
|
||||
// Re-grab options in case they changed between runs
|
||||
tr.options = self._options(grunt.config([self.name, name, 'options']) || {}, tr.options, self.options);
|
||||
@ -235,8 +241,12 @@ module.exports = function(grunt) {
|
||||
// Private method for getting latest config for a watch target
|
||||
target._getConfig = function(name) {
|
||||
var cfgPath = [self.name];
|
||||
if (target.name !== defaultTargetName) { cfgPath.push(target.name); }
|
||||
if (name) { cfgPath.push(name); }
|
||||
if (target.name !== defaultTargetName) {
|
||||
cfgPath.push(target.name);
|
||||
}
|
||||
if (name) {
|
||||
cfgPath.push(name);
|
||||
}
|
||||
return grunt.config(cfgPath);
|
||||
};
|
||||
|
||||
@ -262,13 +272,17 @@ module.exports = function(grunt) {
|
||||
// Do this when queued task runs have completed/scheduled
|
||||
Runner.prototype.complete = function complete() {
|
||||
var self = this;
|
||||
if (self.running === false) { return; }
|
||||
if (self.running === false) {
|
||||
return;
|
||||
}
|
||||
self.running = false;
|
||||
var time = 0;
|
||||
for (var i = 0, len = self.queue.length; i < len; ++i) {
|
||||
var name = self.queue[i];
|
||||
var target = self.targets[name];
|
||||
if (!target) { return; }
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
if (target.startedAt !== false) {
|
||||
time += target.complete();
|
||||
self.queue.splice(i--, 1);
|
||||
@ -291,7 +305,9 @@ module.exports = function(grunt) {
|
||||
var self = this;
|
||||
self.queue.forEach(function(name) {
|
||||
var target = self.targets[name];
|
||||
if (!target) { return; }
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
target.complete();
|
||||
});
|
||||
};
|
||||
|
@ -2,10 +2,12 @@
|
||||
* grunt-contrib-watch
|
||||
* http://gruntjs.com/
|
||||
*
|
||||
* Copyright (c) 2015 "Cowboy" Ben Alman, contributors
|
||||
* Copyright (c) 2016 "Cowboy" Ben Alman, contributors
|
||||
* Licensed under the MIT license.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var Gaze = require('gaze').Gaze;
|
||||
var _ = require('lodash');
|
||||
@ -14,7 +16,6 @@ var changedFiles = Object.create(null);
|
||||
var watchers = [];
|
||||
|
||||
module.exports = function(grunt) {
|
||||
'use strict';
|
||||
|
||||
var taskrun = require('./lib/taskrunner')(grunt);
|
||||
|
||||
@ -77,13 +78,17 @@ module.exports = function(grunt) {
|
||||
dateFormat = df;
|
||||
}
|
||||
|
||||
if (taskrun.running === false) { grunt.log.writeln(waiting); }
|
||||
if (taskrun.running === false) {
|
||||
grunt.log.writeln(waiting);
|
||||
}
|
||||
|
||||
// Initialize taskrun
|
||||
var targets = taskrun.init(name, {target: target});
|
||||
|
||||
targets.forEach(function(target) {
|
||||
if (typeof target.files === 'string') { target.files = [target.files]; }
|
||||
if (typeof target.files === 'string') {
|
||||
target.files = [target.files];
|
||||
}
|
||||
|
||||
// Process into raw patterns
|
||||
var patterns = _.chain(target.files).flatten().map(function(pattern) {
|
||||
@ -108,7 +113,9 @@ module.exports = function(grunt) {
|
||||
// Create watcher per target
|
||||
watchers.push(new Gaze(patterns, target.options, function(err) {
|
||||
if (err) {
|
||||
if (typeof err === 'string') { err = new Error(err); }
|
||||
if (typeof err === 'string') {
|
||||
err = new Error(err);
|
||||
}
|
||||
grunt.log.writeln('ERROR'.red);
|
||||
grunt.fatal(err);
|
||||
return taskrun.done();
|
||||
@ -128,8 +135,8 @@ module.exports = function(grunt) {
|
||||
this.on('all', function(status, filepath) {
|
||||
|
||||
// Skip events not specified
|
||||
if (!_.contains(target.options.event, 'all') &&
|
||||
!_.contains(target.options.event, status)) {
|
||||
if (!_.includes(target.options.event, 'all') &&
|
||||
!_.includes(target.options.event, status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -172,7 +179,9 @@ module.exports = function(grunt) {
|
||||
|
||||
// On watcher error
|
||||
this.on('error', function(err) {
|
||||
if (typeof err === 'string') { err = new Error(err); }
|
||||
if (typeof err === 'string') {
|
||||
err = new Error(err);
|
||||
}
|
||||
grunt.log.error(err.message);
|
||||
});
|
||||
}));
|
||||
|
2
test/fixtures/tasks/echo.js
vendored
2
test/fixtures/tasks/echo.js
vendored
@ -2,7 +2,7 @@
|
||||
* grunt-contrib-watch
|
||||
* http://gruntjs.com/
|
||||
*
|
||||
* Copyright (c) 2015 "Cowboy" Ben Alman, contributors
|
||||
* Copyright (c) 2016 "Cowboy" Ben Alman, contributors
|
||||
* Licensed under the MIT license.
|
||||
*/
|
||||
|
||||
|
@ -161,5 +161,5 @@ exports.events = {
|
||||
test.ok(result.indexOf('Ive changed') !== -1, 'should run task set in event listener');
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
@ -51,5 +51,5 @@ exports.fail = {
|
||||
test.ok(result.match(/This task should be fatal/g).length === 2, 'grunt.fatal should not stop the watch task.');
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
@ -10,7 +10,9 @@ helper.fixtures = path.join(__dirname, '..', 'fixtures');
|
||||
// If verbose flag set, display output
|
||||
helper.verboseLog = function() {};
|
||||
if (_.indexOf(process.argv, '-v') !== -1) {
|
||||
helper.verboseLog = function() { console.log.apply(null, arguments); };
|
||||
helper.verboseLog = function() {
|
||||
console.log.apply(null, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
// helper for creating assertTasks for testing tasks in child processes
|
||||
@ -49,7 +51,11 @@ helper.assertTask = function assertTask(task, options) {
|
||||
|
||||
// Append a last function to kill spawnGrunt
|
||||
runs.push(function() {
|
||||
spawnGrunt.kill('SIGINT');
|
||||
// TODO: This pattern needs to be fixed. It causes async timing issues.
|
||||
// each run() function should let it know when its done.
|
||||
setTimeout(function() {
|
||||
spawnGrunt.kill('SIGINT');
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// After watch starts waiting, run our commands then exit
|
||||
@ -69,7 +75,9 @@ helper.assertTask = function assertTask(task, options) {
|
||||
if (shouldRun) {
|
||||
setTimeout(function() {
|
||||
var run = runs.shift();
|
||||
if (typeof run === 'function') { run(); }
|
||||
if (typeof run === 'function') {
|
||||
run();
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
@ -90,7 +98,9 @@ helper.assertTask = function assertTask(task, options) {
|
||||
|
||||
// clean up files within fixtures
|
||||
helper.cleanUp = function cleanUp(files) {
|
||||
if (typeof files === 'string') { files = [files]; }
|
||||
if (typeof files === 'string') {
|
||||
files = [files];
|
||||
}
|
||||
files.forEach(function(filepath) {
|
||||
filepath = path.join(helper.fixtures, filepath);
|
||||
if (grunt.file.exists(filepath)) {
|
||||
|
@ -10,7 +10,7 @@ var fixtures = helper.fixtures;
|
||||
|
||||
function cleanUp() {
|
||||
helper.cleanUp([
|
||||
'livereload/node_modules',
|
||||
'livereload/node_modules'
|
||||
]);
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ function request(port, done) {
|
||||
var data = '';
|
||||
var req = http.request({
|
||||
hostname: 'localhost',
|
||||
port: port,
|
||||
port: port
|
||||
}, function(res) {
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', function(chunk) {
|
||||
@ -235,5 +235,5 @@ exports.livereload = {
|
||||
'Should not livereload when a task errors with flag and spawn=false');
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
@ -35,7 +35,7 @@ exports.nospawn = {
|
||||
grunt.file.write(path.join(cwd, 'lib', 'nospawn.js'), write);
|
||||
}, function(result) {
|
||||
helper.verboseLog(result);
|
||||
var count = result.match((new RegExp('Running "watch" task', 'g'))).length;
|
||||
var count = result.match(new RegExp('Running "watch" task', 'g')).length;
|
||||
test.equal(count, 2, 'Watch should have fired twice.');
|
||||
test.ok(result.indexOf('Server is listening...') !== -1, 'server should have been started.');
|
||||
test.ok(result.indexOf('Server is talking!') !== -1, 'server should have responded.');
|
||||
@ -52,14 +52,12 @@ exports.nospawn = {
|
||||
setTimeout(function() {
|
||||
grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), write);
|
||||
}, 1000);
|
||||
}, function() {
|
||||
// Two functions needed to run two rounds of watching
|
||||
}], function(result) {
|
||||
helper.verboseLog(result);
|
||||
var count = result.match((new RegExp('Running "long" task', 'g'))).length;
|
||||
var count = result.match(new RegExp('Running "long" task', 'g')).length;
|
||||
test.equal(count, 4, 'long task should have been ran only 4 times.');
|
||||
test.ok(result.indexOf('have been interrupted') !== -1, 'tasks should have been interrupted.');
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
@ -40,5 +40,5 @@ exports.patterns = {
|
||||
'Watch should NOT have been triggered when dontedit.js was edited.');
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
@ -10,7 +10,7 @@ var fixtures = helper.fixtures;
|
||||
function cleanUp() {
|
||||
helper.cleanUp([
|
||||
'multiTargets/node_modules',
|
||||
'multiTargets/Gruntfile.js.bak',
|
||||
'multiTargets/Gruntfile.js.bak'
|
||||
]);
|
||||
}
|
||||
|
||||
@ -45,11 +45,11 @@ exports.reloadgruntfile = {
|
||||
grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var one = true;');
|
||||
}], function(result) {
|
||||
helper.verboseLog(result);
|
||||
var count = result.match((new RegExp('Running "watch" task', 'g'))).length;
|
||||
var count = result.match(new RegExp('Running "watch" task', 'g')).length;
|
||||
test.equal(count, 2, 'Watch should have fired twice.');
|
||||
test.ok(result.indexOf('one has changed') !== -1, 'task one should have been triggered.');
|
||||
test.ok(result.indexOf('two has changed') !== -1, 'task two should have been triggered.');
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
@ -5,6 +5,7 @@ var path = require('path');
|
||||
var fs = require('fs');
|
||||
var helper = require('./helper');
|
||||
var _s = require('underscore.string');
|
||||
var spawn = require('child_process').spawn;
|
||||
|
||||
var fixtures = helper.fixtures;
|
||||
var useFixtures = ['multiTargets', 'oneTarget', 'atBegin', 'dateFormat'];
|
||||
@ -32,7 +33,7 @@ exports.watch = {
|
||||
var cwd = path.resolve(fixtures, 'atBegin');
|
||||
var assertWatch = helper.assertTask(['watch', '--debug'], {cwd: cwd});
|
||||
assertWatch(function() {
|
||||
// noop. Does not modify any watched files.
|
||||
// noop. Does not modify any watched files.
|
||||
}, function(result) {
|
||||
helper.verboseLog(result);
|
||||
var firstIndex = result.indexOf('one has changed');
|
||||
@ -128,8 +129,8 @@ exports.watch = {
|
||||
interrupt: function(test) {
|
||||
test.expect(2);
|
||||
var cwd = path.resolve(fixtures, 'multiTargets');
|
||||
var assertWatch = helper.assertTask('watch', {cwd: cwd});
|
||||
assertWatch(function() {
|
||||
|
||||
function interrupt() {
|
||||
grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = 1;');
|
||||
setTimeout(function() {
|
||||
grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = 2;');
|
||||
@ -137,7 +138,22 @@ exports.watch = {
|
||||
setTimeout(function() {
|
||||
grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = 3;');
|
||||
}, 2000);
|
||||
}, function(result) {
|
||||
}
|
||||
|
||||
var output = [];
|
||||
var child = spawn(process.execPath, [process.argv[1], 'watch'], {cwd: cwd});
|
||||
child.stdout.on('data', function(data) {
|
||||
data = grunt.log.uncolor(data.toString());
|
||||
output.push(data);
|
||||
if (data.indexOf('Done') !== -1) {
|
||||
child.kill('SIGINT');
|
||||
} else if (data.indexOf('Waiting...') !== -1) {
|
||||
setTimeout(interrupt, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
child.on('exit', function() {
|
||||
var result = output.join('\n');
|
||||
helper.verboseLog(result);
|
||||
var interruptMatches = result.match(/have been interrupted/g);
|
||||
test.ok(interruptMatches && interruptMatches.length === 2, 'Task should have been interrupted 2 times.');
|
||||
|
Loading…
Reference in New Issue
Block a user