Skip to content

Simple and fast dependency injection with promise support.

License

Notifications You must be signed in to change notification settings

heartsradiant/pluginus

This branch is 10 commits ahead of asd-xiv/pluginus:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

fcbbe8e · May 30, 2022
Apr 17, 2022
Apr 17, 2022
May 30, 2022
Jun 2, 2021
May 3, 2018
Jun 2, 2021
Apr 17, 2022
Dec 28, 2020
Aug 2, 2019
Jun 2, 2021
Apr 17, 2022
May 30, 2022
Apr 17, 2022
Sep 3, 2020
May 30, 2022
May 30, 2022
May 30, 2022

Repository files navigation

CircleCI npm version Coverage Status

pluginus

Dependency injection with promise support for Node.js.

This is Heartsradiant's fork.

Install

npm install @asd14/pluginus

Use

plugin-1.js

exports default {
  /**
   * Which plugins need loading before this one
   *
   * @type {string[]}
   */
  depend: [],

  /**
   * Name other plugins can use to reference and use this plugin
   *
   * @type {string}
   */
  name: "PluginOne",

  /**
   * Factory function, only runs once when ititialized. The value this function
   * returns or resolves to will be passed to other plugins depending on it.
   *
   * @param {any} ...dependentPlugins
   *
   * @returns {* | Promise<*>}
   */
  create: () => {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve({
          foo: "bar",
        })
      }, 50)
    })
  },
}

plugin-2.js

export default {
  depend: ["PluginOne"],

  name: "Plugin2",

  create: PluginOne => ({
    lorem: `ipsum ${PluginOne.foo}`,
  }),
}

index.js

import { pluginus } from "@asd14/pluginus"

pluginus({
  source: ["path-to-plugin1", "path-to-plugin2"],
}).then(({ PluginOne, Plugin2 }) => {
  // PluginOne
  // => {
  //   foo: "bar",
  // }
  // Plugin2
  // => {
  //   lorem: "ipsum bar",
  // }
})

Develop

git clone git@github.com:asd-xiv/pluginus.git && \
  cd pluginus && \
  npm run setup

Run all *.test.js in src folder

npm test

Watch src and examples folder for changes and re-run tests

npm run tdd

Changelog

See the releases section for details.

About

Simple and fast dependency injection with promise support.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 88.5%
  • Shell 9.3%
  • TypeScript 2.2%