1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
-
-
- 'use strict';
-
- var rimraf = require('rimraf');
-
- module.exports = function(grunt) {
-
- function clean(filepath, options) {
- if (!grunt.file.exists(filepath)) {
- return false;
- }
-
-
- if (!options.force) {
- if (grunt.file.isPathCwd(filepath)) {
- grunt.verbose.error();
- grunt.fail.warn('Cannot delete the current working directory.');
- return false;
- } else if (!grunt.file.isPathInCwd(filepath)) {
- grunt.verbose.error();
- grunt.fail.warn('Cannot delete files outside the current working directory.');
- return false;
- }
- }
-
- try {
-
- if (!options['no-write']) {
- rimraf.sync(filepath);
- }
- grunt.verbose.writeln((options['no-write'] ? 'Not actually cleaning ' : 'Cleaning ') + filepath + '...');
- } catch (e) {
- grunt.log.error();
- grunt.fail.warn('Unable to delete "' + filepath + '" file (' + e.message + ').', e);
- }
- }
-
- grunt.registerMultiTask('clean', 'Clean files and folders.', function() {
-
- var options = this.options({
- force: grunt.option('force') === true,
- 'no-write': grunt.option('no-write') === true,
- });
-
-
- this.filesSrc.forEach(function(filepath) {
- clean(filepath, options);
- });
- grunt.log.ok(this.filesSrc.length + ' ' + grunt.util.pluralize(this.filesSrc.length, 'path/paths') + ' cleaned.');
- });
-
- };
|