Accumulates input vinyls and appends them to the output
Accumulates input files in a stream and appends them to the output.
npm intall vinyl-accumulate
Create gulpfile.js
like the below:
const gulp = require('gulp')
const frontMatter = require('gulp-front-matter')
const accumulate = require('vinyl-accumulate')
gulp.src('src/**/*.md')
.pipe(frontMatter())
.pipe(accumulate('index.html'))
.pipe(anyTransform())
.pipe(gulp.dest('dest'))
Then all the input files are accumulated into one file called index.html
(The contents is empty) at accumulated
node. The output file has .files
property which is the array of the all input files.
For example, you can use it like the below:
gulp.src('src/**/*.md')
.pipe(frontMatter())
.pipe(accumulate('index.html'))
.pipe(through2.obj((file, enc, cb) => {
file.files.forEach(inputFile => {
// Concatenates all the input file's contents.
file.contents = Buffer.concat([file.contents, inputFile.contents])
})
cb(null, file)
}))
.pipe(gulp.dest('dest'))
Then you get dest/index.html
whose contents is the concatenation of src/**/*.md
.
There is another API called accumulate.through
:
gulp.src('src/**/*.md')
.pipe(frontMatter())
.pipe(accumulate.through())
.pipe(anyTransform)
.pipe(gulp.dest('dest'))
accumulate.through()
passes through all the input files but appending all the input files to each file at the property .files
.
Pass the sort function to sort option and the result is sorted by it.
gulp.src('src/**/*.md')
.pipe(frontMatter())
.pipe(accumulate.through({sort: (x, y) => x.frontMatter.date - y.frontMatter.date}))
.pipe(anyTransform)
.pipe(gulp.dest('dest'))
The above example sorts the output files
in the ascending order of the date front-matter property.
By default, vinyl-accumulate
emits the output when the input stream ends. (This is fine when you works with gulp because streams always end in gulp.) If you need to use this module with streams without end like in bulbo
, you need to use debounce
options. It debounces the input stream with the given debounceDuration
(default: 500ms) and outputs after that duration.
const bulbo = require('bulbo')
bulbo.asset('src/**/*.md')
.pipe(frontMatter())
.pipe(accumulate.through({debounce: true})
.pipe(anyTransform)
const accumulate = require('vinyl-accumulate')
Accumulates the input files and outputs an empty file with the collected files appended.
files
.debounceDuration
). If false, it accumulates all the files until the end of the stream and output only once at the end. Default is false. This option is useful when you handle the vinyl stream which never ends (like in bulbo).debounce
option is true. Default is 500.Passes through all the input. Appends accumulated files to each file at the given property name (default ‘files’)
debounceDuration
. If false, it only outputs at the end of the stream. Default is falseCreate vinyl stream from the given glob pattern. Appends accumulated files to each of them.
debounceDuration
. If false, it only outputs at the end of the stream. Default is falseMIT