var fileUtils = require('../utils/fileUtils.js');
var fs = require('fs');
var pluginsLoader = function(app) {
  app.plugins = new Object();
  if (app.isDebug) {
    console.log("Scanning plugins in %s", app.constants.PLUGINS_DIR);
  }
  var arrFiles = fileUtils.readRootDirOnlySync(app.constants.PLUGINS_DIR);
  for (var i in arrFiles) {
    var file = arrFiles[i];

    handleFile(app, file);
  }

  if (app.isDebug) {
    console.log('Done reading plugins directory.');
  }
  /*
  fileUtils.readRootDirOnly(app.constants.PLUGINS_DIR, function(err, opts) {
    if (opts.isDirectory()) {
      var pluginConf = getPluginConf(opts.absolutePath);
      var pluginName = opts.file; //later might get from conf
      if (pluginConf.enabled) {
        if (app.isDebug) {
          console.log('[plugin] %s', pluginName);
        }
        
        app.plugins[pluginName] = require(opts.absolutePath);
      } else {
        if (app.isDebug) {
          console.log('Plugin %s is NOT enabled. Skipping.', pluginName);
        }
      }
    }
  });
*/
}

function handleFile(app, file) {
  var pluginDir = global.BASE_DIR + app.constants.PLUGINS_DIR;

  var stat = fs.statSync(pluginDir);

  if (stat && stat.isDirectory()) {
    
    var absolutePath = pluginDir + '/' + file;
    //console.log('!!!' + absolutePath);

    var pluginConf = getPluginConf(absolutePath);
    var pluginName = file; //later might get from conf
    if (pluginConf.enabled) {
      if (app.isDebug) {
        console.log('[plugin] %s', pluginName);
      }
      
      app.plugins[pluginName] = require(absolutePath);
    } else {
      if (app.isDebug) {
        console.log('Plugin %s is NOT enabled. Skipping.', pluginName);
      }
    }
  }
  
}

function getPluginConf(dir) {
  var conf = require(dir + '/conf.js');

  return conf;
}


module.exports  = pluginsLoader;
@@ -473,629 +473,62 @@
   %7D%0A
-  /*%0A  fileUtils.readRootDirOnly(app.constants.PLUGINS_DIR, function(err, opts) %7B%0A    if (opts.isDirectory()) %7B%0A      var pluginConf = getPluginConf(opts.absolutePath);%0A      var pluginName = opts.file; //later might get from conf%0A      if (pluginConf.enabled) %7B%0A        if (app.isDebug) %7B%0A          console.log('%5Bplugin%5D %25s', pluginName);%0A        %7D%0A        %0A        app.plugins%5BpluginName%5D = require(opts.absolutePath);%0A      %7D else %7B%0A        if (app.isDebug) %7B%0A          console.log('Plugin %25s is NOT enabled. Skipping.', pluginName);%0A        %7D%0A      %7D%0A    %7D%0A  %7D);%0A*/%0A%7D%0A%0Afunction handleFile(app, file) %7B%0A  var pluginDir
+%7D%0A%0Afunction handleFile(app, file) %7B%0A  var absolutePath
  = g
@@ -569,18 +569,30 @@
 GINS_DIR
+ + '/' + file
 ;
-%0A
 %0A  var s
@@ -613,20 +613,25 @@
 ync(
-pluginDir
+absolutePath
 );%0A
+  
 %0A  i
@@ -666,101 +666,8 @@
 )) %7B
-%0A    %0A    var absolutePath = pluginDir + '/' + file;%0A    //console.log('!!!' + absolutePath);
 %0A%0A  

fix for directory check