function createPlugin()

in packages/docpack/lib/utils/DocpackPlugin.js [21:72]


function createPlugin(opts) {
  var options = {};
  if (typeof opts == 'function') {
    options.apply = opts;
  } else if (isPlainObject(opts)) {
    options = opts;
  } else if (typeof opts !== 'undefined') {
    throw new TypeError('createPlugin argument can be a function or object only');
  }

  /**
   * @constructor
   */
  function PluginImplementation(config) {
    if (this instanceof PluginImplementation == false) {
      return new PluginImplementation(config);
    }

    this.config = mergeOptions(
      options.defaultConfig || {},
      isPlainObject(config) ? config : {}
    );

    if (options.init) {
      options.init.call(this, config);
    }
  }

  PluginImplementation.prototype = Object.create(DocpackPlugin.prototype);

  PluginImplementation.prototype.config = null;

  PluginImplementation.prototype._name = options.name || UNNAMED_PLUGIN_NAME;

  PluginImplementation.prototype.getName = function() {
    return this._name;
  };

  PluginImplementation.prototype.emitError = function(message) {
    throw new PluginError(message, this);
  };

  PluginImplementation.prototype.emitWarning = function(message) {
    throw new PluginWarning(message, this);
  };

  if (options.apply) {
    PluginImplementation.prototype.apply = options.apply;
  }

  return PluginImplementation;
}