mirror of
https://github.com/thelounge/thelounge.git
synced 2024-05-10 18:26:53 +02:00
3971ecff63
- Hides progress bars that flash when installing/uninstalling as it does not bring real value here, at least for now - Inform user if package being uninstalled was not actually installed - Do not display npm outputs, mention which version was installed (this will probably need refining when installing packages with dependencies)
87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
"use strict";
|
|
|
|
const colors = require("colors/safe");
|
|
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)
|
|
.action(function(packageName) {
|
|
const fs = require("fs");
|
|
const fsextra = require("fs-extra");
|
|
const path = require("path");
|
|
const child = require("child_process");
|
|
const packageJson = require("package-json");
|
|
|
|
if (!fs.existsSync(Helper.getConfigPath())) {
|
|
log.error(`${Helper.getConfigPath()} does not exist.`);
|
|
return;
|
|
}
|
|
|
|
log.info("Retrieving information about the package...");
|
|
|
|
packageJson(packageName, {
|
|
fullMetadata: true,
|
|
}).then((json) => {
|
|
if (!("thelounge" in json)) {
|
|
log.error(`${colors.red(packageName)} does not have The Lounge metadata.`);
|
|
|
|
process.exit(1);
|
|
}
|
|
|
|
log.info(`Installing ${colors.green(packageName)}...`);
|
|
|
|
const packagesPath = Helper.getPackagesPath();
|
|
const packagesParent = path.dirname(packagesPath);
|
|
const packagesConfig = path.join(packagesParent, "package.json");
|
|
|
|
// Create node_modules folder, otherwise npm will start walking upwards to find one
|
|
fsextra.ensureDirSync(packagesPath);
|
|
|
|
// Create package.json with private set to true to avoid npm warnings
|
|
fs.writeFileSync(packagesConfig, JSON.stringify({
|
|
private: true,
|
|
description: "Packages for The Lounge. All packages in node_modules directory will be automatically loaded.",
|
|
}, null, "\t"));
|
|
|
|
const npm = child.spawn(
|
|
process.platform === "win32" ? "npm.cmd" : "npm",
|
|
[
|
|
"install",
|
|
"--production",
|
|
"--no-save",
|
|
"--no-bin-links",
|
|
"--no-package-lock",
|
|
"--no-progress",
|
|
"--prefix",
|
|
packagesParent,
|
|
packageName,
|
|
],
|
|
{
|
|
// This is the same as `"inherit"` except `process.stdout` is ignored
|
|
stdio: [process.stdin, "ignore", process.stderr],
|
|
}
|
|
);
|
|
|
|
npm.on("error", (e) => {
|
|
log.error(`${e}`);
|
|
process.exit(1);
|
|
});
|
|
|
|
npm.on("close", (code) => {
|
|
if (code !== 0) {
|
|
log.error(`Failed to install ${colors.green(packageName)}. Exit code: ${code}`);
|
|
return;
|
|
}
|
|
|
|
log.info(`${colors.green(packageName + " v" + json.version)} has been successfully installed.`);
|
|
});
|
|
}).catch((e) => {
|
|
log.error(`${e}`);
|
|
process.exit(1);
|
|
});
|
|
});
|