gulp-each
A for each that provides the raw file content.
Last updated 3 years ago by kirilv .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install gulp-each 
SYNC missed versions from official npm registry.

gulp-each

Build Test Coverage Code Climate Downloads Version Dependency Status ISC License Analytics

A for-each for Gulp that exposes the actual content of the file.

I have had to write this code many times because I wanted a "one-off" task that does "somthing quick" to each file. Or, I have wanted to write literally any module that processes code files, and had to start anew every time and figure out this logic.

Most other for-each implementations for Gulp expose the stream (of buffer) object, requiring the user to read the stream (or buffer) and write out a new stream (or buffer). Yes, I used the most annoying way to word that on purpose. This module exposes the content of the file itself, so you can directly start manipulating the content (e.g. code) directly, without worrying about the Gulp plumbing.

Download

npm install gulp-each

Usage

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

gulp.task('mytask', function() {
    return gulp.src('*.js')
        .pipe(each(function(content, file, callback) {
            // content is a string containing the code
            // do with it as you'd like
            var newContent = '// my comment\n' + content;

            // file is the original Vinyl file object

            // return the new content using the callback
            // the first argument is an error, if you encounter one
            callback(null, newContent);
        }))
        .pipe(gulp.dest('output'));
});

By default, gulp-each will assume that you are working with text files and use utf8 as the encoding, returning a string as the content variable. At times, that will not be true. If you want to work with binary files, you can provide 'buffer' as the second parameter:

gulp.task('mytask', function() {
    return gulp.src('*.png')
        .pipe(each(function(content, file, callback) {
            // content is a buffer containing the image
            var newConent = transformTheImageBuffer(content);

            // return the new content using the callback
            // the first argument is an error, if you encounter one
            callback(null, newContent);
        }, 'buffer'))
        .pipe(gulp.dest('output'));
});

Current Tags

  • 0.5.0                                ...           latest (3 years ago)

10 Versions

  • 0.5.0                                ...           3 years ago
  • 0.4.0                                ...           3 years ago
  • 0.3.3 [deprecated]           ...           3 years ago
  • 0.3.2 [deprecated]           ...           3 years ago
  • 0.3.1 [deprecated]           ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.3.0 [deprecated]           ...           3 years ago
  • 0.2.0                                ...           4 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 26
This Month 48
Last Day 7
Last Week 34
Last Month 225
Dependencies (1)
Dev Dependencies (7)

Copyright 2014 - 2017 © taobao.org |