0.1.0-alpha.4 • Published 4 years ago
kuspe v0.1.0-alpha.4
kuspe
kuspe provides an application plugin architecture with dependency resolution.
Installation
yarn add kuspe
or
npm install --save kuspe
kuspe is a ES2015, or ES6, package and requires the running environment to support Set
and the iterable protocol.
Usage
kuspe uses Tarjan's algorithm and topological sorting to provide an array of extensions sorted by dependency order.
import { Extension, extensionManager } from "kuspe";
// Add your own properties for your extension type
type AppExtension = Extension;
const a: AppExtension = {
provides: ["a"]
needs: [],
uses: [],
excludes: [],
first: false,
last: false
};
const b: AppExtension = {
provides: ["b"],
needs: ["a"],
uses: [],
excludes: [],
first: false,
last: false
};
const extensions = extensionManager<AppExtension>();
extensions.register(b);
extensions.register(a);
// Extensions are returned in dependency order
console.log(extensions.order()); // [a, b]
kuspe also provides a plugin manager which returns an array of plugins in order of registration; no dependency resolution is included and any object may be used.
import { Plugin, pluginManager } from "kuspe";
// You can define your own plugin type, if desired
type AppPlugin = Plugin;
const plugins = pluginManager<AppPlugin>();
const a = { name: "a" };
const b = { name: "b" };
plugins.register(b);
plugins.register(a);
// Plugins are returned in registration order
console.log(Array.from(plugins)); // [b, a]
Prior Art
This package is based on the work included in marrow.package
for plugin management.
What does "kuspe" mean?
It's a Lojban gismu.