mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
implement server plugin system
This commit is contained in:
74
server/plugin-system/discovery.js
Normal file
74
server/plugin-system/discovery.js
Normal file
@@ -0,0 +1,74 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
function discoverPlugins(pluginsDir) {
|
||||
const discovered = new Map();
|
||||
|
||||
let entries;
|
||||
|
||||
try {
|
||||
entries = fs.readdirSync(pluginsDir, { withFileTypes: true });
|
||||
} catch {
|
||||
return discovered;
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
if (!entry.isDirectory() || entry.name.startsWith(".")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const pluginPath = path.join(pluginsDir, entry.name);
|
||||
const indexPath = path.join(pluginPath, "index.js");
|
||||
|
||||
if (!fs.existsSync(indexPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let plugin;
|
||||
|
||||
try {
|
||||
plugin = require(indexPath);
|
||||
} catch (e) {
|
||||
console.warn(`[plugins] Failed to load ${entry.name}: ${e.message}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!plugin.id || !plugin.name || typeof plugin.register !== "function") {
|
||||
console.warn(
|
||||
`[plugins] Skipping ${entry.name}: missing id, name, or register`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
let bundledPluginId = null;
|
||||
|
||||
if (plugin.obsidianPlugin) {
|
||||
try {
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(
|
||||
path.join(plugin.obsidianPlugin, "manifest.json"),
|
||||
"utf-8",
|
||||
),
|
||||
);
|
||||
bundledPluginId = manifest.id;
|
||||
} catch {
|
||||
// No valid bundled plugin manifest
|
||||
}
|
||||
}
|
||||
|
||||
discovered.set(plugin.id, {
|
||||
id: plugin.id,
|
||||
name: plugin.name,
|
||||
description: plugin.description || "",
|
||||
obsidianPlugin: plugin.obsidianPlugin || null,
|
||||
bundledPluginId,
|
||||
module: plugin,
|
||||
});
|
||||
|
||||
console.log(`[plugins] Discovered: ${plugin.name}`);
|
||||
}
|
||||
|
||||
return discovered;
|
||||
}
|
||||
|
||||
module.exports = { discoverPlugins };
|
||||
Reference in New Issue
Block a user