Skip to content

Commit

Permalink
Add more functionality to Modules, autoload tasks, commands, routes, …
Browse files Browse the repository at this point in the history
…hooks
  • Loading branch information
GaryCraft committed May 29, 2024
1 parent b22794a commit a0b3b72
Show file tree
Hide file tree
Showing 11 changed files with 650 additions and 216 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ This engine is open source and is licensed under the [MIT License](https://opens
As Features are needed, they will be separated into modules, that can be easily installed.
So the main template remains clean and without bloat.

> [!WARNING]
> This project is still in early development, and while production use is viable, stuff mill most certainly break with future updates, until its API is deemed stable.
# Modules

## Included Modules in release branch
Expand Down
27 changes: 27 additions & 0 deletions docs/modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# UtilityDust Modules

UtilityDust is a **modular** application engine, and as such, it supports modules. Modules are used to extend the functionality of the application, without having to modify the engine itself.

## Module structure

A module is a folder within the `modules` directory, and it should contain an `index` file in it. UtilityDust will automatically load it, expecting it to satisfy the Module type, with a respective configuration key, and eventEmitter class.

For reference you can check out the [Discord Module](../src/modules/discord/index.ts) as an example.

A module should have an object as default export that satisfies the `Module` type, with the following properties:
- `name`: A unique string name, used to get the module using the `getModule` function.
- `loadFunction`: An async function that receives the configuration, and should return the [Module Context](#module-context).
- `initFunction`: An async function that receives the context, and should return nothing. you may use this function to finalize the module initialization.
- `paths` (optional): An object with the following properties:
- `hooks` (optional): A string that references the path to the hooks folder, relative to the module folder.
- `routes` (optional): A string that references the path to the routes folder, relative to the module folder.
- `commands` (optional): A string that references the path to the commands folder, relative to the module folder.
- `tasks` (optional): A string that references the path to the tasks folder, relative to the module folder.

Apart from that you can make any folder or file in the module folder, and it will be used only if imported by your module.

## Module Context

As UtilityDust is mostly Event-Based, all module contexts should inherit the `EventEmitter` class, allowing for the relay of function calls and messages between them and the engine.

Many libraries and clients like discord.js, already do so, thus implementing this should be easy.
Loading

0 comments on commit a0b3b72

Please sign in to comment.