Add support for ES6 modules in plugins
This commit is contained in:
parent
0a2b967e36
commit
70f678119a
|
@ -240,7 +240,7 @@ export default class {
|
|||
mainPath
|
||||
};
|
||||
|
||||
const content = await this.loadContent(paths, configs, readConfig.info, readConfig.main, readConfig.dependencies, readConfig.permissions);
|
||||
const content = await this.loadContent(paths, configs, readConfig.info, readConfig.main, readConfig.dependencies, readConfig.permissions, readConfig.mainExport);
|
||||
if (!content) return undefined;
|
||||
if (!reload && this.getContentById(content.id))
|
||||
throw {message: `A ${this.contentType} with the ID ${content.id} already exists.`};
|
||||
|
|
|
@ -74,7 +74,7 @@ export default class extends ContentManager {
|
|||
static get refreshPlugins() { return this.refreshContent }
|
||||
|
||||
static get loadContent() { return this.loadPlugin }
|
||||
static async loadPlugin(paths, configs, info, main, dependencies, permissions) {
|
||||
static async loadPlugin(paths, configs, info, main, dependencies, permissions, mainExport) {
|
||||
if (permissions && permissions.length > 0) {
|
||||
for (let perm of permissions) {
|
||||
Logger.log(this.moduleName, `Permission: ${Permissions.permissionText(perm).HEADER} - ${Permissions.permissionText(perm).BODY}`);
|
||||
|
@ -97,8 +97,15 @@ export default class extends ContentManager {
|
|||
}
|
||||
}
|
||||
|
||||
const plugin = Globals.require(paths.mainPath)(Plugin, new PluginApi(info, paths.contentPath), Vendor, deps);
|
||||
if (!(plugin.prototype instanceof Plugin))
|
||||
const pluginExports = Globals.require(paths.mainPath);
|
||||
|
||||
const pluginFunction = mainExport ? pluginExports[mainExport]
|
||||
: pluginExports.__esModule ? pluginExports.default : pluginExports;
|
||||
if (typeof pluginFunction !== 'function')
|
||||
throw {message: `Plugin ${info.name} did not export a function.`};
|
||||
|
||||
const plugin = pluginFunction.call(pluginExports, Plugin, new PluginApi(info, paths.contentPath), Vendor, deps);
|
||||
if (!plugin || !(plugin.prototype instanceof Plugin))
|
||||
throw {message: `Plugin ${info.name} did not return a class that extends Plugin.`};
|
||||
|
||||
const instance = new plugin({
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
"description": "Plugin for testing array setting events as the first example plugin has a lot of stuff in it now."
|
||||
},
|
||||
"main": "index.js",
|
||||
"type": "plugin",
|
||||
"mainExport": "main",
|
||||
"defaultConfig": [
|
||||
{
|
||||
"category": "default",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = (Plugin, { Logger, Settings, Modals, BdMenu: { BdMenuItems }, Api }) => class extends Plugin {
|
||||
exports.main = (Plugin, { Logger, Settings, Modals, BdMenu: { BdMenuItems }, Api }) => class extends Plugin {
|
||||
async onstart() {
|
||||
this.keybindEvent = this.keybindEvent.bind(this);
|
||||
|
||||
|
|
Loading…
Reference in New Issue