grunt-contrib-clean icon indicating copy to clipboard operation
grunt-contrib-clean copied to clipboard

Skipping files seems broken

Open Nemikolh opened this issue 9 years ago • 12 comments

The following configuration does not skip the js/main.js file:

{
  clean: {
    js: ['js/', '!js/main.js']
  }
}

Is it intented ?

Nemikolh avatar Feb 27 '15 15:02 Nemikolh

:+1: I am hitting this as well

clean: {
  dest: ['<%= config.dest %>/**', '!<%= config.dest %>/CNAME']
}

Note that skipping files seems to work fine when using a destination path with extensions, but doesn't skip files when destination path matches a directory. My expectation was that a directory shouldn't be cleaned if it contains an excluded file.

jt000 avatar Mar 23 '15 12:03 jt000

Same here! I want to prevent clean to remove files into bower_components folder, but it does not skip it.

    clean: {
        dev: [
                '<%= globalConfig.src %>/**/*.js',
                '<%= globalConfig.src %>/**/*.map',
                '!<%= globalConfig.src %>/**/bower_components/*.*'
            ]
    }

Any idea ?

ghost avatar Mar 23 '15 18:03 ghost

Same issue with this:

[ 
'./WebContent/scripts/**/*',
  '!./WebContent/scripts/views/**/*' 
]

Vadorequest avatar Jun 04 '15 13:06 Vadorequest

:+1:

AndersDJohnson avatar Jun 27 '15 19:06 AndersDJohnson

There is no code in clean.js that deals with exclusion.

But yes, I'd like to see that as well. Either that or please fix the documentation accordingly.

czottmann avatar Jul 02 '15 12:07 czottmann

@Vadorequest You may be able to achieve exclusion of sub-directory with something like this instead:

[ 
  './WebContent/scripts/**/*.*',
  '!./WebContent/scripts/views/**/*' 
]

The problem with your original is that the first rule, ./WebContent/scripts/**/*, was including the views directory in deletes, which overrides the exclusions for anything under that directory, as @jt000 noticed. To work around this, you can mandate an extension via *.*, which should work as long as all the files in your scripts have extensions—otherwise, you'll need glob rules more specific to your project.

To prove that this works, see the excludeSub test case I've added in d642845 on adjohnson916/grunt-contrib-clean#exclude.

For @Nemikolh's case, I'd try matching not the js directory, but any files under it:

['js/**/*.*', '!js/main.js']

For @milton-rodriguez-uruit's case, I'd try matching any files under bower_components deeply:

[
  '<%= globalConfig.src %>/**/*.js',
  '<%= globalConfig.src %>/**/*.map',
  '!<%= globalConfig.src %>/**/bower_components/**/*.*'
]

AndersDJohnson avatar Jul 05 '15 00:07 AndersDJohnson

This is a pretty frustrating issue! Anybody know of an alternative plugin that allows this?

charge-valtech avatar Sep 30 '15 15:09 charge-valtech

Any news about this bug?

damnedest avatar Jan 24 '16 09:01 damnedest

Took me some time to find this. Please fix it.

ClaasM avatar Mar 09 '16 21:03 ClaasM

Same issue, will require some super janky code until fixed.

tyfuji avatar Sep 22 '16 20:09 tyfuji

My case:

      theme: ["public/wp-content/themes/my-theme/*", "!public/wp-content/themes/my-theme/acf-json/"]

I want to remove everything in my-theme but keep everything in acf-json. This rule simply removes everything in my-theme.

tyfuji avatar Sep 22 '16 20:09 tyfuji

This being still open means someone needs to update the .md file, the answer can be found in this old issue thread: https://github.com/gruntjs/grunt-contrib-clean/issues/15

Specifically the reply from https://coderwall.com/p/fkdyag helped me.

theme: ["public/wp-content/themes/my-theme/*", "!public/wp-content/themes/my-theme/acf-json/"]

changed to:

theme: ["!public/wp-content/themes/my-theme/**", "public/wp-content/themes/my-theme/*", "!public/wp-content/themes/my-theme/acf-json/"]

Should work, or in the OPs simpler question { clean: { js: ['!js/**', 'js/*', '!js/main.js'] } }

ClarenceL avatar Sep 04 '17 02:09 ClarenceL