npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-plugins

v1.1.1

Published

Provides a Simple Plugin Manager.

Downloads

20

Readme

Build Status Build Status npm version

NPM

Simple Plugins

This utility provides a simple plugin manager and plugin base class. This provides installation, uninstallation, enable and disable functionality as a plugin manager. And the plugin class provides a means to access the callbacks and an event emitter connected to the single manager, or to each plugin.

Installation

$ npm install simple-plugins

PluginManager Usage

const SimplePlugins = require('simple-plugins');
pm = new SimplePlugins.PluginManager();
pm.index(() => {
    pm.boot(() => {
        // Done.
    });
});

Or you can boot specific plugins, for instance from a configuration of enabled plugins:

const SimplePlugins = require('simple-plugins');
let enabled = ['plugin-1', 'plugin-2'];

pm = new SimplePlugins.PluginManager();
pm.index(() => {
    pm.boot(() => {
        // Reset the config, just incase plugins have been removed since the
        // config value had been set.
        enabled = pm.enabled;

        // Trigger an event on the manage.
        pm.emit('event');

        // Send a message to all plugins.
        pm.message((err, response) => {
            // Message sent.
        }, 'a-message', {hello: 'world'}, null, 'sender');

        // Or send a message to a specific plugin.
        pm.message((err, response) => {
            // Message sent.
        }, 'a-message', {hello: 'world'}, 'plugin-1', 'sender');

        // Get the plugin instance.
        const plugin = pm.plugin('plugin-1');
        const pluginId = pm.pluginId(plugin); // Returns 'plugin-1'.

        done();
    }, enabled);
});

Each plugin can be given a "class", this is the type of plugin and allows you to only index and boot plugins of specific classes. The default class is "simple".

const SimplePlugins = require('simple-plugins');
pm = new SimplePlugins.PluginManager('my-plugin-class');

or

const SimplePlugins = require('simple-plugins');
pm = new SimplePlugins.PluginManager(['my-plugin-class', 'another-plugin-class']);

Plugin Usage

    "SimplePlugins": {
        "plugin-1": {
            "description": "My custom plugin (1).",
            "class": "plugin-class",
            "namespace": "lib/Plugin1"
        },
        "plugin-2": {
            "description": "My custom plugin (2).",
            "class": "another-plugin-class",
            "namespace": "lib/Plugin2"
        }
    }

The ID given to the plugin will be "module-name/plugin-name" so for example if these plugins are in a module called "my-plugins", then the plugin IDs would be "my-plugins/plugin-1" and "my-plugins/plugin-2".

Testing

A mocha test suite has been provided and can be run by:

$ npm test