Merge pull request #131 from JsSucks/plugin-depenencies

Plugin depenencies
This commit is contained in:
Alexei Stukov 2018-02-14 10:22:27 +02:00 committed by GitHub
commit 401f67382d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 5 deletions

View File

@ -154,7 +154,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.dependencies);
if (reload) this.localContent[index] = content;
else this.localContent.push(content);
return content;

View File

@ -9,6 +9,7 @@
*/
import ContentManager from './contentmanager';
import ExtModuleManager from './extmodulemanager';
import Plugin from './plugin';
import PluginApi from './pluginapi';
import Vendor from './vendor';
@ -44,8 +45,22 @@ export default class extends ContentManager {
static get refreshPlugins() { return this.refreshContent }
static get loadContent() { return this.loadPlugin }
static async loadPlugin(paths, configs, info, main) {
const plugin = window.require(paths.mainPath)(Plugin, new PluginApi(info), Vendor);
static async loadPlugin(paths, configs, info, main, dependencies) {
const deps = [];
if (dependencies) {
for (const [key, value] of Object.entries(dependencies)) {
const extModule = ExtModuleManager.findModule(key);
if (!extModule) {
throw {
'message': `Dependency: ${key}:${value} is not loaded`
};
}
deps[key] = extModule.__require;
}
}
const plugin = window.require(paths.mainPath)(Plugin, new PluginApi(info), Vendor, deps);
const instance = new plugin({ configs, info, main, paths: { contentPath: paths.contentPath, dirName: paths.dirName, mainPath: paths.mainPath } });
return instance;
}

View File

@ -0,0 +1,16 @@
{
"info": {
"id": "depend-error",
"name": "Depend Error",
"authors": [ "Jiiks" ],
"version": 1.0,
"description": "Depend Error Plugin Description",
"icon": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS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tNzIuNiw0My4xaDcyLjVjMzQ2LjIsMS45LDY3MS0xNzEuMiw2NzEtNTY3LjlWNzE2LjdDMTkzMy41LDMxMi4yLDE2MDguNywxMzUuMiwxMjYyLjUsMTM1LjJ6Ii8+PC9nPjwvc3ZnPg=="
},
"main": "index.js",
"type": "plugin",
"dependencies": {
"Nonexistent Module": "1.0"
},
"defaultConfig": []
}

View File

@ -0,0 +1,12 @@
module.exports = (Plugin, Api, Vendor) => {
return class extends Plugin {
onStart() {
return true;
}
onStop() {
return true;
}
}
}

View File

@ -9,6 +9,9 @@
},
"main": "index.js",
"type": "plugin",
"dependencies": {
"Example Module": "1.0"
},
"defaultConfig": [
{
"category_default_comment": "default category has no header and is always displayed first",

View File

@ -1,4 +1,4 @@
module.exports = (Plugin, Api, Vendor) => {
module.exports = (Plugin, Api, Vendor, Dependencies) => {
const { $, moment, _ } = Vendor;
const { Events, Logger } = Api;
@ -21,7 +21,7 @@ module.exports = (Plugin, Api, Vendor) => {
console.log('Received internal setting update:', event);
});
const exampleModule = new (Api.import('Example Module'));
const exampleModule = new Dependencies['Example Module'];
Logger.log(`2+4=${exampleModule.add(2, 4)}`);
return true;
}