Skip to content

Commit

Permalink
Add grunt.config.merge method to deep merge config data. See gruntjsg…
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboy committed May 9, 2014
1 parent 155609c commit 057eb1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/grunt/config.js
Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions test/grunt/config_test.js
Expand Up @@ -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.');
Expand Down

0 comments on commit 057eb1c

Please sign in to comment.