Skip to content
This repository has been archived by the owner on May 20, 2018. It is now read-only.

Made a multirask out of the clean task allowing to define specific targets #14

Merged
merged 1 commit into from
May 9, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/clean.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ Inside your `grunt.js` file, add a section named `clean`
``` javascript
clean: ['/path/to/dir/one','/path/to/dir/two']
```

As an alternative, you can add specific targets to your clean config,
which can then be called as 'grunt clean:build', 'grunt clean:release' etc.

``` javascript
clean: {
build: ['/path/to/dir/one','/path/to/dir/two'],
release: ['/path/to/another/dir/one','/path/to/another/dir/two']
}
```
12 changes: 9 additions & 3 deletions tasks/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ module.exports = function(grunt) {
var rimraf = require("rimraf");
var log = grunt.log;

grunt.registerTask("clean",
grunt.registerMultiTask("clean",
"Clear files and folders", function() {
var config = grunt.config.get('clean');
var files = this.data;
var isArray = typeof grunt.utils !== 'undefined' ? grunt.utils._.isArray : grunt.util._.isArray;

var files = grunt.config("clean");
// check if we have a valid config & an invalid target specific config
if (isArray(config) === true && isArray(this.data) === false) {
files = config;
}

files.forEach(function(file) {
grunt.helper("clean", file);
Expand All @@ -29,4 +35,4 @@ module.exports = function(grunt) {
rimraf.sync(path);
});

};
};