thelounge/src/command-line/uninstall.js
Reto d4cc2dd361
Refactor config out of Helper (#4558)
* Remove config from Helper

Helper is the usual util grab bag of useful stuff.
Somehow the config ended up there historically but
structurally that doesn't make any sense.

* Add cert folder to prettier ignore file
2022-05-01 12:12:39 -07:00

39 lines
1.1 KiB
JavaScript

"use strict";
const log = require("../log");
const colors = require("chalk");
const program = require("commander");
const Config = require("../config");
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 path = require("path");
const packagesConfig = path.join(Config.getPackagesPath(), "package.json");
const packages = JSON.parse(fs.readFileSync(packagesConfig, "utf-8"));
if (
!packages.dependencies ||
!Object.prototype.hasOwnProperty.call(packages.dependencies, packageName)
) {
log.warn(`${colors.green(packageName)} is not installed.`);
process.exit(1);
}
log.info(`Uninstalling ${colors.green(packageName)}...`);
return Utils.executeYarnCommand("remove", packageName)
.then(() => {
log.info(`${colors.green(packageName)} has been successfully uninstalled.`);
})
.catch((code) => {
log.error(`Failed to uninstall ${colors.green(packageName)}. Exit code: ${code}`);
process.exit(1);
});
});