Add jsdoc, reduce logging

This commit is contained in:
Danielv123 committed 2024-11-25 18:07:51 +00:00
1 parent 397dc6a5a6
commit 472177bf39
1 file changed
+17 -6
+17 -6
View File
@@ -4,7 +4,12 @@ import { logger } from "./logging";
import * as libFileOps from "./file_ops"; import * as libFileOps from "./file_ops";
/** /**
* Find local plugins to add to the plugin list. This is primarily used during development. * Searches for local plugins in the plugins/ and external_plugins/ directories
* and adds them to the plugin list if they contain a package.json file.
*
* @param pluginList - Map of plugin names to their file paths
* @param pluginListPath - Path to the JSON file storing the plugin list
* @returns Promise that resolves when plugin discovery is complete
*/ */
async function findLocalPlugins(pluginList: Map<string, string>, pluginListPath: string) { async function findLocalPlugins(pluginList: Map<string, string>, pluginListPath: string) {
// Check folders for plugins // Check folders for plugins
@@ -31,11 +36,10 @@ async function findLocalPlugins(pluginList: Map<string, string>, pluginListPath:
if (!(await fs.exists(packageJsonPath))) { if (!(await fs.exists(packageJsonPath))) {
continue; continue;
} }
console.log(`Adding ${pluginName} from ${pluginFolder}`);
pluginList.set(pluginName, pluginPath); pluginList.set(pluginName, pluginPath);
logger.info(`Added ${pluginName} from ${pluginFolder}`); logger.info(`Added ${pluginName} from ${pluginFolder}`);
has_changed++; has_changed += 1;
} }
} }
@@ -46,15 +50,21 @@ async function findLocalPlugins(pluginList: Map<string, string>, pluginListPath:
/** /**
* Find NPM packages in the root package.json that satisfies the requirements for plugins. * Find NPM packages in the root package.json that satisfies the requirements for plugins.
*
* @param pluginList - Map of plugin names to their file paths
* @param pluginListPath - Path to the JSON file storing the plugin list
* @returns Promise that resolves when plugin discovery is complete
*/ */
async function findNpmPlugins(pluginList: Map<string, string>, pluginListPath: string) { async function findNpmPlugins(pluginList: Map<string, string>, pluginListPath: string) {
const rootPackageJson = JSON.parse(await fs.readFile(path.resolve(process.cwd(), "package.json"), { encoding: "utf8" })); const rootPackageJson = JSON.parse(await fs.readFile(path.resolve(
process.cwd(),
"package.json",
), { encoding: "utf8" }));
const dependencies = rootPackageJson.dependencies; const dependencies = rootPackageJson.dependencies;
let changed = 0; let changed = 0;
for (const [pluginName, pluginVersion] of Object.entries(dependencies)) { for (const [pluginName, pluginVersion] of Object.entries(dependencies)) {
if (pluginList.has(pluginName)) { if (pluginList.has(pluginName)) {
console.log(`${pluginName} already exists`);
continue; continue;
} }
// Find the package in node_modules and read the package.json // Find the package in node_modules and read the package.json
@@ -62,10 +72,11 @@ async function findNpmPlugins(pluginList: Map<string, string>, pluginListPath: s
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding: "utf8" })); const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding: "utf8" }));
// Check if the package has the "clusterio-plugin" keyword // Check if the package has the "clusterio-plugin" keyword
if (packageJson.keywords?.includes("clusterio-plugin")) { if (packageJson.keywords?.includes("clusterio-plugin")) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pluginInfo = require(path.resolve(process.cwd(), "node_modules", pluginName)).plugin; const pluginInfo = require(path.resolve(process.cwd(), "node_modules", pluginName)).plugin;
pluginList.set(pluginInfo.name, pluginName); pluginList.set(pluginInfo.name, pluginName);
logger.info(`Added ${pluginInfo.name} from NPM`); logger.info(`Added ${pluginInfo.name} from NPM`);
changed++; changed += 1;
} else { } else {
logger.info(`${pluginName}@${pluginVersion} is not a clusterio-plugin`); logger.info(`${pluginName}@${pluginVersion} is not a clusterio-plugin`);
} }