2017-09-18 15:57:24 +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");
|
2020-08-21 11:26:35 +00:00
|
|
|
const semver = require("semver");
|
2017-09-18 15:57:24 +00:00
|
|
|
const program = require("commander");
|
|
|
|
const Helper = require("../helper");
|
|
|
|
const Utils = require("./utils");
|
|
|
|
|
|
|
|
program
|
|
|
|
.command("install <package>")
|
|
|
|
.description("Install a theme or a package")
|
|
|
|
.on("--help", Utils.extraHelp)
|
2020-03-21 20:55:36 +00:00
|
|
|
.action(function (packageName) {
|
2017-09-18 15:57:24 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
const packageJson = require("package-json");
|
|
|
|
|
2017-12-07 03:54:54 +00:00
|
|
|
if (!fs.existsSync(Helper.getConfigPath())) {
|
|
|
|
log.error(`${Helper.getConfigPath()} does not exist.`);
|
2017-09-18 15:57:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-27 08:05:34 +00:00
|
|
|
log.info("Retrieving information about the package...");
|
|
|
|
|
2018-03-07 03:40:21 +00:00
|
|
|
const split = packageName.split("@");
|
|
|
|
packageName = split[0];
|
|
|
|
const packageVersion = split[1] || "latest";
|
|
|
|
|
2017-09-18 15:57:24 +00:00
|
|
|
packageJson(packageName, {
|
2017-11-15 06:35:15 +00:00
|
|
|
fullMetadata: true,
|
2018-03-07 03:40:21 +00:00
|
|
|
version: packageVersion,
|
2019-07-17 09:33:59 +00:00
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
if (!("thelounge" in json)) {
|
|
|
|
log.error(
|
|
|
|
`${colors.red(
|
|
|
|
json.name + " v" + json.version
|
|
|
|
)} does not have The Lounge metadata.`
|
|
|
|
);
|
2017-09-18 15:57:24 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2017-09-18 15:57:24 +00:00
|
|
|
|
2020-08-21 11:26:35 +00:00
|
|
|
if (
|
|
|
|
json.thelounge.supports &&
|
|
|
|
!semver.satisfies(Helper.getVersionNumber(), json.thelounge.supports)
|
|
|
|
) {
|
|
|
|
log.error(
|
|
|
|
`${colors.red(
|
|
|
|
json.name + " v" + json.version
|
|
|
|
)} does not support The Lounge v${Helper.getVersionNumber()}. Supported version(s): ${
|
|
|
|
json.thelounge.supports
|
|
|
|
}`
|
|
|
|
);
|
|
|
|
|
|
|
|
process.exit(2);
|
|
|
|
}
|
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
log.info(`Installing ${colors.green(json.name + " v" + json.version)}...`);
|
2017-09-18 15:57:24 +00:00
|
|
|
|
2019-12-13 15:45:10 +00:00
|
|
|
return Utils.executeYarnCommand("add", "--exact", `${json.name}@${json.version}`)
|
2019-07-17 09:33:59 +00:00
|
|
|
.then(() => {
|
|
|
|
log.info(
|
|
|
|
`${colors.green(
|
|
|
|
json.name + " v" + json.version
|
|
|
|
)} has been successfully installed.`
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.catch((code) => {
|
|
|
|
throw `Failed to install ${colors.green(
|
|
|
|
json.name + " v" + json.version
|
|
|
|
)}. Exit code: ${code}`;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
log.error(`${e}`);
|
|
|
|
process.exit(1);
|
2017-09-18 15:57:24 +00:00
|
|
|
});
|
|
|
|
});
|