Skip to content

Instantly share code, notes, and snippets.

@gerred
Created April 21, 2014 17:52
Show Gist options
  • Save gerred/11150542 to your computer and use it in GitHub Desktop.
Save gerred/11150542 to your computer and use it in GitHub Desktop.
doing some config building with through2
var through = require('through2')
var path = require('path')
var File = require('gulp-util').File
var yaml = require('js-yaml')
var configBuilder = function(fileName) {
var buffer = [];
var firstFile = null;
return through.obj(function(file, enc, cb) {
buffer.push(file.frontMatter);
if (!firstFile) firstFile = file;
cb();
}, function() {
if (buffer.length > 0) {
var joinedPath = path.join(firstFile.base, fileName);
var file = new File({
cwd: firstFile.cwd,
base: firstFile.base,
path: joinedPath,
contents: new Buffer(yaml.dump(buffer))
});
this.push(file);
}
this.emit('end');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment