diff --git a/lib/grunt/config.js b/lib/grunt/config.js index a427c3d4e..59b8242ac 100644 --- a/lib/grunt/config.js +++ b/lib/grunt/config.js @@ -81,6 +81,12 @@ config.set = function(prop, value) { return grunt.util.namespace.set(config.data, config.getPropString(prop), value); }; +// Deep merge config data. +config.merge = function(obj) { + grunt.util._.merge(config.data, obj); + return config.data; +}; + // Initialize config data. config.init = function(obj) { grunt.verbose.write('Initializing config...').ok(); diff --git a/test/grunt/config_test.js b/test/grunt/config_test.js index 84db9fa41..ac6fa1785 100644 --- a/test/grunt/config_test.js +++ b/test/grunt/config_test.js @@ -85,6 +85,20 @@ exports['config'] = { test.equal(grunt.config.data.a.b.c, '<%= foo2 %>', 'Should have set the value.'); test.done(); }, + 'config.merge': function(test) { + test.expect(4); + test.deepEqual(grunt.config.merge({}), grunt.config.getRaw(), 'Should return internal data object.'); + grunt.config.set('obj', {a: 12}); + grunt.config.merge({ + foo: 'test', + baz: '123', + obj: {a: 34, b: 56}, + }); + test.deepEqual(grunt.config.getRaw('foo'), 'test', 'Should overwrite existing properties.'); + test.deepEqual(grunt.config.getRaw('baz'), '123', 'Should add new properties.'); + test.deepEqual(grunt.config.getRaw('obj'), {a: 34, b: 56}, 'Should deep merge.'); + test.done(); + }, 'config': function(test) { test.expect(10); test.equal(grunt.config('foo'), 'bar', 'Should retrieve processed data.');