2018-01-05 02:09:59 +00:00
|
|
|
"use strict";
|
|
|
|
|
2018-06-15 20:31:06 +00:00
|
|
|
const log = require("../log");
|
2018-03-02 18:28:54 +00:00
|
|
|
const colors = require("chalk");
|
2018-01-05 02:09:59 +00:00
|
|
|
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");
|
2019-12-24 09:31:17 +00:00
|
|
|
const path = require("path");
|
2018-01-05 02:09:59 +00:00
|
|
|
|
2019-12-24 09:31:17 +00:00
|
|
|
const packagesConfig = path.join(Helper.getPackagesPath(), "package.json");
|
|
|
|
const packages = JSON.parse(fs.readFileSync(packagesConfig, "utf-8")).dependencies;
|
2018-01-19 10:50:33 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
if (
|
|
|
|
!packages.dependencies ||
|
|
|
|
!Object.prototype.hasOwnProperty.call(packages.dependencies, packageName)
|
|
|
|
) {
|
2019-12-24 09:31:17 +00:00
|
|
|
log.warn(`${colors.green(packageName)} is not installed.`);
|
2018-01-19 10:50:33 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2019-12-24 09:31:17 +00:00
|
|
|
log.info(`Uninstalling ${colors.green(packageName)}...`);
|
|
|
|
|
2019-07-17 09:33:59 +00: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 02:09:59 +00:00
|
|
|
});
|