This commit is contained in:
2024-10-29 19:49:24 +02:00
commit 11eb888b9c
42 changed files with 7877 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
class App{
constructor(){
this.root = path.resolve(dirname(fileURLToPath(import.meta.url)) + '/../../');
}
plugins = [];
async use(plugin){
this[plugin.name] = plugin;
plugin.app = this;
this.plugins.push(plugin);
}
async init(){
for (let p of this.plugins){
console.debug('Initializing', p.name)
if(p.init) await p.init(this);
}
}
async importModules(modules){
const mods = {};
for (let m of modules){
mods[m.name] = (await import(`../${m.path}`))[m.name];
}
for (let m of modules){
this.use(new mods[m.name]())
}
}
async replace(p){
let old = this[p.name];
this.plugins[this.plugins.indexOf(old)] = p;
this[p.name] = p;
p.app = this;
if(p.init) await p.init(this);
}
async start(){
for (let p of this.plugins){
console.debug('Starting', p.name)
if(p.start) await p.start(this);
}
}
}
export default App;