Add a thelounge uninstall command to remove themes and packages

This commit is contained in:
Jérémie Astori 2018-01-04 21:09:59 -05:00
parent 52b3ef18f7
commit d9cb640c2a
No known key found for this signature in database
GPG key ID: B9A4F245CD67BDE8
2 changed files with 54 additions and 0 deletions

View file

@ -65,6 +65,7 @@ if (!Helper.config.public && !Helper.config.ldap.enable) {
require("./users");
}
require("./install");
require("./uninstall");
// TODO: Remove this when releasing The Lounge v3
if (process.argv[1].endsWith(`${require("path").sep}lounge`)) {

View file

@ -0,0 +1,53 @@
"use strict";
const colors = require("colors/safe");
const path = require("path");
const program = require("commander");
const Helper = require("../helper");
const Utils = require("./utils");
program
.command("uninstall <package>")
.description("Uninstall a theme or a package")
.on("--help", Utils.extraHelp)
.action(function(packageName) {
const fs = require("fs");
const child = require("child_process");
if (!fs.existsSync(Helper.getConfigPath())) {
log.error(`${Helper.getConfigPath()} does not exist.`);
return;
}
log.info(`Uninstalling ${colors.green(packageName)}...`);
const packagesPath = Helper.getPackagesPath();
const packagesParent = path.dirname(packagesPath);
const npm = child.spawn(
process.platform === "win32" ? "npm.cmd" : "npm",
[
"uninstall",
"--prefix",
packagesParent,
packageName,
],
{
stdio: "inherit",
}
);
npm.on("error", (e) => {
log.error(`${e}`);
process.exit(1);
});
npm.on("close", (code) => {
if (code !== 0) {
log.error(`Failed to uninstall ${colors.green(packageName)}. Exit code: ${code}`);
return;
}
log.info(`${colors.green(packageName)} has been successfully uninstalled.`);
});
});