js doc composer for interop with visual paradigm
This commit is contained in:
@@ -1,19 +1,33 @@
|
||||
import path, { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
/**
|
||||
* Main backend application
|
||||
*/
|
||||
class App{
|
||||
constructor(){
|
||||
this.root = path.resolve(dirname(fileURLToPath(import.meta.url)) + '/../../');
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugins used by the application
|
||||
* @type {AppPlugin[]}
|
||||
*/
|
||||
plugins = [];
|
||||
|
||||
/**
|
||||
* Declaration of plugin usage
|
||||
* @param {AppPlugin} plugin The plugin to be used
|
||||
*/
|
||||
async use(plugin){
|
||||
this[plugin.name] = plugin;
|
||||
plugin.app = this;
|
||||
this.plugins.push(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the application. All plugins are initialized at this stage
|
||||
*/
|
||||
async init(){
|
||||
for (let p of this.plugins){
|
||||
console.debug('Initializing', p.name)
|
||||
@@ -21,6 +35,10 @@ class App{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports modules as plugins in the app by a given list
|
||||
* @param {Array} modules Modules to be imported
|
||||
*/
|
||||
async importModules(modules){
|
||||
const mods = {};
|
||||
for (let m of modules){
|
||||
@@ -32,6 +50,10 @@ class App{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces a plugin
|
||||
* @param {AppPlugin} p Plugin to be replaced
|
||||
*/
|
||||
async replace(p){
|
||||
let old = this[p.name];
|
||||
this.plugins[this.plugins.indexOf(old)] = p;
|
||||
@@ -40,6 +62,9 @@ class App{
|
||||
if(p.init) await p.init(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the application. All Plugins are started at this point
|
||||
*/
|
||||
async start(){
|
||||
for (let p of this.plugins){
|
||||
console.debug('Starting', p.name)
|
||||
|
||||
Reference in New Issue
Block a user