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-component-manager

v1.0.4

Published

A simple framework for managing multiple components, their dependencies, and configuration of their features

Downloads

13

Readme

Build Status Coverage Status

Waffle.io - Columns and their card count

Allows you to create software components that you can register, lookup, and combine together at run-time.

Install

npm install scm

Using

Define a scm-config.json file and run scm from the command line (or a boot script).

Some initial documentation can be found here.

About

Simple Component Manager (SCM) is an Inversion of Control framework for node.js that enables late binding through service locator injection and generic-type injection.

Whew. That's a mouthfull. What does it actually mean?

Normally you have to do includes in node.js using require(). If I want to use a database, I have to decide whether I want to require("mongodb") or require("mysql") when I'm writing my code. And if I want to give the user the choice, I have to write some logic around that and include all the options the user might want to use.

SCM turns that upside-down. Rather than doing require() you define components, such as a database component and register them with the ComponentManager (typically things are registered automatically through the scm-config.json). Things that use databases could then call ComponentManager.get("database") and then use the database withouth caring which database is underneath.

This is great for databases, loggers, communication protocols, etc. where there are so many choices, so many religions, and no right answers that the only solution is to offer flexibility.

scm-config.json

The scm-config.json can be located in the local directory, or globally in /etc/scm.

The most important section of the scm-config.json is the components list, which says which components are needed. Each component object in the list has a name, a type, a package and optionally pre-config and post-config settings. Here is an example of a single component declaration:

{
    "name": "http",
    "type": "generic",
    "package": "component-web",
    "pre-config": [{
        "set-port": 8888
    }]
}

This component declares that it is using the component-web component, which we will name "http" (that's the name other components will use to find it). It will install the npm package component-web (any valid package name should work, including package@version and /path/to/a/package). Before the init() function of the component is called, the pre-config says that we should call set-port with 8888.

Here is an example of a full scm-config.json.

// scm-config
//
// this is a JSON file that allows JavaScript-style comments
{
    // setuid and setgid are only required if running with sudo
    // you can delete these lines and run without sudo if your http/https ports don't require special privledges
    // "setuid": 1,
    // "setgid": 1,
    "components": [{
        "name": "http",
        "type": "generic",
        "package": "component-web",
        "pre-config": [{
            "set-port": 8888
        }],
        "post-config": [{
            "set-redirect": {
                "destProtocol": "https",
                "destPort": 8443,
                "destTemporary": false
            }
        }]
    }, {
        "name": "https",
        "type": "generic",
        "package": "component-web",
        "pre-config": [{
            "set-port": 8443,
            "set-https": true,
            "set-domain": "localhost",
            "set-body-parser": "json",
            "set-enable-session": true
        }, { // demo UI for WebAuthn
            "add-static": {
                "path": "/",
                "dir": "webauthn-yubiclone"
            }
        }, { // serve up swagger UI
            "add-static": {
                "path": "/swagger",
                "dir": "fido2-swagger"
            }
        }]
    }, {
        "name": "cert-manager",
        "type": "generic",
        "package": "component-certs-static",
        "pre-config": [{
            "set-cert-file": "data/node_modules/component-certs-static/test/helpers/certs/cert.pem",
            "set-key-file": "data/node_modules/component-certs-static/test/helpers/certs/key.pem"
        }]
    }, {
        "name": "fido2",
        "type": "generic",
        "package": "/Users/apowers/Projects/fido2-stack/component-fido2",
        "pre-config": [{
            "enable-dangerous-open-registration": true,
            "enable-dangerous-xmit-debug-info": true,
            "set-service-name": "WebAuthn.org"
        }]
    }, {
        "name": "uds",
        "type": "generic",
        "package": "/Users/apowers/Projects/components/component-uds-json"
    }, {
        "name": "logger",
        "type": "logger",
        "package": "component-logger-winston",
        "pre-config": [{
            "set-level": "silly",
            "add-transport": [{
                // log to the screen...
                "type": "console",
                "colorize": true
            }, {
                // ...and log to a file
                // see winston's npm page for more transport configuration options
                "type": "file",
                "filename": "scm.log"
            }]
        }]
    }]
}

Custom Components

You can define your own components, which can be really anything (even plain-ole Objects or Functions). For convenience functions, you can use the component-class which also includes a template that shows how to use other components.