A gulp plugin that allows you to edit Vinyl files directly.
npm install gulp-remasterYou could also write a gulp plugin by wrapping Remaster.
.pipe() method of a readable Vinyl stream. By default, Remaster will behave much like gulp-clone in that it will make a clone of all Vinyl files found in the stream and pass them on. A more useful invocation of Remaster will pass a file handler function to be run on each file and, optionally, a final handler function to be invoked after the last file is processed but before the stream is closed. There is also an options object syntax that allows setting both handler functions and a few other options.If you wanted to build something like a simplistic gulp-filter, you could invoke Remaster something like this:
~~~javascript
var gulp = require('gulp'),
remaster = require('gulp-remaster');
var filterPattern = /-test$/;
gulp.task('example', function(){
return gulp.src("src/*/.js")
.pipe(remaster( function(file, done){
if(file.isNull || filterPattern.test(file.stem)) {
// remove file from the stream by calling the callback
// without an error or a file.
return done();
}
// pass the file on by passing it to the callback
done(null, file);
}))
.pipe(gulp.dest("dest"));
})
~~~
Take a look at the tests for more examples.
remaster( eachFileHandler[, finalHandler] ) or remaster( options )This is really just a thinly wrapped through2 transform function. For each file in the stream it receives either the file and a callback([err[, file]]) or the file, it's encoding, and a callback([err[, file]]). Remaster will send an error to the callback if it encounters a file (object) that is not a vinyl file (i.e. what gulp streams usually contain.) The callback takes an err - for reporting errors - and a file, which will be pushed to the stream. As with through2, this is set to the stream, so you may call this.push(file) instead of passing the file to the callback.
This is a through2 flush function. It receives a single callback([err]) which may be passed an error and should be called when you are done with the stream.
If truthy, Remaster will clone all Vinyl files passed through the stream before passing the clone to the eachFile handler. If an object, it will be passed as an options object to clone.
If truthy, Remaster will check whether every object coming through the stream is a Vinyl file using Vinyl's own test function. This option exists and is off by default in case your workflow passes through things that act like Vinyl files, but are not. You can turn it on if you want to be sure every file object is truely a Vinyl file.
This is a function that will call the gulp-util PluginError constructor used to generate errors inside Remaster. It is exposed here in case you want to use Remaster to simplify writing your own gulp plugin. In that case only, set this to your own function that calls gulp-util's PluginError constructor.