@mutant-ws/pluginus
v1.2.0
Published
Dependency injection with promise support.
Downloads
4
Maintainers
Readme
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 [email protected]: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.