var glob = require('glob');
var fs = require('fs');

var _ = require('lodash');


var lupa = module.exports = {
    run: function run(pattern, plugins, callback) {
        var lupa = this;
        glob(pattern, {}, function (err, files) {
            var data = lupa.analyzeFiles(files, plugins);
            callback(err, data);
        });
    },
    analyzeFiles: function analyzeFiles (files, plugins) {
        function getDataFromPlugins(plugins) {
            return plugins.map(function (plugin) {
                var res = plugin.readFiles(fs, files);
                console.log("DEBUG Data from plugin ",plugin.name, ": ", JSON.stringify(res, null, 2), "\n");
                return res;
            });
        }

        return getDataFromPlugins(plugins).map(function (filesMetadata) {
            return _.indexBy(filesMetadata, 'file');
        }).reduce(function (dict, chunk) {
            return _.merge(dict, chunk);
        }, {});
    }
};

@@ -413,360 +413,82 @@
     
-function getDataFromPlugins(plugins) %7B%0A            return plugins.map(function (plugin) %7B%0A                var res = plugin.readFiles(fs, files);%0A                console.log(%22DEBUG Data from plugin %22,plugin.name, %22: %22, JSON.stringify(res, null, 2), %22%5Cn%22);%0A                return res;%0A            %7D);%0A        %7D%0A%0A        return getDataFromPlugins(plugins)
+return _%0A            .invoke(plugins, 'readFiles', fs, files)%0A            
 .map
@@ -511,24 +511,28 @@
 Metadata) %7B%0A
+    
             
@@ -580,18 +580,35 @@
         
-%7D)
+    %7D)%0A            
 .reduce(
@@ -636,32 +636,36 @@
 ) %7B%0A            
+    
 return _.merge(d
@@ -677,16 +677,20 @@
 chunk);%0A
+    
         

simplify lupa.js file by using _.invoke