Created
April 21, 2014 17:52
-
-
Save gerred/11150542 to your computer and use it in GitHub Desktop.
doing some config building with through2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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