瀏覽代碼

Update loadConfig to allow duplicates

Rashid Khan 12 年之前
父節點
當前提交
07f1571563
共有 1 個文件被更改,包括 9 次插入6 次删除
  1. 9 6
      Gruntfile.js

+ 9 - 6
Gruntfile.js

@@ -15,17 +15,20 @@ module.exports = function (grunt) {
   // load task definitions
   grunt.loadTasks('tasks');
 
-  // Utility function to load plugin configurations into an object
-  function loadConfig(path) {
-    var object = {};
+  // Utility function to load plugin settings into config
+  function loadConfig(config,path) {
     require('glob').sync('*', {cwd: path}).forEach(function(option) {
-      object[option.replace(/\.js$/,'')] = require(path + option)(config);
+      var key = option.replace(/\.js$/,'');
+      // If key already exists, extend it. It is your responsibility to avoid naming collisions
+      config[key] = config[key] || {};
+      grunt.util._.extend(config[key], require(path + option)(config));
     });
-    return object;
+    // technically not required
+    return config;
   }
 
   // Merge that object with what with whatever we have here
-  grunt.util._.extend(config, loadConfig('./tasks/options/'));
+  loadConfig(config,'./tasks/options/');
 
   // pass the config to grunt
   grunt.initConfig(config);