{"size": 1247, "ext": "js", "max_stars_repo_path": "lib/shovelapps/plugins.js", "max_stars_repo_name": "vaginessa/CMS", "max_stars_repo_stars_event_min_datetime": "2015-01-10T05:57:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-17T06:06:31.000Z", "max_issues_repo_path": "lib/shovelapps/plugins.js", "max_issues_repo_name": "vaginessa/CMS", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/shovelapps/plugins.js", "max_forks_repo_name": "vaginessa/CMS", "max_forks_repo_forks_event_min_datetime": "2015-02-02T04:30:40.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-28T06:46:46.000Z"}
{"max_stars_count": 19, "max_issues_count": null, "max_forks_count": 15, "avg_line_length": 26.5319148936, "max_line_length": 82, "alphanum_fraction": 0.6551724138}
var fs = require("fs"),
  path = require("path"),
  async = require("async");

module.exports = {
  "name": "plugins",
  attach: function() {

    /**
     * Loads every plugin
     * from the plugins folder.
     * We're using broadway plugin mechanism
     * (https://github.com/flatiron/broadway)
     * @param {Function} callback
     *   - {array} plugins - Declared name of every plugin that was loaded
     */
    this.loadPlugins = loadPlugins.bind(this);
    this.usePlugin = usePlugin.bind(this);
    this.loadPlugins(function(pluginNames) {

    });
  },
  "init": function(done) {}
}

function loadPlugins(callback) {
  var _this = this,
    pluginsNames;
  pluginNames = fs.readdirSync(_this._options.pluginsPath).filter(function(file) {
    return fs.statSync(path.join(_this._options.pluginsPath, file)).isDirectory();
  });
  async.each(pluginNames, function(pluginName, asyncCallback) {
      _this.usePlugin(pluginName);
      asyncCallback(null);
    },
    function() {
      callback(_this.plugins)
    });
};

function usePlugin(pluginName) {
  var app = this;
  var _path = path.join(process.cwd(), "plugins", pluginName),
    pluginEntryPoint = pluginName + ".js";
  app.use(require(path.join(_path, pluginEntryPoint)));

}