Socket
Socket
Sign inDemoInstall

gulp-collect

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    gulp-collect

Work on all files of a gulp stream simultaneously


Version published
Maintainers
1
Install size
6.58 kB
Created

Readme

Source

gulp-collect

gulp-collect collects all the (vinyl) files from a stream, and then calls a given callback once to process all of them.

Example

Here is a dummy example which sorts files by name and then adds properties to the file object to build a doubly linked list.

var gulp = require("gulp");
var collect = require("gulp-collect");

gulp.task("default", function() {
  return gulp.src("src/**")
    .pipe(collect.list(function(files) {
      files.sort(function(a, b) {
        if (a.relative < b.relative) return -1;
        if (a.relative > b.relative) return +1;
        return 0;
      });
      var prev = files[0];
      for (var i = 1; i < files.length; ++i) {
        var next = files[i];
        prev.nextPath = next.relative;
        next.prevPath = prev.relative;
      }
      return files;
    }))
    .pipe(gulp.dst("build"));
});

API

collect.list(handler)
collect.dict(handler)

The plugin exports two different functions. A stream created using collect.list will pass the files as a list to the handler. A stream created using collect.dict will instead build a dictionary using relative path names as keys. The latter is very similar to how Metalsmith operates, but the files are still vinyl file objects as gulp uses them.

The handler function has different options regarding its return values.

  • The handler may return an array or dictionary object. Even a collect.list handler may return a dictionary or a collect.dict handler may return an array. The keys of an array are ignored, so if you want to rename a file make sure that you actually modify its path in the vinyl object.

  • The handler may return a promise. The value of the promise can be as described above.

  • The transform stream callback is passed on as a second argument to the handler. So the stream may return nothing, but instead call that function at any time to either signal an error (first argument to the callback) or a single file (second argument). Before calling the callback, the handler may call this.push to push any number of output files.

Keywords

FAQs

Last updated on 09 Dec 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc