pluginus.xyz

Dependency injection with promise support.

Usage no npm install needed!

<script type="module">
  import pluginusXyz from 'https://cdn.skypack.dev/pluginus.xyz';
</script>

README

CircleCI npm version dev-badge Coverage Status

pluginus

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

Install

npm install pluginus.xyz

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 "pluginus.xyz"

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

Develop

git clone git@github.com:andreidmt/pluginus.xyz.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.