import Promise from 'bluebird';
import _ from 'lodash';
import fs from 'fs';
import path from 'path';

let log = require('logfilename')('plugins');

export default function Plugins(app){

  let plugins = {};

  function requirePluginDir(pluginPath, name){
    log.debug(`requirePluginDir: ${pluginPath}, name: ${name}`);
    fs.readdirSync(pluginPath)
      .filter( file => file.slice(-9) === 'Plugin.js')
      .forEach(file => {
        plugins[name] = require(path.join(pluginPath, file))(app);
      });
  }

  function createPlugin(dirname) {
      fs.readdirSync(__dirname)
        .filter(file => fs.lstatSync(path.join(dirname, file)).isDirectory())
        .forEach(file => requirePluginDir(path.join(dirname, file), file));
  }

  createPlugin(__dirname);

  async function action(ops){
    await Promise.each(_.values(plugins), obj => obj[ops](app));
  }

  return {
    get(){
      return plugins;
    },
    async start(){
      await action('start');
    },
    async stop(){
      await action('stop');
    }
  };
}

@@ -142,16 +142,64 @@
 ins');%0A%0A
+const blackList = %5B%0A  'fidor',%0A  //'ticket'%0A%5D;%0A%0A
 export d
@@ -700,16 +700,70 @@
 tory())%0A
+        .filter(file =%3E !_.includes(file, blackList))%0A
         

add the possibilty to black list a plugin