-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: add hooks support for wiki caching customization #10
Comments
NPM Dependencies: use dynamic import inside callback-function definition. module.exports = async (data) => {
const axios = require('axios'); // Example dependency
console.log('Custom Callback: Data received:', data);
// Use axios to send the data somewhere
await axios.post('https://example.com/api', data);
}; const fs = require('fs');
const path = require('path');
class HookManager {
constructor() {
this.hooks = {};
}
registerHook(name, callback) {
if (!this.hooks[name]) {
this.hooks[name] = [];
}
this.hooks[name].push(callback);
}
async executeHooks(name, ...args) {
if (this.hooks[name]) {
for (const callback of this.hooks[name]) {
await callback(...args);
}
}
}
async loadAndRegisterHooks(hookConfigPath) {
const config = require(hookConfigPath);
for (const hookName in config.hooks) {
const hookFiles = config.hooks[hookName];
for (const hookFile of hookFiles) {
const hookPath = path.resolve(hookFile);
// Dynamically load the callback
const callback = require(hookPath);
// Register the callback
this.registerHook(hookName, callback);
}
}
}
}
module.exports = HookManager; const HookManager = require('./HookManager');
const hookManager = new HookManager();
// Load hooks from a configuration file (JSON or YAML)
(async () => {
await hookManager.loadAndRegisterHooks('./hooks.yaml');
// Trigger the hook to see it in action
hookManager.executeHooks('onDataReceived', { id: 1, name: 'Sample Data' });
})(); |
build package like webpack and conf |
Implement a middleware system where users can add functions to be executed at specific stages. |
Feature description
The text was updated successfully, but these errors were encountered: