base-files-each

0.1.5 • Public • Published

base-files-each NPM version NPM downloads Build Status

Base plugin for iterating over an array of 'files' objects in a declarative configuration and writing them to the file system.

Install

Install with npm:

$ npm install --save base-files-each

Usage

var files = require('base-files-each');

Example

var expand = require('expand-files');
var Base = require('base');
var pipeline = require('base-pipeline');
var each = require('base-files-each');
var vfs = require('base-fs');
var app = new Base();
 
app.use(pipeline());
app.use(each());
app.use(vfs());
 
// register pipeline plugins using the `.plugin` method
app.plugin('foo', function(options) {
  return through.obj(function(file, enc, next) {
    // do plugin stuff 
    next(null, file);
  });
});
 
// use `expand-files` to expand a declarative configuration object
config = expand({
  cwd: fixtures,
  src: '*.txt',
  dest: actual
});
 
// pass the config object to `.each()`
app.each(config)
  .on('end', function() {
    console.log('done!');
  });

API

.each

Iterate over an array of files objects in a declarative configuration, optionally run them through a plugin pipline, then write the files to the file system.

Params

  • config {Object}
  • cb {Function}: Optional callback function. If callback is not passed, .eachStream is called and a stream is returned.

Example

var expand = require('expand-files');
var config = expand.config({src: '*', dest: 'foo/'});
generate.each({files: [config]}, function(err) {
  if (err) throw err;
  console.log('done!');
});
 
// or
generate.each({files: [config]})
  .on('end', function() {
    console.log('done!');
  });

.eachSeries

Generate files configurations in series.

Params

  • config {Object}
  • cb {Function}

Example

var expand = require('expand-files');
var config = expand.config({src: '*', dest: 'foo/'});
generate.eachSeries({files: [config]}, function(err) {
  if (err) throw err;
  console.log('done!');
});

.eachStream

Generate files configurations in parallel.

Params

  • config {Object}
  • returns {Stream}: returns stream with all process files

Example

var expand = require('expand-files');
var config = expand.config({src: '*', dest: 'foo/'});
generate.eachStream({files: [config]}, options)
  .on('error', console.error)
  .on('end', function() {
    console.log('done!');
  });

About

Related projects

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v0.9.0, on July 18, 2016.

Package Sidebar

Install

npm i base-files-each

Weekly Downloads

1

Version

0.1.5

License

MIT

Last publish

Collaborators

  • doowb
  • jonschlinkert