1
0
Fork 0

feat(core): Added support for conditional plugins

This commit is contained in:
Joost De Cock 2020-09-12 19:01:12 +02:00
parent 3aeefc3748
commit 72c2a6c9e7
2 changed files with 26 additions and 2 deletions

View file

@ -397,6 +397,23 @@ Pattern.prototype.use = function (plugin, data) {
return this
}
Pattern.prototype.useIf = function (plugin, settings) {
if (plugin.condition(settings)) {
if (this.debug)
this.raise.debug(
`Condition met: Loaded plugin \`${plugin.plugin.name}:${plugin.plugin.version}\``
)
this.loadPluginHooks(plugin.plugin, plugin.data)
} else {
if (this.debug)
this.raise.debug(
`Condition not met: Skipped loading plugin \`${plugin.plugin.name}:${plugin.plugin.version}\``
)
}
return this
}
Pattern.prototype.loadPluginHooks = function (plugin, data) {
for (let hook of Object.keys(this.hooks)) {
if (typeof plugin.hooks[hook] === 'function') {