0.2.1 • Published 9 years ago

gulp-controlled-merge-json v0.2.1

Weekly downloads
126
License
MIT
Repository
github
Last release
9 years ago

gulp-controlled-merge-json

NPM Version Build Status Coverage Status Dependency Status Dev Dependency Status

A gulp plugin for deep-merging multiple JSON files into one file. Any conflicting attributes are recorded and output to the console once the merge has completed.

The main use case, and the reason that this plugin was developed, is the merging of language files.

Usage

var merge = require('gulp-controlled-merge-json');

/*
	Basic functionality
 */
gulp.src('jsonFiles/**/*.json')
	.pipe(merge('combined.json'))
	.pipe(gulp.dest('./dist'));

This will merge your input files into a file called "combined.json" and then output them into your dist directory.

Example Input

This is an example of an input where there are no conflicting keys

/*
	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"
	}
}

Conflicts

In the event of a conflict, the first value will be merged and the attribute name will be output to the console.

conflicting keys have been found
Key myKey found in /path/to/jsonFile.json but also in  /path/to/other/jsonFile.json

The plugin will then emit an error.

Credits

Based on gulp-merge-json by @joshswan. Adapted by @robinj (Robin Janssens) and powered by 9888.