diff --git a/package.json b/package.json index 278b63283..ba6fb92af 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,8 @@ "postinstall": "node post-install.js", "lint": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js", "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": { "sillytavern": "./server.js" diff --git a/plugins.js b/plugins.js index 4615951c6..63d21778a 100644 --- a/plugins.js +++ b/plugins.js @@ -15,6 +15,12 @@ if (command === 'update') { updatePlugins(); } +if (command === 'install') { + const pluginName = process.argv[3]; + console.log('Installing a new plugin', color.green(pluginName)); + installPlugin(pluginName); +} + async function updatePlugins() { const directories = fs.readdirSync(pluginsPath) .filter(file => !file.startsWith('.')) @@ -51,3 +57,19 @@ async function updatePlugins() { 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); + } +}