gulp-data
gulp-data copied to clipboard
How can i append the data to an existing JSON file?
Hi, how can i append the data i get from front-matter to an existing json file? Here's what i have:
`gulp.task('meta', function(){ return gulp.src(path.posts) .pipe(plumber({ handleError: onError })) .pipe(frontMatter({ property: 'meta'})) //.pipe(data(function(file){ // file.meta.path = file.path // })) .pipe(pluck('meta', 'meta.json')) .pipe(data(function(file){ file.contents = new Buffer(JSON.stringify({'articles': file.meta}, null, ' ')); //var obj = JSON.parse(require './config.json'); //obj.articles = file.contents;
}))
.pipe(gulp.dest('dev/articles/'))
});`
At the moment it outputs to a meta.json file, i'd like for it to append the data to an existing config.json under an "artilcles" key.
Thanks, Tiago
This is from my project and works well.
- Append static json
- Append currFile
- Append GrayMatter Data (works same as FrontMatter)
.pipe(plugins.data(function (file) {
let data = JSON.parse(fs.readFileSync(cacheFile));
data.currFile = path.basename(file.path);
return data;
}))
.pipe(plugins.grayMatter())