I'm trying to achieve this with Gulp
.
- Read every
.json
file in a given directory including subdirectories. - Transform them in some way, for example add a new root level, etc.
- Save them into a new directory keeping original structure.
The point where I'm lost is how to pipe reading/writing JSON to src
.
I have the following skeleton now.
gulp.task("migratefiles", function () {
return gulp.src("files/**/*.json")
.pipe(/* WHAT HERE? */)
.pipe(gulp.dest("processed"));
});
There's a number of way you can do this:
(1) Use the
gulp-json-transform
plugin:Pros:
Promise
)file
Cons:
(2) Use the
gulp-json-editor
plugin:Pros:
js-beautify
optionsCons:
(3) Do it manually (by directly accessing the
vinyl
file object usingmap-stream
):Pros:
done
callback)Cons: