Navigation Menu

Skip to content

wires/gulp-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Better mapping.

npm install --save gulp-map

Works with

var map = require('gulp-map');

When returning a promise, it is mapped asynchronously (in parallel):

var Q = require('kew');

// wait 500 ms and add a 'slow' tag to the file
.pipe(map(function (file) {
	return Q
		.delay(500)
		.then(function () {
			file.tags = (file.tags || []).push('slow')
			return file
		})
	})
}))

The stream 'end' event delayed until all promisses are finished.

When you return undefined from your promise or regular function, the file is filtered from the stream.

.pipe(map(function (file) {
	if (file.path.match(/gulpfile\.js/))
		return file
	// other files not emitted
}))

That's it.

Alternatives

For regular callback style mapping, just use map-stream.

var map = require('map-stream');
// ...
.pipe(map(function(file, done){
	done(null, file);
}))

For both data and end events, through2 works well:

var Through = require('through2').obj;
// ...
.pipe(Through(
	function handle_data(file, encoding, done) {
		this.push(file);
		done();
	}
	function handle_end(done) {
		done();
	}
))

About

(A)synchronous mapping and filtering of vinyl streams (gulp plugin)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published