mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add install to plugin manager script
This commit is contained in:
@ -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"
|
||||||
|
22
plugins.js
22
plugins.js
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user