Module loading

This commit is contained in:
Jiiks 2018-02-13 18:06:36 +02:00
parent d406384dd0
commit 1f1d748687
4 changed files with 26 additions and 2 deletions

View File

@ -153,7 +153,7 @@ export default class {
mainPath
}
const content = await this.loadContent(paths, configs, readConfig.info, readConfig.main);
const content = await this.loadContent(paths, configs, readConfig.info, readConfig.main, readConfig.type);
if (reload) this.localContent[index] = content;
else this.localContent.push(content);
return content;

View File

@ -20,6 +20,7 @@ export default class {
this.stop = this.stop.bind(this);
}
get type() { return 'plugin' }
get configs() { return this.__pluginInternals.configs }
get info() { return this.__pluginInternals.info }
get icon() { return this.info.icon }

View File

@ -37,7 +37,16 @@ export default class extends ContentManager {
static get refreshPlugins() { return this.refreshContent }
static get loadContent() { return this.loadPlugin }
static async loadPlugin(paths, configs, info, main) {
static async loadPlugin(paths, configs, info, main, type) {
if (type === 'module') return {
paths,
configs,
info,
main,
type,
module: window.require(paths.mainPath)
}
const plugin = window.require(paths.mainPath)(Plugin, new PluginApi(info), Vendor);
const instance = new plugin({ configs, info, main, paths: { contentPath: paths.contentPath, dirName: paths.dirName } });

View File

@ -0,0 +1,14 @@
module.exports = class {
constructor() {
}
get foo() {
return 'Bar';
}
add(i1, i2) {
return i1 + i2;
}
}