grunt-contrib-watch
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -60,2 +60,5 @@ # Examples | ||
tasks: ['jshint'], | ||
options: { | ||
nospawn: true, | ||
}, | ||
}, | ||
@@ -74,2 +77,4 @@ }, | ||
If you need to dynamically modify your config, the `nospawn` option must be enabled to keep the watch running under the same context. | ||
If you save multiple files simultaneously you may opt for a more robust method: | ||
@@ -76,0 +81,0 @@ |
@@ -78,3 +78,3 @@ # Settings | ||
#### options.event | ||
## options.event | ||
Type: `String|Array` | ||
@@ -81,0 +81,0 @@ Default: `'all'` |
{ | ||
"name": "grunt-contrib-watch", | ||
"description": "Run predefined tasks whenever watched file patterns are added, changed or deleted.", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"homepage": "https://github.com/gruntjs/grunt-contrib-watch", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -106,3 +106,3 @@ # grunt-contrib-watch [![Build Status](https://travis-ci.org/gruntjs/grunt-contrib-watch.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-watch) | ||
###### options.event | ||
#### options.event | ||
Type: `String|Array` | ||
@@ -212,2 +212,5 @@ Default: `'all'` | ||
tasks: ['jshint'], | ||
options: { | ||
nospawn: true, | ||
}, | ||
}, | ||
@@ -226,2 +229,4 @@ }, | ||
If you need to dynamically modify your config, the `nospawn` option must be enabled to keep the watch running under the same context. | ||
If you save multiple files simultaneously you may opt for a more robust method: | ||
@@ -327,2 +332,3 @@ | ||
* 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. | ||
@@ -347,2 +353,2 @@ * 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. | ||
*This file was generated on Thu May 09 2013 14:54:44.* | ||
*This file was generated on Sat May 11 2013 21:51:44.* |
@@ -32,5 +32,5 @@ /* | ||
// Targets available to task run | ||
this._targets = Object.create(null); | ||
this.targets = Object.create(null); | ||
// The queue of task runs | ||
this._queue = []; | ||
this.queue = []; | ||
// Whether we're actively running tasks | ||
@@ -85,3 +85,3 @@ this.running = false; | ||
// If not previously running but has items in the queue, needs run | ||
self._queue = reloadTargets; | ||
self.queue = reloadTargets; | ||
reloadTargets = []; | ||
@@ -134,3 +134,3 @@ self.run(); | ||
var self = this; | ||
if (self._queue.length < 1) { | ||
if (self.queue.length < 1) { | ||
self.running = false; | ||
@@ -143,4 +143,4 @@ return; | ||
var shouldInterrupt = true; | ||
self._queue.forEach(function(name) { | ||
var tr = self._targets[name]; | ||
self.queue.forEach(function(name) { | ||
var tr = self.targets[name]; | ||
if (tr && tr.options.interrupt !== true) { | ||
@@ -168,7 +168,6 @@ shouldInterrupt = false; | ||
var shouldComplete = true; | ||
grunt.util.async.forEachSeries(self._queue, function(name, next) { | ||
var tr = self._targets[name]; | ||
grunt.util.async.forEachSeries(self.queue, function(name, next) { | ||
var tr = self.targets[name]; | ||
if (!tr) { return next(); } | ||
if (tr.options.nospawn) { shouldComplete = false; } | ||
tr.changedFiles = self.changedFiles; | ||
tr.run(next); | ||
@@ -185,17 +184,5 @@ }, function() { | ||
// Queue target names for running | ||
Runner.prototype.queue = function queue(names) { | ||
var self = this; | ||
if (typeof names === 'string') { names = [names]; } | ||
names.forEach(function(name) { | ||
if (self._queue.indexOf(name) === -1) { | ||
self._queue.push(name); | ||
} | ||
}); | ||
return self._queue; | ||
}; | ||
// Push targets onto the queue | ||
Runner.prototype.add = function add(target) { | ||
if (!this._targets[target.name || 0]) { | ||
if (!this.targets[target.name || 0]) { | ||
var tr = new TaskRun(target, this.options); | ||
@@ -210,7 +197,7 @@ | ||
tr.livereload = livereload(lrconfig); | ||
} else if (this.livereload) { | ||
} else if (this.livereload && lrconfig !== false) { | ||
tr.livereload = this.livereload; | ||
} | ||
return this._targets[tr.name] = tr; | ||
return this.targets[tr.name] = tr; | ||
} | ||
@@ -226,8 +213,8 @@ return false; | ||
var time = 0; | ||
self._queue.forEach(function(name, i) { | ||
var target = self._targets[name]; | ||
self.queue.forEach(function(name, i) { | ||
var target = self.targets[name]; | ||
if (!target) { return; } | ||
if (target.startedAt !== false) { | ||
time += target.complete(); | ||
self._queue[i] = null; | ||
self.queue[i] = null; | ||
@@ -249,4 +236,4 @@ // if we're just livereloading and no tasks | ||
var self = this; | ||
self._queue.forEach(function(name) { | ||
var target = self._targets[name]; | ||
self.queue.forEach(function(name) { | ||
var target = self.targets[name]; | ||
if (!target) { return; } | ||
@@ -308,3 +295,3 @@ target.complete(); | ||
// Which targets to run after reload | ||
reloadTargets = self._queue; | ||
reloadTargets = self.queue; | ||
self.emit('reload', reloadTargets); | ||
@@ -311,0 +298,0 @@ |
@@ -28,3 +28,2 @@ /* | ||
grunt.log.writeln(); | ||
taskrun.changedFiles = changedFiles; | ||
// Reset changedFiles | ||
@@ -141,5 +140,17 @@ changedFiles = Object.create(null); | ||
// Run tasks | ||
// Group changed files only for display | ||
changedFiles[filepath] = status; | ||
taskrun.queue(target.name); | ||
// Add changed files to the target | ||
if (taskrun.targets[target.name]) { | ||
taskrun.targets[target.name].changedFiles = Object.create(null); | ||
taskrun.targets[target.name].changedFiles[filepath] = status; | ||
} | ||
// Queue the target | ||
if (taskrun.queue.indexOf(target.name) === -1) { | ||
taskrun.queue.push(target.name); | ||
} | ||
// Run the tasks | ||
taskrun.run(); | ||
@@ -146,0 +157,0 @@ }); |
@@ -28,3 +28,3 @@ module.exports = function(grunt) { | ||
done(); | ||
}, 1); | ||
}, 1000); | ||
}); | ||
@@ -36,4 +36,4 @@ grunt.registerTask('fatal', function() { | ||
done(); | ||
}, 1); | ||
}, 1000); | ||
}); | ||
}; |
module.exports = function(grunt) { | ||
'use strict'; | ||
var path = require('path'); | ||
grunt.initConfig({ | ||
@@ -33,2 +35,12 @@ watch: { | ||
}, | ||
triggerwrite: { | ||
files: ['sass/*'], | ||
tasks: ['writecss'], | ||
options: { | ||
livereload: false, | ||
}, | ||
}, | ||
triggerlr: { | ||
files: ['css/*'], | ||
}, | ||
}, | ||
@@ -43,2 +55,6 @@ }); | ||
}); | ||
grunt.registerTask('writecss', function() { | ||
grunt.file.write(path.join(__dirname, 'css', 'one.css'), '#one {}'); | ||
}); | ||
}; |
@@ -128,2 +128,18 @@ 'use strict'; | ||
}, | ||
onlytriggeron: function(test) { | ||
test.expect(2); | ||
var cwd = path.resolve(fixtures, 'livereload'); | ||
var assertWatch = helper.assertTask(['watch', '-v'], {cwd: cwd}); | ||
assertWatch([function() { | ||
request(35729, function(data) { | ||
grunt.file.write(path.join(cwd, 'sass', 'one.scss'), '#one {}'); | ||
}); | ||
}], function(result) { | ||
result = helper.unixify(result); | ||
helper.verboseLog(result); | ||
test.ok(result.indexOf('Live reloading sass/one.scss') === -1, 'Should not trigger live reload on non livereload targets.'); | ||
test.ok(result.indexOf('Live reloading css/one.css') !== -1, 'Should trigger live reload when other tasks trigger livereload targets.'); | ||
test.done(); | ||
}); | ||
}, | ||
}; |
Sorry, the diff of this file is not supported yet
81612
50
1510
350