Skip to content

Commit 9b144bd

Browse files
authored
Merge pull request #1 from Youssefbaghr/feature/plugin-system
Implement plugin system and add documentation
2 parents 1123930 + 22f3101 commit 9b144bd

File tree

4 files changed

+73
-4814
lines changed

4 files changed

+73
-4814
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,49 @@ Example configuration:
142142
```
143143
3. Add the template using `clixor template --add`
144144

145+
### Creating Plugins
146+
147+
Clixor supports a plugin system that allows you to extend its functionality. Here's how to create a
148+
plugin:
149+
150+
1. Create a new TypeScript file in the `src/plugins` directory.
151+
2. Import the `PluginInterface` from `src/plugins/types/index.ts`.
152+
3. Create a class that implements the `PluginInterface`.
153+
4. Implement the required methods:
154+
- `name`: A string identifier for your plugin.
155+
- `version`: The version of your plugin.
156+
- `initialize`: A method called when the plugin is registered.
157+
- `execute`: The main functionality of your plugin.
158+
159+
Example plugin:
160+
161+
```typescript
162+
import { PluginInterface } from '../types';
163+
export class MyCustomPlugin implements PluginInterface {
164+
name = 'MyCustomPlugin';
165+
version = '1.0.0';
166+
initialize(): void {
167+
console.log('MyCustomPlugin initialized');
168+
}
169+
async execute(context: any): Promise<string> {
170+
return MyCustomPlugin executed with context: ${JSON.stringify(context)};
171+
}
172+
}
173+
```
174+
175+
To use your plugin, register it in the `src/utils/plugins.ts` file:
176+
177+
```typescript
178+
import { MyCustomPlugin } from '../plugins/MyCustomPlugin';
179+
// In the loadPlugins function
180+
const myCustomPlugin = new MyCustomPlugin();
181+
myCustomPlugin.initialize();
182+
// Add logic to use the plugin as needed
183+
```
184+
185+
Plugins allow you to add new commands, modify existing functionality, or integrate with external
186+
services to enhance Clixor's capabilities.
187+
145188
## 🤝 Contributing
146189

147190
We love our contributors! ❤️ Check out the [CONTRIBUTORS.md](CONTRIBUTORS.md) file to see the

src/plugins/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { PluginInterface } from './types';
2+
3+
class PluginManager {
4+
private plugins: Map<string, PluginInterface> = new Map();
5+
6+
registerPlugin(plugin: PluginInterface): void {
7+
this.plugins.set(plugin.name, plugin);
8+
plugin.initialize();
9+
}
10+
11+
async executePlugin(name: string, context: any): Promise<any> {
12+
const plugin = this.plugins.get(name);
13+
if (!plugin) {
14+
throw new Error(`Plugin "${name}" not found`);
15+
}
16+
return await plugin.execute(context);
17+
}
18+
19+
getPlugins(): PluginInterface[] {
20+
return Array.from(this.plugins.values());
21+
}
22+
}
23+
24+
export const pluginManager = new PluginManager();

src/plugins/types/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface PluginInterface {
2+
name: string;
3+
version: string;
4+
initialize: () => void;
5+
execute: (context: any) => Promise<any>;
6+
}

0 commit comments

Comments
 (0)