grunt-restrict
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -57,2 +57,3 @@ /* | ||
plain_task: ['test/plain_task_test.js'], | ||
unit: ['test/handlers.js'], | ||
restrict_task_nofile_test: ['test/restrict_task_nofile_test.js'], | ||
@@ -105,2 +106,4 @@ restrict_task_firstfile_test: ['test/restrict_task_firstfile_test.js'], | ||
'nodeunit:restrict_task_nomatch_test', | ||
'nodeunit:unit', | ||
]); | ||
@@ -107,0 +110,0 @@ |
{ | ||
"name": "grunt-restrict", | ||
"description": "Run grunt tasks on subset of their src files.", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/ichernev/grunt-restrict", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -32,2 +32,3 @@ # grunt-restrict | ||
```javascript | ||
// Setup your tasks as usual | ||
grunt.initConfig({ | ||
@@ -40,4 +41,15 @@ coffee: { | ||
ext: '.js' | ||
}, | ||
// (grunt-contrib-)watch task is optional | ||
watch: { | ||
coffee: { | ||
files: ['**/*.coffee'], | ||
tasks: ['restrict:coffee'], | ||
} | ||
} | ||
}) | ||
// Use this if you use grunt-contrib-watch | ||
require('grunt-restrict/tasks/restrict').registerHandlers(grunt); | ||
``` | ||
@@ -76,2 +88,4 @@ | ||
## Release History | ||
0.1.0 Initial commit | ||
* 0.2.0 Simple detection for source-only tasks, provide watch event handlers | ||
* 0.1.1 Removed extra console.log | ||
* 0.1.0 Initial commit |
@@ -16,3 +16,3 @@ /* | ||
module.exports = function(grunt) { | ||
var exported = function(grunt) { | ||
var _ = grunt.util._, | ||
@@ -56,12 +56,25 @@ old_configs = {}; | ||
grunt.config([task, target]), task); | ||
files = _.select(files, function(file) { | ||
return _.any(file.src, function(f) { | ||
return f in restricted; | ||
}); | ||
}); | ||
config = grunt.config([task, target]); | ||
old_configs[task + ":" + target] = _.extend({}, grunt.config.getRaw([task, target])); | ||
delete config.src; | ||
delete config.dest; | ||
config.files = files; | ||
// Check files format | ||
if (Array.isArray(config)) { | ||
// task: [list of files] | ||
// --> Change files. This task shouldn't have a destination. | ||
config = [].concat.apply([], _.map(files, function(file) { | ||
return _.filter(file.src, function(f) { | ||
return f in restricted; | ||
}); | ||
})); | ||
} else { | ||
// task: {src: [...], dest: file, ...} OR {files: {...}, ...} | ||
// --> Change config.files (remove old .src & .dest) | ||
files = _.select(files, function(file) { | ||
return _.any(file.src, function(f) { | ||
return f in restricted; | ||
}); | ||
}); | ||
delete config.src; | ||
delete config.dest; | ||
config.files = files; | ||
} | ||
grunt.config([task, target], config); | ||
@@ -75,1 +88,26 @@ }); | ||
}; | ||
exported.watchHandler = function(grunt) { | ||
return function(action, filepath) { | ||
var cliArgs = grunt.config.get(['watch', 'options', 'cliArgs']); | ||
if (cliArgs == null) { | ||
cliArgs = ['--file', filepath]; | ||
} else { | ||
cliArgs[1] += ',' + filepath; | ||
} | ||
grunt.config(['watch', 'options', 'cliArgs'], cliArgs); | ||
}; | ||
}; | ||
exported.watchPostRunHandler = function(grunt) { | ||
return function() { | ||
grunt.config(['watch', 'options', 'cliArgs'], null); | ||
}; | ||
}; | ||
exported.registerHandlers = function(grunt) { | ||
grunt.event.on('watch', exported.watchHandler(grunt)); | ||
grunt.event.on('watch-post-run', exported.watchPostRunHandler(grunt)); | ||
}; | ||
module.exports = exported; |
27132
18
379
89