Skip to content

A gulp plugin to merge JSON files into one file, with conflict resolution logic

License

Notifications You must be signed in to change notification settings

robinj/gulp-controlled-merge-json

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gulp-controlled-merge-json

Warning: this repo is not maintained anymore. It will continue to exist as I am aware of projects which depend on it. If you need to make changes, please fork this repo

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).

About

A gulp plugin to merge JSON files into one file, with conflict resolution logic

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%