2022-05-23 09:44:01 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2022-05-02 09:50:13 +02:00
|
|
|
import log from "../log";
|
|
|
|
import colors from "chalk";
|
|
|
|
import {Command} from "commander";
|
|
|
|
import Config from "../config";
|
|
|
|
import Utils from "./utils";
|
2018-04-29 09:47:39 +02:00
|
|
|
|
2022-05-03 03:32:20 +02:00
|
|
|
const program = new Command("upgrade");
|
2018-04-29 09:47:39 +02:00
|
|
|
program
|
2022-05-03 03:32:20 +02:00
|
|
|
.usage("upgrade [packages...]")
|
2022-05-31 22:44:54 +02:00
|
|
|
.arguments("[packages...]")
|
2020-03-15 12:53:09 +01:00
|
|
|
.description("Upgrade installed themes and packages to their latest versions")
|
2018-04-29 09:47:39 +02:00
|
|
|
.on("--help", Utils.extraHelp)
|
2020-03-21 21:55:36 +01:00
|
|
|
.action(function (packages) {
|
2018-04-29 09:47:39 +02:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
// Get paths to the location of packages directory
|
2022-05-01 21:12:39 +02:00
|
|
|
const packagesConfig = path.join(Config.getPackagesPath(), "package.json");
|
2020-01-01 00:11:04 +01:00
|
|
|
const packagesList = JSON.parse(fs.readFileSync(packagesConfig, "utf-8")).dependencies;
|
2019-12-13 16:45:10 +01:00
|
|
|
const argsList = ["upgrade", "--latest"];
|
2018-04-29 09:47:39 +02:00
|
|
|
|
|
|
|
let count = 0;
|
|
|
|
|
2019-12-24 10:31:17 +01:00
|
|
|
if (!Object.entries(packagesList).length) {
|
2018-04-29 09:47:39 +02:00
|
|
|
log.warn("There are no packages installed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a package names are supplied, check they exist
|
|
|
|
if (packages.length) {
|
|
|
|
log.info("Upgrading the following packages:");
|
|
|
|
packages.forEach((p) => {
|
|
|
|
log.info(`- ${colors.green(p)}`);
|
|
|
|
|
2019-06-25 10:51:47 +02:00
|
|
|
if (Object.prototype.hasOwnProperty.call(packagesList, p)) {
|
2019-01-16 11:51:52 +01:00
|
|
|
argsList.push(p);
|
2018-04-29 09:47:39 +02:00
|
|
|
count++;
|
|
|
|
} else {
|
|
|
|
log.error(`${colors.green(p)} is not installed.`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
log.info("Upgrading all packages...");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count === 0 && packages.length) {
|
|
|
|
log.warn("There are not any packages to upgrade.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-23 09:44:01 +02:00
|
|
|
const command = argsList.shift();
|
|
|
|
const params = argsList;
|
|
|
|
|
|
|
|
if (!command) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Utils.executeYarnCommand(command, ...params)
|
2019-07-17 11:33:59 +02:00
|
|
|
.then(() => {
|
|
|
|
log.info("Package(s) have been successfully upgraded.");
|
|
|
|
})
|
|
|
|
.catch((code) => {
|
2022-05-31 23:06:27 +02:00
|
|
|
log.error(`Failed to upgrade package(s). Exit code ${String(code)}`);
|
2019-12-24 10:31:17 +01:00
|
|
|
process.exit(1);
|
2019-07-17 11:33:59 +02:00
|
|
|
});
|
2018-04-29 09:47:39 +02:00
|
|
|
});
|
2022-05-03 03:32:20 +02:00
|
|
|
|
|
|
|
export default program;
|