Add install to plugin manager script

This commit is contained in:
Cohee
2024-05-13 21:22:01 +03:00
parent fd18e0cc78
commit 28da838bd1
2 changed files with 24 additions and 1 deletions

View File

@ -75,7 +75,8 @@
"postinstall": "node post-install.js", "postinstall": "node post-install.js",
"lint": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js", "lint": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js",
"lint:fix": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js --fix", "lint:fix": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js --fix",
"plugins:update": "node plugins update" "plugins:update": "node plugins update",
"plugins:install": "node plugins install"
}, },
"bin": { "bin": {
"sillytavern": "./server.js" "sillytavern": "./server.js"

View File

@ -15,6 +15,12 @@ if (command === 'update') {
updatePlugins(); updatePlugins();
} }
if (command === 'install') {
const pluginName = process.argv[3];
console.log('Installing a new plugin', color.green(pluginName));
installPlugin(pluginName);
}
async function updatePlugins() { async function updatePlugins() {
const directories = fs.readdirSync(pluginsPath) const directories = fs.readdirSync(pluginsPath)
.filter(file => !file.startsWith('.')) .filter(file => !file.startsWith('.'))
@ -51,3 +57,19 @@ async function updatePlugins() {
console.log(color.magenta('All plugins updated!')); console.log(color.magenta('All plugins updated!'));
} }
async function installPlugin(pluginName) {
try {
const pluginPath = path.join(pluginsPath, path.basename(pluginName, '.git'));
if (fs.existsSync(pluginPath)) {
return console.log(color.yellow(`Directory already exists at ${pluginPath}`));
}
await git().clone(pluginName, pluginPath, { '--depth': 1 });
console.log(`Plugin ${color.green(pluginName)} installed to ${color.cyan(pluginPath)}`);
}
catch (error) {
console.error(color.red(`Failed to install plugin ${pluginName}`), error);
}
}