forked from gulpjs/gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request gulpjs#623 from sindresorhus/delete-recipe
add recipe for deleting files
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
``` |