Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping files seems broken #65

Open
Nemikolh opened this issue Feb 27, 2015 · 12 comments
Open

Skipping files seems broken #65

Nemikolh opened this issue Feb 27, 2015 · 12 comments

Comments

@Nemikolh
Copy link

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

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

Is it intented ?

@jt000
Copy link

jt000 commented Mar 23, 2015

👍 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.

@ghost
Copy link

ghost commented Mar 23, 2015

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 ?

@Vadorequest
Copy link

Same issue with this:

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

@AndersDJohnson
Copy link
Member

👍

@czottmann
Copy link

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.

AndersDJohnson pushed a commit to AndersDJohnson/grunt-contrib-clean that referenced this issue Jul 5, 2015
AndersDJohnson pushed a commit to AndersDJohnson/grunt-contrib-clean that referenced this issue Jul 5, 2015
@AndersDJohnson
Copy link
Member

@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/**/*.*'
]

@charge-valtech
Copy link

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

@damnedest
Copy link

Any news about this bug?

@ClaasM
Copy link

ClaasM commented Mar 9, 2016

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

@tyfuji
Copy link

tyfuji commented Sep 22, 2016

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

@tyfuji
Copy link

tyfuji commented Sep 22, 2016

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.

@ClarenceL
Copy link

ClarenceL commented Sep 4, 2017

This being still open means someone needs to update the .md file, the answer can be found in this old issue thread: #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'] } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests