2018-01-05 03:09:59 +01:00
|
|
|
"use strict";
|
|
|
|
|
2018-06-15 22:31:06 +02:00
|
|
|
const log = require("../log");
|
2018-03-02 19:28:54 +01:00
|
|
|
const colors = require("chalk");
|
2018-01-05 03:09:59 +01:00
|
|
|
const program = require("commander");
|
2022-05-01 21:12:39 +02:00
|
|
|
const Config = require("../config");
|
2018-01-05 03:09:59 +01:00
|
|
|
const Utils = require("./utils");
|
|
|
|
|
|
|
|
program
|
|
|
|
.command("uninstall <package>")
|
|
|
|
.description("Uninstall a theme or a package")
|
|
|
|
.on("--help", Utils.extraHelp)
|
2020-03-21 21:55:36 +01:00
|
|
|
.action(function (packageName) {
|
2018-01-05 03:09:59 +01:00
|
|
|
const fs = require("fs");
|
2019-12-24 10:31:17 +01:00
|
|
|
const path = require("path");
|
2018-01-05 03:09:59 +01:00
|
|
|
|
2022-05-01 21:12:39 +02:00
|
|
|
const packagesConfig = path.join(Config.getPackagesPath(), "package.json");
|
2020-02-27 18:21:01 +01:00
|
|
|
const packages = JSON.parse(fs.readFileSync(packagesConfig, "utf-8"));
|
2018-01-19 11:50:33 +01:00
|
|
|
|
2019-07-17 11:33:59 +02:00
|
|
|
if (
|
|
|
|
!packages.dependencies ||
|
|
|
|
!Object.prototype.hasOwnProperty.call(packages.dependencies, packageName)
|
|
|
|
) {
|
2019-12-24 10:31:17 +01:00
|
|
|
log.warn(`${colors.green(packageName)} is not installed.`);
|
2018-01-19 11:50:33 +01:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2018-02-20 08:28:04 +01:00
|
|
|
|
2019-12-24 10:31:17 +01:00
|
|
|
log.info(`Uninstalling ${colors.green(packageName)}...`);
|
|
|
|
|
2019-07-17 11:33:59 +02:00
|
|
|
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);
|
|
|
|
});
|
2018-01-05 03:09:59 +01:00
|
|
|
});
|