Added target specific event emissions. Closes GH-116.
This commit is contained in:
parent
81636c6fea
commit
ede6a107b3
@ -192,8 +192,8 @@ grunt.initConfig({
|
||||
},
|
||||
},
|
||||
});
|
||||
grunt.event.on('watch', function(action, filepath) {
|
||||
grunt.log.writeln(filepath + ' has ' + action);
|
||||
grunt.event.on('watch', function(action, filepath, target) {
|
||||
grunt.log.writeln(target + ': ' + filepath + ' has ' + action);
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -41,8 +41,8 @@ grunt.initConfig({
|
||||
},
|
||||
},
|
||||
});
|
||||
grunt.event.on('watch', function(action, filepath) {
|
||||
grunt.log.writeln(filepath + ' has ' + action);
|
||||
grunt.event.on('watch', function(action, filepath, target) {
|
||||
grunt.log.writeln(target + ': ' + filepath + ' has ' + action);
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -127,7 +127,7 @@ module.exports = function(grunt) {
|
||||
|
||||
// Emit watch events if anyone is listening
|
||||
if (grunt.event.listeners('watch').length > 0) {
|
||||
grunt.event.emit('watch', status, filepath);
|
||||
grunt.event.emit('watch', status, filepath, target.name);
|
||||
}
|
||||
|
||||
// Group changed files only for display
|
||||
|
13
test/fixtures/events/Gruntfile.js
vendored
13
test/fixtures/events/Gruntfile.js
vendored
@ -29,20 +29,27 @@ module.exports = function(grunt) {
|
||||
event: ['added', 'deleted'],
|
||||
},
|
||||
files: ['lib/*.js'],
|
||||
}
|
||||
},
|
||||
targetOne: { files: ['lib/one/*.js'] },
|
||||
targetTwo: { files: ['lib/two/*.js'] },
|
||||
},
|
||||
});
|
||||
|
||||
// Load this watch task
|
||||
grunt.loadTasks('../../../tasks');
|
||||
|
||||
// trigger on watch events
|
||||
var timeout;
|
||||
grunt.event.on('watch', function(action, filepath) {
|
||||
|
||||
// trigger on watch events
|
||||
grunt.event.on('watch', function(action, filepath, target) {
|
||||
grunt.log.writeln(filepath + ' was indeed ' + action);
|
||||
if (target !== undefined) {
|
||||
grunt.log.writeln(target + ' specifc event was fired')
|
||||
}
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(function() {
|
||||
grunt.util.exit(0);
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
};
|
||||
|
1
test/fixtures/events/lib/one/test.js
vendored
Normal file
1
test/fixtures/events/lib/one/test.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var test = false;
|
1
test/fixtures/events/lib/two/test.js
vendored
Normal file
1
test/fixtures/events/lib/two/test.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var test = false;
|
@ -110,4 +110,24 @@ exports.events = {
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
targetSpecific: function(test) {
|
||||
test.expect(2);
|
||||
var cwd = path.resolve(fixtures, 'events');
|
||||
var assertWatch = helper.assertTask('watch', {cwd: cwd});
|
||||
assertWatch([function() {
|
||||
var write = 'var test = false;';
|
||||
setTimeout(function() {
|
||||
grunt.file.write(path.join(cwd, 'lib/one', 'test.js'), write);
|
||||
}, 300);
|
||||
setTimeout(function() {
|
||||
grunt.file.write(path.join(cwd, 'lib/two', 'test.js'), write);
|
||||
}, 300);
|
||||
}], function(result) {
|
||||
result = helper.unixify(result);
|
||||
helper.verboseLog(result);
|
||||
test.ok(result.indexOf('lib/one/test.js was indeed changed\ntargetOne specifc event was fired') !== -1, 'event should have been emitted with targetOne specified');
|
||||
test.ok(result.indexOf('lib/two/test.js was indeed changed\ntargetTwo specifc event was fired') !== -1, 'event should have been emitted with targetTwo specified');
|
||||
test.done();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user