text: const fs    = require('fs');
  const utils = require('./utils');
  
  var m_plugins = [];
  
  module.exports = {
      load: function(pluginsDir) {
          utils.log(`PluginManager@${this.version} loading plugins...`)
          let files = fs.readdirSync(pluginsDir);
  
          for(let file of files) {
              let filename = file.substring(0, file.length - 3);
  
              // . at the start because require needs to go 1 dir level up first, but fs doesn't...
              let plugin = require(`.${pluginsDir}/${filename}`);
  
              m_plugins.push(plugin);
  
              utils.log(`${plugin.name}@${plugin.version} loaded`);
          }
  
          utils.log(`Plugins loaded`);
      },
      getPlugins: function() {
          return m_plugins;
      },
      findPluginByName: function(pluginName, plugins, caseSensitive = false) {
          let pluginNamesArray = plugins.map(plugin => caseSensitive ? plugin.name : plugin.name.toLowerCase());
  
          let index = pluginNamesArray.indexOf(caseSensitive ? pluginName : pluginName.toLowerCase());
  
          if(index != -1) {
              return plugins[index];
          }
  
          return undefined;
      },
      version: '0.1.1'
  }
  