core: add hydrooj uninstall command

This commit is contained in:
undefined committed 2022-11-09 11:28:31 +08:00
1 parent d21ae767dd
commit bd1034eff8
3 files changed
+47 -29

No files matched your search

+17
View File
@@ -175,6 +175,23 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
lastUpdate: Date.now(),
}));
});
cli.command('uninstall [package]').action(async (name) => {
if (!name) {
cli.outputHelp();
return;
}
if (yarnVersion !== 1) throw new Error('Yarn 1 is required.');
const addonDir = path.join(hydroPath, 'addons');
fs.ensureDirSync(addonDir);
const plugins = fs.readdirSync(addonDir);
if (!plugins.includes(name)) {
throw new Error(`Plugin ${name} not found or not installed with \`hydrooj install\`.`);
}
const newAddonPath = path.join(addonDir, name);
child.execSync(`hydrooj addon remove '${newAddonPath}'`, { stdio: 'inherit' });
fs.removeSync(newAddonPath);
console.log(`Successfully uninstalled ${name}.`);
});
cli.help();
cli.parse();
if (!cli.matchedCommand) {