feat(xo-server): load @xen-orchestra/server-* plugins

This commit is contained in:
Julien Fontanet
2020-06-01 16:05:54 +02:00
parent 34f42216c8
commit d4526e1ed2

View File

@@ -367,10 +367,7 @@ function registerPluginWrapper(pluginPath, pluginName) {
)
}
const PLUGIN_PREFIX = 'xo-server-'
const PLUGIN_PREFIX_LENGTH = PLUGIN_PREFIX.length
async function registerPluginsInPath(path) {
async function registerPluginsInPath(path, prefix) {
const files = await readdir(path).catch(error => {
if (error.code === 'ENOENT') {
return []
@@ -380,11 +377,11 @@ async function registerPluginsInPath(path) {
await Promise.all(
files.map(name => {
if (name.startsWith(PLUGIN_PREFIX)) {
if (name.startsWith(prefix)) {
return registerPluginWrapper.call(
this,
`${path}/${name}`,
name.slice(PLUGIN_PREFIX_LENGTH)
name.slice(prefix.length)
)
}
})
@@ -393,9 +390,11 @@ async function registerPluginsInPath(path) {
async function registerPlugins(xo) {
await Promise.all(
[`${__dirname}/../node_modules/`, '/usr/local/lib/node_modules/'].map(
registerPluginsInPath,
xo
[`${__dirname}/../node_modules`, `${__dirname}/../node_modules`].map(path =>
Promise.all([
registerPluginsInPath.call(xo, path, 'xo-server-'),
registerPluginsInPath.call(xo, `${path}/@xen-orchestra`, 'server-'),
])
)
)
}