@mutant-ws/pluginus

1.2.0 • Public • Published

CircleCI npm package version Coverage Status

pluginus

Dependency injection with promise support - Things that get ran after other things.

Install

npm install @mutant-ws/pluginus

Use

plugins/thing.js

exports default {
  create: () =>
    new Promise(resolve => {
      setTimeout(() => {
        resolve({
          foo: "bar",
        })
      }, 50)
    }),
}

plugins/second-thing.js

module.exports = {
  // First "Thing" is resolved to { foo: "bar" }
  depend: ["Thing"],

  // After dependencies are resolved, the current constructor is called
  create: Thing => ({
    ThingContent: `ipsum ${Thing.foo}`,
  }),
}

index.js

import glob from "glob"
import { pluginus } from "@mutant-ws/pluginus"

pluginus({
  files: glob.sync("./plugins/*.js", { absolute: true }),
}).then(({ Thing, SecondThing }) => {
  // Thing
  // => {
  //   foo: "bar",
  // }
  // SecondThing
  // => {
  //   ThingContent: "ipsum bar",
  // }
})

Develop

git clone git@github.com:mutant-ws/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.

Package Sidebar

Install

npm i @mutant-ws/pluginus

Weekly Downloads

1

Version

1.2.0

License

BSD-3-Clause

Unpacked Size

25.4 kB

Total Files

32

Last publish

Collaborators

  • andreid