UNPKG

statigen

Version:

A static site generator that supports html, ejs, and markdown source files

58 lines 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class PluginManager { constructor(plugins = []) { this.plugins = []; this.plugins.push(...plugins); } /** * Call `event` on plugins */ emit(eventName, data) { for (let plugin of this.plugins) { if (plugin[eventName]) { plugin[eventName](data); } } } /** * Emit an event and get the first non-undefined return value. * Returning a value from the handler will cancel the rest of the plugin chain. */ getFirst(eventName, data) { for (let plugin of this.plugins) { if (plugin[eventName]) { const returnValue = plugin[eventName](data); if (returnValue !== undefined) { return returnValue; } } } } /** * Add a plugin to the beginning of the list of plugins */ addFirst(plugin) { if (!this.has(plugin)) { this.plugins.unshift(plugin); } } /** * Add a plugin to the end of the list of plugins */ add(plugin) { if (!this.has(plugin)) { this.plugins.push(plugin); } } has(plugin) { return this.plugins.includes(plugin); } remove(plugin) { if (this.has(plugin)) { this.plugins.splice(this.plugins.indexOf(plugin)); } } } exports.default = PluginManager; //# sourceMappingURL=PluginManager.js.map