UNPKG

typhonjs-plugin-manager

Version:

Provides a plugin manager that dispatches events to loaded plugins.

177 lines (147 loc) 3.69 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Defines a class holding the data associated with a plugin including its instance. */ var PluginEntry = function () { /** * Instantiates a PluginEntry. * * @param {string} name - The plugin name. * * @param {object} data - Data describing the plugin, manager, and optional module data. * * @param {Object} instance - The loaded plugin instance. * * @param {EventProxy} eventProxy - An EventProxy associated with the plugin wrapping the plugin manager eventbus. */ function PluginEntry(name, data, instance) { var eventProxy = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : void 0; (0, _classCallCheck3.default)(this, PluginEntry); /** * Data describing the plugin, manager, and optional module data. * @type {object} * @private */ this._data = data; /** * The plugin enabled state. * @type {boolean} * @private */ this._enabled = true; /** * The plugin name. * @type {string} * @private */ this._name = name; /** * The loaded plugin instance. * @type {Object} * @private */ this._instance = instance; /** * An EventProxy associated with the plugin wrapping the plugin manager eventbus. * @type {EventProxy} * @private */ this._eventProxy = eventProxy; } /** * Provides a convenience method to escape file paths. * * @param {string} value - A string to escape. * * @returns {string} */ (0, _createClass3.default)(PluginEntry, [{ key: 'data', /** * Get plugin data. * * @returns {object} */ get: function get() { return this._data; } /** * Get enabled. * * @returns {boolean} */ }, { key: 'enabled', get: function get() { return this._enabled; } /** * Set enabled. * * @param {boolean} enabled - New enabled state. */ , set: function set(enabled) { /** * The plugin enabled state. * @type {boolean} * @private */ this._enabled = enabled; } /** * Get associated EventProxy. * * @returns {EventProxy} */ }, { key: 'eventProxy', get: function get() { return this._eventProxy; } /** * Get plugin instance. * * @returns {Object} */ }, { key: 'instance', get: function get() { return this._instance; } /** * Get plugin name. * * @returns {string} */ }, { key: 'name', get: function get() { return this._name; } }], [{ key: 'escape', value: function escape(value) { if (typeof value !== 'string') { throw new TypeError('\'value\' is not a \'string\''); } // Remove any leading relative directory paths. var escaped = value.replace(/^(\.\.|\.)/, ''); // Escape any forward / reverse slashes for RegExp creation. escaped = escaped.replace(/[\\]/g, '\\'); escaped = escaped.replace(/[\/]/g, '\\/'); return escaped; } }]); return PluginEntry; }(); exports.default = PluginEntry; module.exports = exports['default'];