23cfbee2bcc80cb4b1b94c30791bf3e1022dbd49
Example Plugin
A demonstration plugin showing how to build plugins for the Plugin Host system.
Features
This example demonstrates:
- ✅ Plugin activation/deactivation lifecycle
- ✅ Hook registration and execution
- ✅ Event listening and emission
- ✅ Configuration access
- ✅ Logging utilities
- ✅ Periodic tasks
- ✅ Exported functions
Structure
Plugin-Example/
├── plugin.json # Plugin manifest
├── index.js # Main plugin code
├── package.json # NPM metadata
└── README.md # This file
Plugin Manifest (plugin.json)
The manifest defines your plugin's metadata:
{
"id": "example-plugin",
"name": "Example Plugin",
"version": "1.0.0",
"description": "An example plugin",
"author": "Your Name",
"main": "index.js",
"repository": "http://your-git-repo",
"config": {
"greeting": "Hello from Example Plugin!"
},
"permissions": ["hooks", "events"]
}
Plugin API
Lifecycle Methods
export async function activate(context) {
// Called when plugin loads
}
export async function deactivate(context) {
// Called when plugin unloads
}
Context API
context.registerHook(hookName, callback) // Register a hook
context.runHook(hookName, ...args) // Execute hooks
context.getConfig(key) // Get config value
context.log(...args) // Log with plugin prefix
context.on(event, listener) // Listen to events
context.emit(event, ...args) // Emit events
Creating Your Own Plugin
- Copy this example
- Edit
plugin.jsonwith your plugin details - Implement
activate()anddeactivate()inindex.js - Add any additional functions/features
- Submit to the Plugin Directory
Hooks
This example registers:
on-startup- Called when the system startstransform-data- Transform data objects
License
MIT
Description
Languages
JavaScript
100%