gulp-merge-json-2
v0.1.0
Published
A gulp plugin to merge JSON files into one file with a param to pass a var.
Downloads
14
Readme
gulp-merge-json
A gulp plugin for deep-merging multiple JSON files into one file. Export as JSON or a node module.
Usage
var merge = require('gulp-merge-json');
/*
Basic functionality
*/
gulp.src('jsonFiles/**/*.json')
.pipe(merge('combined.json'))
.pipe(gulp.dest('./dist'));
/*
Edit JSON with function
*/
gulp.src('jsonFiles/**/*.json')
.pipe(merge('combined.json', function(parsedJson) {
if (parsedJson.someValue) {
delete parsedJson.otherValue;
}
return parsedJson;
}))
.pipe(gulp.dest('./dist'));
/*
Provide a default object (files are merged in order so object values will be overwritten)
*/
gulp.src('jsonFiles/**/*.json')
.pipe(merge('combined.json', false, {someKey: 'defaultValue'}))
.pipe(gulp.dest('./dist'));
/*
Provide an overwriting object (merged at the end)
*/
gulp.src('jsonFiles/**/*.json')
.pipe(merge('combined.json', false, false, {someKey: 'specialValue'}))
.pipe(gulp.dest('./dist'));
/*
Wrap in var
*/
gulp.src('jsonFiles/**/*.json')
.pipe(merge('dataModule.js', false, false, false, 'my.var'))
.pipe(gulp.dest('./dist'));
Example Input
/*
json/defaults.json
*/
{
"key1": {
"data1": "value1",
"data2": "value2"
},
"key2": {
"dataA": "valueA",
"dataB": {
"a": "b",
"c": "d"
}
}
}
/*
json/development.json
*/
{
"key1": {
"data1": "devValue"
},
"key2": {
"dataB": {
"c": "DEV MODE!"
}
},
"key3": {
"important": "value"
}
}
Example Output
/*
dist/combined.json
*/
{
"key1": {
"data1": "devValue",
"data2": "value2"
},
"key2": {
"dataA": "valueA",
"dataB": {
"dataA": "valueA",
"dataB": {
"a": "b",
"c": "DEV MODE!"
}
}
},
"key3": {
"important": "value"
}
}