Created
May 6, 2014 13:55
-
-
Save evensandbox/9c0bcbc981db537c8292 to your computer and use it in GitHub Desktop.
grunt-contrib-delete.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| grunt.registerMultiTask('delete', function(when, task) { | |
| var path = require( 'path' ), fs = require( 'fs' ); | |
| var queue = function( list, fn, callback, index, ret ) { | |
| "use strict"; | |
| index = index || 0; | |
| ret = ret || []; | |
| var next = function ( value, stop, returnCurrentValue ) { | |
| ret[ ret.length ] = value; | |
| if ( stop ) { | |
| return callback.apply( null, returnCurrentValue ? [value] : ret ); | |
| } | |
| queue( list, fn, callback, ++index, ret ); | |
| }; | |
| if ( index < list.length ) { | |
| var argus = [ list[ index ], index, ret ]; | |
| if ( fn.length ) { | |
| argus = argus.slice( 0, fn.length - 1 ); | |
| } | |
| argus.push( next ); | |
| fn.apply( null, argus ); | |
| } | |
| else if ( callback ) { | |
| callback.apply( null, ret ); | |
| } | |
| }; | |
| function rmdir( file, cb ) { | |
| if ( grunt.file.isDir(file) ) { | |
| queue( fs.readdirSync(file), function( f, next ) { | |
| rmdir( path.resolve(file, f), next ); | |
| }, function() { | |
| fs.rmdirSync( file ); | |
| cb(); | |
| }); | |
| } | |
| else { | |
| fs.unlinkSync( file ); | |
| cb(); | |
| } | |
| } | |
| this.filesSrc.forEach(function( file ) { | |
| rmdir( path.resolve( __dirname, file ), function() {} ); | |
| }); | |
| }); | |
| grunt.registerTask( 'default', [ 'delete' ] ); |
Author
evensandbox
commented
May 6, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment