-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from MR-MKZ/10-plugin-system
plugin system
- Loading branch information
Showing
8 changed files
with
98 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { AxonCore, AxonPlugin, Router } from "../../../src"; | ||
export class LogPluginTest implements AxonPlugin { | ||
private logs: number; | ||
|
||
constructor() { | ||
this.logs = 0; | ||
} | ||
|
||
name: string = "Pretty Logger"; | ||
version: string = "1.2.0-beta"; | ||
|
||
init(core: AxonCore): void { | ||
const router = Router(); | ||
|
||
router.get('/log', async (req, res) => { | ||
this.logs++; | ||
|
||
return res.status(200).body({ | ||
message: "This is the fist plugin of AxonJs", | ||
logs: this.logs | ||
}); | ||
}); | ||
|
||
core.loadRoute(router); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { AxonPlugin } from "../types/AxonPlugin"; | ||
import AxonCore from "./AxonCore"; | ||
import { logger } from "./utils/coreLogger"; | ||
|
||
export class PLuginLoader { | ||
private plugins: AxonPlugin[] = []; | ||
|
||
async loadPlugin(plugin: AxonPlugin) { | ||
plugin.name = plugin.name.replace(" ", "-"); | ||
plugin.version = plugin.version.replace(" ", "-"); | ||
this.plugins.push(plugin); | ||
logger.debug(`Plugin ${plugin.name} (${plugin.version}) loaded`); | ||
} | ||
|
||
async initializePlugins(core: AxonCore) { | ||
this.plugins.forEach(plugin => { | ||
plugin.init(core); | ||
logger.info(`Plugin ${plugin.name} (${plugin.version}) initialized`) | ||
}) | ||
} | ||
|
||
async getPlugins(): Promise<AxonPlugin[]> { | ||
return this.plugins; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import AxonCore from "../core/AxonCore"; | ||
|
||
export interface AxonPlugin { | ||
name: string; | ||
version: string; | ||
init(core: AxonCore): void; | ||
[methodName: string]: any; | ||
} |