1.0.7 • Published 5 years ago

zox-plugins v1.0.7

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Develop your app and node modules using plugins!

Use PluginDiscovery to auto-load plugins in your project and node_modules.

Write a plugin:

@MathPlugin({ operation: 'add' })
export class AddPlugin implements IMathPlugin
{
    calc(args: MyArgs): number
    {
        return args.A + args.B;
    }
}

Scan the entire project, a directory, a .js/.jsx/.ts/.tsx file or just a single class or function:

const pluginDiscovery = new PluginDiscovery();
await pluginDiscovery.scanProject();
await pluginDiscovery.scanNodeModules();
await pluginDiscovery.scanDirectory('Plugins');
pluginDiscovery.scanModule(require('./Plugins/AddPlugin'));
pluginDiscovery.scan(AddPlugin);

Individual plugins can also be manually added:

pluginDiscovery.add(pluginkey, AddPlugin, /* optional data */);

Access all plugins of the same type using their pluginkey:

pluginDiscovery.getPlugins(pluginkey);

You can also clear the plugin list, but it's unlikely that you will need to do this.

pluginDiscovery.clear();

package.json

Scanning a project is done based on configuration in your package.json file.

You can specify a list of files to load (extensions are optional):

{
  "plugins": {
    "files": [
      "src/FooPlugin",
      "src/BarPlugin"
    ]
  }
}

You can specify directories that contain your plugins,
in which case all .js/.jsx/.ts/.tsx files in those folders will be loaded:

{
  "plugins": {
    "dirs": [
      "src/Plugins"
    ]
  }
}

Or you can do both

{
  "plugins": {
    "files": [
      "src/FooPlugin",
      "src/BarPlugin"
    ],
    "dirs": [
      "src/Plugins"
    ]
  }
}
1.0.7

5 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago