This repository has been archived on 2025-07-07. You can view files and clone it, but cannot push or open issues/pull-requests.
dashy/services/update-checker.js

33 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

const axios = require('axios').default;
const currentVersion = require('../package.json').version;
const packageUrl = 'https://raw.githubusercontent.com/Lissy93/dashy/master/package.json';
const logToConsole = (msg) => {
console.log(msg); // eslint-disable-line no-console
};
const makeMsg = (latestVersion) => {
const parse = (version) => parseInt(version.replace(/\./g, ''), 10);
const difference = parse(latestVersion) - parse(currentVersion);
let msg = '';
if (difference <= 0) {
msg = '\x1b[1m\x1b[32m✅ Dashy is Up-to-Date\x1b[0m\n';
} else {
msg = `\x1b[103m\x1b[34m${new Array(27).fill('━').join('')}\x1b[0m\n`
+ `\x1b[103m\x1b[34m⚠ Update Available: ${latestVersion} \x1b[0m\n`
+ `\x1b[103m\x1b[34m${new Array(27).fill('━').join('')}\x1b[0m\n`;
}
return msg;
};
axios.get(packageUrl).then((response) => {
if (response && response.data && response.data.version) {
logToConsole(`\nUsing Dashy V-${currentVersion}. Update Check Complete`);
logToConsole(makeMsg(response.data.version));
}
}).catch(() => {
logToConsole('Unable to check for updates');
});