Skip to content

Commit

Permalink
Merge pull request gulpjs#623 from sindresorhus/delete-recipe
Browse files Browse the repository at this point in the history
add recipe for deleting files
  • Loading branch information
yocontra committed Aug 12, 2014
2 parents 54197db + 0bd21f2 commit 3aaf3ea
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/recipes/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Recipes

* [Combining streams to handle errors](combining-streams-to-handle-errors.md)
* [Delete files and folders](delete-files-folder.md)
* [Fast browserify builds with watchify](fast-browserify-builds-with-watchify.md)
* [Incremental rebuilding, including operating on full file sets](incremental-builds-with-concatenate.md)
* [Make stream from buffer (memory contents)](make-stream-from-memory-buffer.md)
Expand Down
42 changes: 42 additions & 0 deletions docs/recipes/delete-files-folder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Delete files and folders

You might want delete some files before running your build. Since deleting files doesn't work on the file contents there's no reason to use a gulp plugin. An excellent opportunity to use a vanilla node module.

Let's use the [`del`](https://github.com/sindresorhus/del) module for this example as it supports multiple files and [globbing](https://github.com/sindresorhus/multimatch#globbing-patterns):

```sh
$ npm install --save-dev gulp del
```

Imagine this file structure:

```
.
├── dist
│   ├── report.csv
│   ├── desktop
│   └── mobile
│   ├── app.js
│   ├── deploy.json
│   └── index.html
└── src
```

In the gulpfile we want to clean out the contents of the `mobile` folder before running our build:

```js
var gulp = require('gulp');
var del = require('del');

gulp.task('clean:mobile', function (cb) {
del([
'dist/report.csv',
// here we use a globbing pattern to match everything inside the `mobile` folder
'dist/mobile/**',
// we don't want to clean this file though so we negate the pattern
'!dist/mobile/deploy.json'
], cb);
});

gulp.task('default', ['clean:mobile']);
```

0 comments on commit 3aaf3ea

Please sign in to comment.