Initial commit: Example Plugin 2

This commit is contained in:
2026-04-17 02:07:33 +10:00
commit dc5568fb49
5 changed files with 164 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules/
*.log

46
README.md Normal file
View File

@@ -0,0 +1,46 @@
# Example Plugin 2
A second demonstration plugin showing additional plugin system capabilities.
## Features
- ✅ Data filtering hooks
- ✅ Input validation
- ✅ Text transformation
- ✅ Configurable periodic tasks
- ✅ Multi-hook patterns
## Plugin Manifest
```json
{
"id": "example-plugin-2",
"name": "Example Plugin 2",
"version": "1.0.0",
"author": "litruv",
"main": "index.js"
}
```
## Hooks Provided
- `filter-data` - Filters out null/undefined values from arrays
- `validate-input` - Validates string inputs
- `transform-text` - Converts text to uppercase
## Configuration
```json
{
"enabled": true,
"interval": 60000
}
```
## Usage
This plugin automatically activates when loaded by the Plugin Host.
## License
MIT

89
index.js Normal file
View File

@@ -0,0 +1,89 @@
/**
* Example Plugin 2 - Another demonstration plugin
*
* This plugin shows different patterns:
* - Data filtering
* - Configuration usage
* - Multiple hook patterns
*/
let taskInterval = null;
/**
* Called when the plugin is loaded
* @param {Object} context - Plugin context API
*/
export async function activate(context) {
context.log('Example Plugin 2 activated!');
const enabled = context.getConfig('enabled');
const interval = context.getConfig('interval');
context.log(`Configuration: enabled=${enabled}, interval=${interval}ms`);
// Register a data filtering hook
context.registerHook('filter-data', async (data) => {
context.log('Filtering data...');
// Filter out any items with null values
return data.filter(item => item !== null && item !== undefined);
});
// Register a validation hook
context.registerHook('validate-input', async (input) => {
context.log('Validating input:', input);
if (!input || typeof input !== 'string') {
throw new Error('Invalid input: must be a non-empty string');
}
return { valid: true, input };
});
// Register a transform hook
context.registerHook('transform-text', async (text) => {
context.log('Transforming text...');
return text.toUpperCase();
});
// Start periodic task if enabled
if (enabled) {
taskInterval = setInterval(() => {
context.log('Periodic check running...');
}, interval);
}
// Listen for other plugins loading
context.on('plugin-loaded', (plugin) => {
if (plugin.id !== 'example-plugin-2') {
context.log(`Detected plugin: ${plugin.name}`);
}
});
}
/**
* Called when the plugin is unloaded
* @param {Object} context - Plugin context API
*/
export async function deactivate(context) {
context.log('Example Plugin 2 deactivating...');
if (taskInterval) {
clearInterval(taskInterval);
taskInterval = null;
}
context.log('Example Plugin 2 deactivated!');
}
/**
* Process data array
*/
export function processData(data) {
console.log('Processing data array:', data);
return data.map(item => ({ ...item, processed: true }));
}
/**
* Format output
*/
export function formatOutput(data) {
return JSON.stringify(data, null, 2);
}

10
package.json Normal file
View File

@@ -0,0 +1,10 @@
{
"name": "@pluginhost/example2",
"version": "1.0.0",
"description": "A second example plugin for the plugin host system",
"main": "index.js",
"type": "module",
"keywords": ["plugin", "example"],
"author": "litruv",
"license": "MIT"
}

17
plugin.json Normal file
View File

@@ -0,0 +1,17 @@
{
"id": "example-plugin-2",
"name": "Example Plugin 2",
"version": "1.0.0",
"description": "A second example plugin demonstrating additional capabilities",
"author": "litruv",
"main": "index.js",
"repository": "http://synbox.ruv.wtf:8418/litruv/Plugin-Example2.git",
"config": {
"enabled": true,
"interval": 60000
},
"permissions": [
"hooks",
"events"
]
}