Support for monorepo autodiscovery

This commit is contained in:
Danielv123 committed 2024-11-26 09:23:09 +00:00
1 parent 37fed2064e
commit 5dbfff9bfd
1 file changed
+24 -13
+24 -13
View File
@@ -20,6 +20,9 @@ async function findLocalPlugins(pluginList: Map<string, string>, pluginListPath:
]; ];
let has_changed = 0; let has_changed = 0;
const ignoredFolders = new Set(["node_modules", ".git", "dist", "build", "disabled"]);
const maxDepth = 3;
for (const pluginFolder of pluginFolders) { for (const pluginFolder of pluginFolders) {
let pluginNames; let pluginNames;
try { try {
@@ -32,28 +35,36 @@ async function findLocalPlugins(pluginList: Map<string, string>, pluginListPath:
throw err; throw err;
} }
for (const pluginName of pluginNames) { for (const pluginName of pluginNames) {
const pluginPath = path.resolve(pluginFolder, pluginName); const pluginPath = path.join(pluginFolder, pluginName);
if (pluginList.has(pluginName)) { if (pluginList.has(pluginName)) {
// If the one in the list is not the same as this one, warn // If the one in the list is not the same as this one, warn
if (pluginList.get(pluginName) !== pluginPath) { if (pluginList.get(pluginName) !== path.resolve(pluginPath)) {
logger.warn(`${pluginName} is already in the plugin list, but with a different path - using ${pluginList.get(pluginName)}`); logger.warn(`${pluginName} is already in the plugin list, but with a different path - using ${pluginList.get(pluginName)}`);
} }
continue; continue;
} }
const stats = await fs.stat(pluginPath); const stats = await fs.stat(pluginPath);
if (!stats.isDirectory()) { if (stats.isDirectory()) {
continue; // Check for package.json in current directory
} const packageJsonPath = path.join(pluginPath, "package.json");
if (await fs.exists(packageJsonPath)) {
// Read and parse package.json
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding: "utf8" }));
// Check that the plugin has a package.json file // Check if package has the clusterio-plugin keyword
const packageJsonPath = path.resolve(pluginPath, "package.json"); if (packageJson.keywords?.includes("clusterio-plugin")) {
if (!(await fs.exists(packageJsonPath))) { pluginList.set(pluginName, path.resolve(pluginPath));
continue; logger.info(`Added ${pluginName} from ${pluginFolder}`);
} has_changed += 1;
continue;
}
}
pluginList.set(pluginName, pluginPath); if (pluginPath.split(path.sep).length < maxDepth && !ignoredFolders.has(pluginName)) {
logger.info(`Added ${pluginName} from ${pluginFolder}`); logger.warn(`Possible monorepo detected, scanning ${pluginPath} for clusterio-plugins`);
has_changed += 1; pluginFolders.push(pluginPath);
}
}
} }
} }