3.0.0 • Published 2 years ago

@asd14/pluginus v3.0.0

Weekly downloads
59
License
MIT
Repository
github
Last release
2 years ago

CircleCI npm version Coverage Status

pluginus

Dependency injection with promise support for Node.js.

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.

3.0.0

2 years ago

2.5.0

2 years ago

2.4.0

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.0

4 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago