Initial commit: Plugin Host system

This commit is contained in:
2026-04-17 01:48:22 +10:00
commit f423c50d68
5 changed files with 380 additions and 0 deletions

59
README.md Normal file
View File

@@ -0,0 +1,59 @@
# Plugin Host
A lightweight, event-driven plugin host system for Node.js applications.
## Features
- **Dynamic Plugin Loading**: Load plugins at runtime from a local directory
- **Plugin Registry**: Automatic fetching of available plugins from a remote directory
- **Hook System**: Plugins can register hooks for extensibility
- **Event System**: EventEmitter-based communication between host and plugins
- **Hot Reload**: Support for unloading and reloading plugins
- **Auto-Update**: Periodic registry updates from the plugin directory
## Installation
```bash
npm install
```
## Usage
```javascript
import { PluginHost } from './src/PluginHost.js';
const host = new PluginHost({
directoryUrl: 'http://your-plugin-directory/plugins',
pluginsDir: './plugins',
autoUpdate: true,
updateInterval: 300000 // 5 minutes
});
await host.initialize();
await host.loadPlugins();
```
## Plugin Context API
Plugins receive a context object with the following API:
- `registerHook(hookName, callback)` - Register a hook
- `unregisterHook(hookName, callback)` - Unregister a hook
- `runHook(hookName, ...args)` - Execute a hook
- `getConfig(key)` - Get plugin configuration
- `log(...args)` - Log with plugin prefix
- `on(event, listener)` - Listen to host events
- `emit(event, ...args)` - Emit events
## Events
- `initialized` - Host initialized
- `registry-updated` - Plugin registry updated
- `plugin-loaded` - Plugin loaded
- `plugin-unloaded` - Plugin unloaded
- `plugin-error` - Plugin error occurred
- `shutdown` - Host shutting down
## License
MIT