2018-04-29 07:47:39 +00:00
|
|
|
"use strict";
|
|
|
|
|
2018-06-15 20:31:06 +00:00
|
|
|
const log = require("../log");
|
2018-04-29 07:47:39 +00:00
|
|
|
const colors = require("chalk");
|
|
|
|
const program = require("commander");
|
|
|
|
const Helper = require("../helper");
|
|
|
|
const Utils = require("./utils");
|
|
|
|
|
|
|
|
program
|
|
|
|
.command("upgrade [packages...]")
|
2020-03-15 11:53:09 +00:00
|
|
|
.description("Upgrade installed themes and packages to their latest versions")
|
2018-04-29 07:47:39 +00:00
|
|
|
.on("--help", Utils.extraHelp)
|
|
|
|
.action(function(packages) {
|
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
// Get paths to the location of packages directory
|
2019-12-24 09:31:17 +00:00
|
|
|
const packagesConfig = path.join(Helper.getPackagesPath(), "package.json");
|
2019-12-31 23:11:04 +00:00
|
|
|
const packagesList = JSON.parse(fs.readFileSync(packagesConfig, "utf-8")).dependencies;
|
2019-12-13 15:45:10 +00:00
|
|
|
const argsList = ["upgrade", "--latest"];
|
2018-04-29 07:47:39 +00:00
|
|
|
|
|
|
|
let count = 0;
|
|
|
|
|
2019-12-24 09:31:17 +00:00
|
|
|
if (!Object.entries(packagesList).length) {
|
2018-04-29 07:47:39 +00: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 08:51:47 +00:00
|
|
|
if (Object.prototype.hasOwnProperty.call(packagesList, p)) {
|
2019-01-16 10:51:52 +00:00
|
|
|
argsList.push(p);
|
2018-04-29 07:47:39 +00: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;
|
|
|
|
}
|
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
return Utils.executeYarnCommand(...argsList)
|
|
|
|
.then(() => {
|
|
|
|
log.info("Package(s) have been successfully upgraded.");
|
|
|
|
})
|
|
|
|
.catch((code) => {
|
2019-12-24 09:31:17 +00:00
|
|
|
log.error(`Failed to upgrade package(s). Exit code ${code}`);
|
|
|
|
process.exit(1);
|
2019-07-17 09:33:59 +00:00
|
|
|
});
|
2018-04-29 07:47:39 +00:00
|
|
|
});
|