3.0.16 • Published 10 months ago

@weedzcokie/plugin-loader v3.0.16

Weekly downloads
31
License
MIT
Repository
github
Last release
10 months ago

plugin-loader

npm

Usage

Define a base class and api for plugins:

// Plugin.ts
import { PluginBase } from "@weedzcokie/plugin-loader";

// this could be anything.
export type PluginApi = {
    x: number
    y: number
}

export default abstract class Plugin extends PluginBase<PluginApi> {
    x: number;
    y: number;
    
    init?(): void;

    constructor(api: PluginApi) {
        super(api);
        // `api` is also available from `this.api`.
        this.x = api.x;
        this.y = api.y;
    }
}

Plugin manifest (plugin.json)

{
    "name": "test-plugin",
    "version": "1.0.0"
}

version must be a semver compatible version string.

And with dependencies, similar to how package.json defines dependencies:

{
    "name": "plugin-2",
    "version": "1.0.0",
    "dependencies": {
        "test-plugin": "^1.0.0"
    }
}

Load plugins:

Assuming the following directory tree:

├─ plugins
│  ├─ test-plugin
│  │  ├── index.ts
│  │  └── plugin.json
│  └─ plugin-2
│     ├── index.ts
│     └── plugin.json
├─ index.ts
└─ Plugin.ts
// index.ts
import Loader, { NodeHandler } from "@weedzcokie/plugin-loader";
import Plugin, { PluginApi } from "./Plugin.ts":

const plugins = await Loader<Plugin, PluginApi>(["test-plugin"], {
    api: {
        x: 1,
        y: 2,
    },

    // Path to where plugins are located
    path: path.resolve('./plugins'),
    log: (msg: string) => console.log('[PluginLoader]', msg),
    handlers: {
        default: NodeHandler
    }
});
3.0.16

10 months ago

3.0.15

10 months ago

3.0.12

12 months ago

3.0.13

12 months ago

3.0.14

12 months ago

3.0.11

2 years ago

3.0.10

2 years ago

3.0.9

3 years ago

3.0.8

3 years ago

3.0.7

3 years ago

3.0.4

3 years ago

3.0.6

3 years ago

3.0.5

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

3.0.0-alpha.2

3 years ago

3.0.0-alpha.1

3 years ago

2.4.1

3 years ago

2.4.0

3 years ago

2.3.0

3 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago