@reaxi/plugin-system
v0.5.1
Published
plugin system for any node.js application
Downloads
3
Maintainers
Readme
commander-plugin-system
plugin system for any node.js application
- creates an complete plugin system for your application,
- you can even extend any package that doesn't support plugins: commander.js example
originally designed for reaxi, but will work on any node.js program
features
Plugin Loader
Program enhancer: enhances your program runtime with additional commands, arguments, options (with validation)
Plugin Schema/Validation https://github.com/colinhacks/zod
Plugins are simple plain javascript objects, so the possibilites are unlimited
Plugin Filter, filters by any property, (like detecting when to use it on runtime)
Typescript shines, you can extend the plugin definition for your application needs (creates unlimited plugins types)
Usage
Examples
your own library:
Commander.js
import { PluginCommand } from 'commander-plugin-system';
const loader = new PluginLoader(/* strategy */);
const enhancer = new PluginEnhancer(/* strategy */);
const plugins = loader.run();
const enhancedProgram = enhancer.enhance(program, plugins);
//option 1
export { enhancedProgram as program };
//option 2
enhancedProgram.parseArgs();
//* your base program */
program.addCommand(new PluginCommand());
express.js:
...
defining plugins:
commonjs:
module.exports = [
{
name: 'exported plugin',
},
];
please note the syntax (an array of objects) the array is only required for module.exports syntax ( and even for just one plugin)
es modules (preferred)
//plugin.[j|t]s
// single plugin
export const myPlugin = {
...props,
};
//multi plugins:
export const myPlugins = [
{
...plugin,
},
{
...plugin2,
},
{
...plugin3,
},
];