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 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");
|
|
|
|
|
|
|
|
if (!fs.existsSync(Helper.getConfigPath())) {
|
|
|
|
log.error(`${Helper.getConfigPath()} does not exist.`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info(`Uninstalling ${colors.green(packageName)}...`);
|
|
|
|
|
|
|
|
const packagesPath = Helper.getPackagesPath();
|
2018-02-08 05:19:44 +00:00
|
|
|
const packagesConfig = path.join(packagesPath, "package.json");
|
2018-01-06 06:34:41 +00:00
|
|
|
const packageWasNotInstalled = `${colors.green(packageName)} was not installed.`;
|
|
|
|
|
|
|
|
if (!fs.existsSync(packagesConfig)) {
|
|
|
|
log.warn(packageWasNotInstalled);
|
2018-01-13 07:00:37 +00:00
|
|
|
process.exit(1);
|
2018-01-06 06:34:41 +00:00
|
|
|
}
|
2018-01-05 02:09:59 +00:00
|
|
|
|
2018-01-19 10:50:33 +00:00
|
|
|
const packages = JSON.parse(fs.readFileSync(packagesConfig, "utf-8"));
|
|
|
|
|
2019-06-25 08:51:47 +00:00
|
|
|
if (!packages.dependencies || !Object.prototype.hasOwnProperty.call(packages.dependencies, packageName)) {
|
2018-01-19 10:50:33 +00:00
|
|
|
log.warn(packageWasNotInstalled);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2018-04-24 18:38:54 +00:00
|
|
|
return Utils.executeYarnCommand(
|
|
|
|
"remove",
|
|
|
|
packageName
|
|
|
|
).then(() => {
|
2018-01-19 10:50:33 +00:00
|
|
|
log.info(`${colors.green(packageName)} has been successfully uninstalled.`);
|
2018-04-24 18:38:54 +00:00
|
|
|
}).catch((code) => {
|
|
|
|
log.error(`Failed to uninstall ${colors.green(packageName)}. Exit code: ${code}`);
|
|
|
|
process.exit(1);
|
2018-01-05 02:09:59 +00:00
|
|
|
});
|
|
|
|
});
|