prep for upcoming grunt release. Closes GH-23.

normalize linefeeds. remove grunt v0.3 and node v0.6 support
pull/41/head v0.2.0-a
Chris Talkington 12 years ago committed by Kyle Robinson Young
parent 3496beb2f4
commit 7c326a6fcf

1
.gitattributes vendored

@ -0,0 +1 @@
* text=auto

@ -1,2 +1,2 @@
Kyle Robinson Young (http://dontkry.com)
Kyle Robinson Young (http://dontkry.com)
"Cowboy" Ben Alman (http://benalman.com)

@ -1,5 +1,8 @@
v0.1.5:
v0.2.0:
date: 2012-12-15
changes:
- 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.
v0.1.4:

@ -1,22 +1,22 @@
Copyright (c) 2012 "Cowboy" Ben Alman, contributors
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Copyright (c) 2012 "Cowboy" Ben Alman, contributors
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

@ -2,31 +2,20 @@
> Run predefined tasks whenever watched file patterns are added, changed or deleted.
_Note that this plugin has not yet been released, and only works with the latest bleeding-edge, in-development version of grunt. See the [When will I be able to use in-development feature 'X'?](https://github.com/gruntjs/grunt/blob/devel/docs/faq.md#when-will-i-be-able-to-use-in-development-feature-x) FAQ entry for more information._
## Getting Started
_If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide._
If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide, as it explains how to create a [gruntfile][Getting Started] as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:
From the same directory as your project's [Gruntfile][Getting Started] and [package.json][], install this plugin with the following command:
```bash
```shell
npm install grunt-contrib-watch --save-dev
```
Once that's done, add this line to your project's Gruntfile:
```js
grunt.loadNpmTasks('grunt-contrib-watch');
```
If the plugin has been installed correctly, running `grunt --help` at the command line should list the newly-installed plugin's task or tasks. In addition, the plugin should be listed in package.json as a `devDependency`, which ensures that it will be installed whenever the `npm install` command is run.
[grunt]: http://gruntjs.com/
[Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md
[package.json]: https://npmjs.org/doc/json.html
## The watch task
## Watch task
_Run this task with the `grunt watch` command._
### Overview
@ -135,14 +124,15 @@ grunt.initConfig({
## Release History
* 2012-11-19 - v0.1.5 - Allow watch task to be renamed. Use grunt.util.spawn "grunt" option.
* 2012-10-31 - v0.1.4 - Prevent watch from spawning duplicate watch tasks
* 2012-10-27 - 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-16 - 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-15 - 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-07 - v0.1.0 - Release watch task Remove spawn from helper Run on Grunt v0.4
* 2012-12-14v0.2.0Conversion 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.
* 2012-10-31v0.1.4Prevent watch from spawning duplicate watch tasks
* 2012-10-27v0.1.3Better 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-16v0.1.2Only spawn a process per task one at a time Add interrupt option to cancel previous spawned process Grunt v0.3 compatibility changes
* 2012-10-15v0.1.1Fallback to global grunt bin if local doesnt exist. Fatal if bin cannot be found Update to gaze 0.1.6
* 2012-10-07v0.1.0Release watch task Remove spawn from helper Run on Grunt v0.4
---
--
Task submitted by <a href="http://dontkry.com">Kyle Robinson Young</a>.
Task submitted by [Kyle Robinson Young](http://dontkry.com)
*Generated on Mon Nov 19 2012 12:58:44.*
*This file was generated on Thu Dec 13 2012 11:57:38.*

@ -1,7 +1,7 @@
{
"name": "grunt-contrib-watch",
"description": "Run predefined tasks whenever watched file patterns are added, changed or deleted.",
"version": "0.1.4",
"version": "0.2.0a",
"homepage": "https://github.com/gruntjs/grunt-contrib-watch",
"author": {
"name": "Grunt Team",
@ -33,8 +33,8 @@
"devDependencies": {
"grunt-contrib-jshint": "~0.1.0",
"grunt-contrib-nodeunit": "~0.1.0",
"grunt-contrib-internal": "*",
"grunt": "~0.4.0a"
"grunt-contrib-internal": "~0.1.0",
"grunt": "~0.4.0"
},
"keywords": [
"gruntplugin", "watch"

@ -9,17 +9,10 @@
module.exports = function(grunt) {
'use strict';
// TODO: ditch this when grunt v0.4 is released
grunt.util = grunt.util || grunt.utils;
var path = require('path');
var fs = require('fs');
var Gaze = require('gaze').Gaze;
// In Nodejs 0.8.0, existsSync moved from path -> fs.
// TODO: When 0.4 is release, use grunt.file.exists
fs.existsSync = fs.existsSync || path.existsSync;
// Default options for the watch task
var defaults = {
interrupt: false
@ -28,11 +21,13 @@ module.exports = function(grunt) {
grunt.registerTask('watch', 'Run predefined tasks whenever watched files change.', function(target) {
var name = this.name || 'watch';
this.requiresConfig(name);
// Build an array of files/tasks objects
var watch = grunt.config(name);
var targets = target ? [target] : Object.keys(watch).filter(function(key) {
return typeof watch[key] !== 'string' && !Array.isArray(watch[key]);
});
targets = targets.map(function(target) {
// Fail if any required config properties have been omitted
target = [name, target];
@ -47,12 +42,16 @@ module.exports = function(grunt) {
// Message to display when waiting for changes
var waiting = 'Waiting...';
// File changes to be logged.
var changedFiles = Object.create(null);
// Keep track of spawns per tasks
var spawned = Object.create(null);
// List of changed / deleted file paths.
grunt.file.watchFiles = {changed: [], deleted: [], added: []};
// Get process.argv options without grunt.cli.tasks to pass to child processes
var cliArgs = grunt.util._.without.apply(null, [[].slice.call(process.argv, 2)].concat(grunt.cli.tasks));
@ -68,16 +67,20 @@ module.exports = function(grunt) {
spawned[i].kill('SIGINT');
delete spawned[i];
}
// Only spawn one at a time unless interrupt is specified
if (!spawned[i]) {
grunt.log.ok();
var fileArray = Object.keys(changedFiles);
fileArray.forEach(function(filepath) {
// Log which file has changed, and how.
grunt.log.ok('File "' + filepath + '" ' + changedFiles[filepath] + '.');
});
// Reset changedFiles
changedFiles = Object.create(null);
// Spawn the tasks as a child process
spawned[i] = grunt.util.spawn({
// Spawn with the grunt bin
@ -91,6 +94,7 @@ module.exports = function(grunt) {
delete spawned[i];
grunt.log.writeln('').write(waiting);
});
// Display stdout/stderr immediately
spawned[i].stdout.on('data', function(buf) { grunt.log.write(String(buf)); });
spawned[i].stderr.on('data', function(buf) {
@ -106,20 +110,24 @@ module.exports = function(grunt) {
}
// Get patterns to glob for this target
var patterns = grunt.util._.chain(target.files).flatten().uniq().value();
// Default options per target
var options = grunt.util._.defaults(target.options || {}, defaults);
// Create watcher per target
var gaze = new Gaze(patterns, options, function(err) {
if (err) {
grunt.log.error(err.message);
return done();
}
// On changed/added/deleted
this.on('all', function(status, filepath) {
filepath = path.relative(process.cwd(), filepath);
changedFiles[filepath] = status;
runTasks(i, target.tasks, options);
});
// On watcher error
this.on('error', function(err) { grunt.log.error(err); });
});

@ -2,17 +2,6 @@
var grunt = require('grunt');
var path = require('path');
grunt.util = grunt.util || grunt.utils;
// Node v0.6 compat
path.sep = path.sep || path.normalize('/');
// In case the grunt being used to test is different than the grunt being
// tested, initialize the task and config subsystems.
if (grunt.task.searchDirs.length === 0) {
grunt.task.init([]);
grunt.config.init({});
}
// Where our fixtures are
var fixtures = path.join(__dirname, '..', 'fixtures');

Loading…
Cancel
Save