del: Negating a pattern is not working

.
├── assets
│   ├── .gitkeep
│   ├── rev-manifest.json
│   ├── style-2ccbb519.css

I’m auto compiling my less and using gulp-rev for revisioning. I have a clean:css task defined like so:

gulp.task('clean:css', function (cb) {
    del(['public/assets/**', '!public/assets/.gitkeep'], cb);
});

When running the clean:css task everything in the public/assets directory is removed including .gitkeep, I expect .gitkeep to remain in place. I have replaced .gitkeep with example.txt to rule out problems with empty files and the problem persists (example.txt contained “example”).

Have I missed something obvious, if not is there something I can do to debug this? I’m using ubuntu 14.04 (through Vagrant). Gulp is at version 3.8.7, npm is 1.3.10 and del is 0.1.1.

I followed this recipe.

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 27 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I also had a problem with it deleting my dist folder with this code

del(['dist/**','!dist/sftp-config.json']);

after changing it to the below, it worked

del(['dist/**/*','!dist/sftp-config.json']);

I have a ./dist/.git directory I need to preserve when running gulp clean:dist…how can I do that?

I’ve tried all the suggestions, they don’t work.

gulp.task('clean:dist', function(cb){
    del(['dist/**/*', '!dist/.git/**/*'], { dot: true }, cb);
});

I found luck with this, if it helps anyone

return del([
        '../leads/**/*',
        '!../leads/svn{,/**}'
    ], {force: true});

Its amazing that this repo is still so bad quality with all this popularity.

Prolly instead of experimenting I could have written a working repo within the same time frame.

Please stop complaining. This is free, open source software and everybody is free to submit a PR with a fix 😃

one thing I realized is that you need to exclude each folder in the path, a well as inside the folders, example:

del([
    `${BASE_FOLDER}/**/*`,
    `!${BASE_FOLDER}/folderA{,/folderB{,/**/*}}`
  ]

which would be the same as

del([
    `${BASE_FOLDER}/**/*`,
    `!${BASE_FOLDER}/folderA`,
    `!${BASE_FOLDER}/folderA/folderB`,
    `!${BASE_FOLDER}/folderA/folderB/**/*`
  ]