embed plugins
This commit is contained in:
@@ -84,32 +84,39 @@ const pluginController = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_loadPlugin (pluginFile) {
|
||||||
|
try {
|
||||||
|
const plugin = require(pluginFile)
|
||||||
|
const name = plugin.configuration.name
|
||||||
|
console.log(`Found plugin '${name}'`)
|
||||||
|
pluginController.plugins.push(plugin)
|
||||||
|
if (settingsController.settings['plugin_' + name]) {
|
||||||
|
const pluginSetting = settingsController.settings['plugin_' + name]
|
||||||
|
if (pluginSetting.enable) {
|
||||||
|
pluginController.loadPlugin(name)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
settingsController.set('plugin_' + name, { enable: false })
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.warn(`Unable to load plugin ${pluginFile}: ${String(e)}`)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_load() {
|
_load() {
|
||||||
// load custom plugins
|
// load custom plugins
|
||||||
const plugins_path = config.plugins_path || path.resolve(process.env.cwd || '', 'plugins')
|
const system_plugins_path = path.resolve(__dirname || '', '../../../gancio_plugins')
|
||||||
log.info(`Loading plugin ${plugins_path}`)
|
const custom_plugins_path = config.plugins_path || path.resolve(process.env.cwd || '', 'plugins')
|
||||||
if (fs.existsSync(plugins_path)) {
|
const plugins_paths = custom_plugins_path === system_plugins_path ? [custom_plugins_path] : [custom_plugins_path, system_plugins_path]
|
||||||
const plugins = fs.readdirSync(plugins_path)
|
|
||||||
.map(e => path.resolve(plugins_path, e, 'index.js'))
|
log.info(`Loading plugins from ${plugins_paths.join(' and ')}`)
|
||||||
.filter(index => fs.existsSync(index))
|
for (const plugins_path of plugins_paths) {
|
||||||
plugins.forEach(pluginFile => {
|
if (fs.existsSync(plugins_path)) {
|
||||||
try {
|
fs.readdirSync(plugins_path)
|
||||||
const plugin = require(pluginFile)
|
.map(e => path.resolve(plugins_path, e, 'index.js'))
|
||||||
const name = plugin.configuration.name
|
.filter(index => fs.existsSync(index))
|
||||||
console.log(`Found plugin '${name}'`)
|
.forEach(pluginController._loadPlugin)
|
||||||
pluginController.plugins.push(plugin)
|
}
|
||||||
if (settingsController.settings['plugin_' + name]) {
|
|
||||||
const pluginSetting = settingsController.settings['plugin_' + name]
|
|
||||||
if (pluginSetting.enable) {
|
|
||||||
pluginController.loadPlugin(name)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
settingsController.set('plugin_' + name, { enable: false })
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
log.warn(`Unable to load plugin ${pluginFile}: ${String(e)}`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user