From dc5568fb496ad18dad9d79030498f33a517826a0 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 17 Apr 2026 02:07:33 +1000 Subject: [PATCH] Initial commit: Example Plugin 2 --- .gitignore | 2 ++ README.md | 46 +++++++++++++++++++++++++++ index.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 10 ++++++ plugin.json | 17 ++++++++++ 5 files changed, 164 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 index.js create mode 100644 package.json create mode 100644 plugin.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..552f221 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +*.log diff --git a/README.md b/README.md new file mode 100644 index 0000000..75e8b2b --- /dev/null +++ b/README.md @@ -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 diff --git a/index.js b/index.js new file mode 100644 index 0000000..d9fac1e --- /dev/null +++ b/index.js @@ -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); +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..52740fc --- /dev/null +++ b/package.json @@ -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" +} diff --git a/plugin.json b/plugin.json new file mode 100644 index 0000000..a498e5f --- /dev/null +++ b/plugin.json @@ -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" + ] +}