Merge pull request #2760 from thelounge/mcinkay/plugins/show-updates

Add check for outdated packages, and show on the help screen.
This commit is contained in:
Pavel Djundik 2019-07-19 16:06:53 +03:00 committed by GitHub
commit fc532be5df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 99 additions and 5 deletions

View File

@ -1932,12 +1932,14 @@ part/quit messages where we don't load previews (adds a blank line otherwise) */
content: "\f253"; /* https://fontawesome.com/icons/hourglass-end?style=solid */ content: "\f253"; /* https://fontawesome.com/icons/hourglass-end?style=solid */
} }
#version-checker.new-version { #version-checker.new-version,
#version-checker.new-packages {
color: #8a6d3b; color: #8a6d3b;
background-color: #fcf8e3; background-color: #fcf8e3;
} }
#version-checker.new-version::before { #version-checker.new-version::before,
#version-checker.new-packages::before {
content: "\f164"; /* https://fontawesome.com/icons/thumbs-up?style=solid */ content: "\f164"; /* https://fontawesome.com/icons/thumbs-up?style=solid */
} }

View File

@ -29,6 +29,8 @@ socket.on("changelog", function(data) {
if (data.latest) { if (data.latest) {
status = "new-version"; status = "new-version";
} else if (data.packages) {
status = "new-packages";
} else if (data.current.changelog) { } else if (data.current.changelog) {
status = "up-to-date"; status = "up-to-date";
} else { } else {

View File

@ -12,6 +12,12 @@
Read more on GitHub Read more on GitHub
</a> </a>
</p> </p>
{{else equal status "new-packages"}}
<p>
The Lounge is up to date, but there are out of date packages
Run <code>thelounge upgrade</code> on the server to upgrade packages.
</p>
{{else equal status "up-to-date"}} {{else equal status "up-to-date"}}
<p> <p>
The Lounge is up to date! The Lounge is up to date!

View File

@ -60,6 +60,7 @@ if (!Helper.config.public && !Helper.config.ldap.enable) {
require("./install"); require("./install");
require("./uninstall"); require("./uninstall");
require("./upgrade"); require("./upgrade");
require("./outdated");
// `parse` expects to be passed `process.argv`, but we need to remove to give it // `parse` expects to be passed `process.argv`, but we need to remove to give it
// a version of `argv` that does not contain options already parsed by // a version of `argv` that does not contain options already parsed by

View File

@ -0,0 +1,27 @@
"use strict";
const program = require("commander");
const Utils = require("./utils");
const packageManager = require("../plugins/packages");
const log = require("../log");
program
.command("outdated")
.description("Check for any outdated packages")
.on("--help", Utils.extraHelp)
.action(async () => {
log.info("Checking for outdated packages");
await packageManager
.outdated(0)
.then((outdated) => {
if (outdated) {
log.info("There are outdated packages");
} else {
log.info("No outdated packages");
}
})
.catch(() => {
log.error("Error finding outdated packages.");
});
});

View File

@ -7,13 +7,22 @@ const Helper = require("../../helper");
const themes = require("./themes"); const themes = require("./themes");
const packageMap = new Map(); const packageMap = new Map();
const inputs = require("../inputs"); const inputs = require("../inputs");
const fs = require("fs");
const Utils = require("../../command-line/utils");
const stylesheets = []; const stylesheets = [];
const TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes, in milliseconds
const cache = {
outdated: undefined,
};
module.exports = { module.exports = {
getStylesheets, getStylesheets,
getPackage, getPackage,
loadPackages, loadPackages,
outdated,
}; };
const packageApis = function(packageName) { const packageApis = function(packageName) {
@ -99,3 +108,46 @@ function loadPackages() {
); );
} }
} }
async function outdated(cacheTimeout = TIME_TO_LIVE) {
if (cache.outdated !== undefined) {
return cache.outdated;
}
// Get paths to the location of packages directory
const packagesPath = Helper.getPackagesPath();
const packagesConfig = path.join(packagesPath, "package.json");
const argsList = [
"outdated",
"--latest",
"--json",
"--production",
"--ignore-scripts",
"--non-interactive",
"--cwd",
packagesPath,
];
// Check if the configuration file exists
if (!fs.existsSync(packagesConfig)) {
log.warn("There are no packages installed.");
return false;
}
// If we get an error from calling outdated and the code isn't 0, then there are no outdated packages
await Utils.executeYarnCommand(...argsList)
.then(() => updateOutdated(false))
.catch((code) => updateOutdated(code !== 0));
if (cacheTimeout > 0) {
setTimeout(() => {
delete cache.outdated;
}, cacheTimeout);
}
return cache.outdated;
}
function updateOutdated(outdatedPackages) {
cache.outdated = outdatedPackages;
}

View File

@ -454,9 +454,13 @@ function initializeClient(socket, client, token, lastMessage) {
} }
}); });
socket.on("changelog", async () => { socket.on("changelog", () => {
const data = await changelog.fetch(); Promise.all([changelog.fetch(), packages.outdated()]).then(
socket.emit("changelog", data); ([changelogData, packageUpdate]) => {
changelogData.packages = packageUpdate;
socket.emit("changelog", changelogData);
}
);
}); });
socket.on("msg:preview:toggle", (data) => { socket.on("msg:preview:toggle", (data) => {