Pass deps to plugins directly. Should be used when a plugin must have a module to function.

This commit is contained in:
Jiiks 2018-02-14 10:05:34 +02:00
parent 4fba4049e1
commit b23a5ba7ac
4 changed files with 7 additions and 4 deletions

View File

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

View File

@ -56,7 +56,7 @@ export default class extends ContentManager {
'message': `Dependency: ${key}:${value} is not loaded` 'message': `Dependency: ${key}:${value} is not loaded`
}; };
} }
deps.push(extModule); deps[key] = extModule.__require;
} }
} }

View File

@ -9,6 +9,9 @@
}, },
"main": "index.js", "main": "index.js",
"type": "plugin", "type": "plugin",
"dependencies": {
"Example Module": "1.0"
},
"defaultConfig": [ "defaultConfig": [
{ {
"category_default_comment": "default category has no header and is always displayed first", "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 { $, moment, _ } = Vendor;
const { Events, Logger } = Api; const { Events, Logger } = Api;
@ -21,7 +21,7 @@ module.exports = (Plugin, Api, Vendor) => {
console.log('Received internal setting update:', event); 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)}`); Logger.log(`2+4=${exampleModule.add(2, 4)}`);
return true; return true;
} }