a group and aggregate plugin for gulp (and other streams)
npm install gulp-group-aggregategulp-group-aggregate as a development dependency:
shell
npm install --save-dev gulp-group-aggregate
`
Then, add it to your gulpfile.js:
`javascript
var path = require('path');
var groupAggregate = require('gulp-group-aggregate');
var processFiles = function (files) {...};
gulp.task('folderWrap', function(){
gulp.src(...)
.pipe(groupAggregate({
group: function (file){
// group by the directory name of each file
return path.basename(path.dirname(file.path));
},
aggregate: function (group, files){
// create a new file by processing the grouped files
return {
path: group + '.html',
contents: new Buffer(processFiles(files))
};
}
}));
.pipe(gulp.dest(...));
});
`
API
gulp-group-aggregate is a `function(options)` that returns a `read-write stream`. The _options_ argument should include two functions: _group_ and _aggregate_.
#### options.group
Type: `function(File)` returns `string`
Receives a vinyl from the stream and returns a string which represents its group.
#### options.aggregate
Type: `function(string, File[])` returns `File.options``