BasePlugin
This file defines the BasePlugin
class, which serves as the base class for all plugins in the @sodacore/core
library. It provides default properties, logging, and automatic plugin configuration registration in the Registry
.
Features
- Default Properties: Provides default values for
name
,author
,description
,version
, anddependencies
. - Logging: Provides a protected
logger
property for use in derived plugins. - Automatic Registration: Includes a
setup
method to register the plugin's configuration in the globalRegistry
.
Usage
typescript
import BasePlugin from './base/plugin';
class MyPlugin extends BasePlugin {
constructor(config: Record<string, any>) {
super(config);
this.name = '@sodacore/my-plugin';
this.description = 'A custom plugin for Sodacore.';
}
// Optionally override setup or other logic
}
API
Properties
- logger: An injected instance of the
Logger
class, available to subclasses. - name: The name of the plugin. Defaults to
'@sodacore/example'
. - author: The author of the plugin.
- description: A short description of the plugin.
- version: The plugin version.
- dependencies: An array of plugin dependencies.
Constructor
typescript
constructor(protected config?: Record<string, any>)
- config: Optional configuration object for the plugin.
Methods
protected setup(): void
Registers the plugin's configuration in the Registry
under a key based on the plugin's name (removing the @sodacore/
prefix if present).
Notes
- Extend this class to create new plugins for the Sodacore ecosystem.
- The
setup
method should be called by the extending plugin to ensure configuration is registered. - The class uses dependency injection for the logger.