modified: package-lock.json

modified:   tools/pluginManager.js
This commit is contained in:
2024-11-02 00:38:57 -03:00
parent cab101fe3d
commit a4d10c5de9
2 changed files with 50 additions and 36 deletions

24
package-lock.json generated
View File

@@ -10,7 +10,8 @@
"license": "GPL-3.0-or-later",
"dependencies": {
"cli-color": "^2.0.4",
"nypm": "^0.3.12"
"nypm": "^0.3.12",
"ws": "^8.18.0"
}
},
"node_modules/acorn": {
@@ -482,6 +483,27 @@
"engines": {
"node": ">= 8"
}
},
"node_modules/ws": {
"version": "8.18.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
"integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
}
}

View File

@@ -13,44 +13,36 @@ module.exports = class pluginManager {
}
#scanPluginsFolder() {
try {
let pluginsFolder = fs.readdirSync(this.pluginsPath);
pluginsFolder.forEach((pluginFolder) => {
let filePath = path.join(this.pluginsPath, pluginFolder, "pluginData.json");
if (fs.existsSync(filePath)) {
let pluginData = JSON.parse(fs.readFileSync(filePath, 'utf8'));
this.#checkDependencies(pluginData);
this.#loadPlugin(path.join(this.pluginsPath, pluginFolder, pluginData.entrypoint), pluginData);
} else {
console.log(`No pluginData.json found for ${pluginFolder}`);
}
});
} catch (err) {
console.error('Unable to scan directory:', err);
process.exit(0);
}
let pluginsFolder = fs.readdirSync(this.pluginsPath);
pluginsFolder.forEach((pluginFolder) => {
let filePath = path.join(this.pluginsPath, pluginFolder, "pluginData.json");
if (fs.existsSync(filePath)) {
let pluginData = JSON.parse(fs.readFileSync(filePath, 'utf8'));
this.#checkDependencies(pluginData.dependencies);
//FIX THIS, needs to wait for dependencies and then ask for restart or wait for them to be installed before loading
this.#loadPlugin(path.join(this.pluginsPath, pluginFolder, pluginData.entrypoint), pluginData);
} else {
console.log(`No pluginData.json found for ${pluginFolder}`);
}
});
}
#checkDependencies(pluginData) {
if (pluginData.dependencies) {
for (const [key, value] of Object.entries(pluginData.dependencies)) {
console.log(`Checking for: ${key}@${value}`);
try {
nypm.ensureDependencyInstalled(`${key}`).then((result) => {
if (result) {
console.log(`${key}@${value} is already installed.`);
} else {
console.log(`Installing ${key}@${value}`);
nypm.addDependency(`${key}@${value}`);
nypm.installDependencies();
}
})
} catch (error) {
console.error(`Error ensuring dependency ${key}@${value}:`, error.message);
}
#checkDependencies(dependencies) {
for (const [key, value] of Object.entries(dependencies)) {
console.log(`Checking for: ${key}@${value}`);
try {
nypm.ensureDependencyInstalled(`${key}`).then((result) => {
if (result) {
console.log(`${key}@${value} is already installed.`);
} else {
console.log(`Installing ${key}@${value}`);
nypm.addDependency(`${key}@${value}`);
nypm.installDependencies();
}
})
} catch (error) {
console.error(`Error ensuring dependency ${key}@${value}:`, error.message);
}
} else {
console.log("No dependencies found for this plugin.");
}
}