gulp-clean
Advanced tools
Comparing version 0.2.4 to 0.3.0
28
index.js
'use strict'; | ||
var rimraf = require('rimraf'); | ||
var es = require('event-stream'); | ||
var through2 = require('through2'); | ||
var gutil = require('gulp-util'); | ||
@@ -8,3 +8,3 @@ var path = require('path'); | ||
module.exports = function (options) { | ||
return es.map(function (file, cb) { | ||
return through2.obj(function (file, enc, cb) { | ||
// Paths are resolved by gulp | ||
@@ -18,16 +18,22 @@ var filepath = file.path; | ||
rimraf(filepath, function (error) { | ||
if (!error) { | ||
return cb(null, file); | ||
} else { | ||
return cb(new Error('Unable to delete "' + filepath + '" file (' + error.message + ').'), file); | ||
if (error) { | ||
this.emit('error', new gutil.PluginError('gulp-clean', 'Unable to delete "' + filepath + '" file (' + error.message + ').')); | ||
} | ||
}); | ||
this.push(file); | ||
cb(); | ||
}.bind(this)); | ||
} else if (relative === '') { | ||
gutil.log('gulp-clean: Cannot delete current working directory. (' + filepath + ')'); | ||
return cb(null, file); | ||
var msgCurrent = 'Cannot delete current working directory. (' + filepath + '). Use option force.'; | ||
gutil.log('gulp-clean: ' + msgCurrent); | ||
this.emit('error', new gutil.PluginError('gulp-clean', msgCurrent)); | ||
this.push(file); | ||
cb(); | ||
} else { | ||
gutil.log('gulp-clean: Cannot delete files outside the current working directory. (' + filepath + ')'); | ||
return cb(null, file); | ||
var msgOutside = 'Cannot delete files outside the current working directory. (' + filepath + '). Use option force.'; | ||
gutil.log('gulp-clean: ' + msgOutside); | ||
this.emit('error', new gutil.PluginError('gulp-clean', msgOutside)); | ||
this.push(file); | ||
cb(); | ||
} | ||
}); | ||
}; |
{ | ||
"name": "gulp-clean", | ||
"version": "0.2.4", | ||
"version": "0.3.0", | ||
"description": "A gulp plugin for removing files and folders.", | ||
@@ -8,3 +8,4 @@ "keywords": [ | ||
"clean", | ||
"remove" | ||
"remove", | ||
"delete" | ||
], | ||
@@ -26,9 +27,9 @@ "homepage": "https://github.com/peter-vilja/gulp-clean", | ||
"dependencies": { | ||
"rimraf": "~2.2.6", | ||
"event-stream": "~3.1.0", | ||
"gulp-util": "~2.2.12" | ||
"rimraf": "^2.2.8", | ||
"gulp-util": "^2.2.14", | ||
"through2": "^0.4.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.17.0", | ||
"chai": "~1.8.1" | ||
"mocha": "^1.19.0", | ||
"chai": "^1.9.1" | ||
}, | ||
@@ -35,0 +36,0 @@ "engines": { |
@@ -13,3 +13,3 @@ # [gulp](https://github.com/wearefractal/gulp)-clean [![Build Status](https://secure.travis-ci.org/peter-vilja/gulp-clean.png?branch=master)](https://travis-ci.org/peter-vilja/gulp-clean) [![NPM version](https://badge.fury.io/js/gulp-clean.png)](http://badge.fury.io/js/gulp-clean) | ||
## Example | ||
## Examples | ||
@@ -20,11 +20,9 @@ ```js | ||
gulp.task('default', function() { | ||
gulp.src('app/tmp', {read: false}) | ||
gulp.task('default', function () { | ||
return gulp.src('app/tmp', {read: false}) | ||
.pipe(clean()); | ||
}); | ||
``` | ||
Option read false prevents gulp to read the contents of the file and makes this task a lot faster. | ||
Option read false prevents gulp to read the contents of the file and makes this task a lot faster. If you need the file and it's contents after cleaning in the same stream, do not set the read option to false. | ||
After using gulp-clean the stream still contains the app/tmp and it can be used i.e. for moving the content to different location. | ||
```js | ||
@@ -34,5 +32,5 @@ var gulp = require('gulp'); | ||
gulp.task('default', function() { | ||
gulp.src('app/tmp/index.js', {read: false}) | ||
.pipe(clean({force: true})); | ||
gulp.task('default', function () { | ||
return gulp.src('app/tmp/index.js') | ||
.pipe(clean({force: true})) | ||
.pipe(gulp.dest('dist')); | ||
@@ -42,6 +40,27 @@ }); | ||
#### For safety files and folders outside the current working directory can be removed only with option force set to true. | ||
##### For safety files and folders outside the current working directory can be removed only with option force set to true. | ||
Clean as a dependency: | ||
```js | ||
var gulp = require('gulp'); | ||
var clean = require('gulp-clean'); | ||
gulp.task('clean-scripts', function () { | ||
return gulp.src('app/tmp/*.js', {read: false}) | ||
.pipe(clean()); | ||
}); | ||
gulp.task('scripts', ['clean-scripts'], function () { | ||
gulp.src('app/scripts/*.js') | ||
.pipe(gulp.dest('app/tmp')); | ||
}); | ||
gulp.task('default', ['scripts']); | ||
``` | ||
Make sure to return the stream so that gulp knows the clean task is [asynchronous](https://github.com/gulpjs/gulp/blob/master/docs/API.md#async-task-support) and waits for it to terminate before starting the dependent one. | ||
## License | ||
[MIT](http://en.wikipedia.org/wiki/MIT_License) @ Peter Vilja |
34
test.js
@@ -9,2 +9,4 @@ /*global describe, before, it*/ | ||
function noop() {} | ||
describe('gulp-clean plugin', function () { | ||
@@ -39,2 +41,3 @@ | ||
fs.writeFile('tmp/test.js', content, function () { | ||
stream.on('data', noop); | ||
stream.on('end', function () { | ||
@@ -74,3 +77,3 @@ fs.exists('tmp/test.js', function (exists) { | ||
})); | ||
stream.on('data', noop); | ||
stream.end(); | ||
@@ -93,3 +96,3 @@ }); | ||
}); | ||
stream.on('data', noop); | ||
stream.write(new gutil.File({ | ||
@@ -108,2 +111,8 @@ cwd: cwd, | ||
stream.on('error', function () { | ||
fs.exists('.', function (exists) { | ||
expect(exists).to.be.true; | ||
}); | ||
}); | ||
stream.on('end', function () { | ||
@@ -116,2 +125,3 @@ fs.exists('.', function (exists) { | ||
stream.on('data', noop); | ||
stream.write(new gutil.File({ | ||
@@ -130,2 +140,8 @@ cwd: cwd, | ||
stream.on('error', function () { | ||
fs.exists('../secrets', function (exists) { | ||
expect(exists).to.be.true; | ||
}); | ||
}); | ||
stream.on('end', function () { | ||
@@ -138,2 +154,4 @@ fs.exists('../secrets', function (exists) { | ||
stream.on('data', noop); | ||
stream.write(new gutil.File({ | ||
@@ -152,2 +170,10 @@ cwd: path.resolve(cwd), | ||
stream.on('error', function () { | ||
fs.exists('../gulp-cleanTemp', function (exists) { | ||
expect(exists).to.be.true; | ||
}); | ||
}); | ||
stream.on('data', noop); | ||
stream.on('end', function () { | ||
@@ -174,3 +200,3 @@ fs.exists('../gulp-cleanTemp', function (exists) { | ||
if (!fs.existsSync('../gulp-cleanTemp')) { fs.mkdirSync('../gulp-cleanTemp'); } | ||
stream.on('data', noop); | ||
stream.on('end', function () { | ||
@@ -190,2 +216,2 @@ fs.exists('../gulp-cleanTemp', function (exists) { | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9589
204
63
+ Addedthrough2@^0.4.2
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedobject-keys@0.4.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedthrough2@0.4.2(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxtend@2.1.2(transitive)
- Removedevent-stream@~3.1.0
- Removedduplexer@0.1.2(transitive)
- Removedevent-stream@3.1.7(transitive)
- Removedfrom@0.1.7(transitive)
- Removedmap-stream@0.1.0(transitive)
- Removedpause-stream@0.0.11(transitive)
- Removedrimraf@2.2.8(transitive)
- Removedsplit@0.2.10(transitive)
- Removedstream-combiner@0.0.4(transitive)
- Removedthrough@2.3.8(transitive)
Updatedgulp-util@^2.2.14
Updatedrimraf@^2.2.8