Add update checker function!

This commit is contained in:
Sophie Marie 2023-01-22 17:32:26 -06:00
parent 3713ba9cf2
commit 2c45f65a39
No known key found for this signature in database
GPG Key ID: 0C9FB786E7770775
1 changed files with 20 additions and 0 deletions

20
functions/updateCheck.js Normal file
View File

@ -0,0 +1,20 @@
/* eslint-disable brace-style */ // Tell eslint to stfu :)
const fetch = require('node-fetch');
const config = require('../config.json');
module.exports = () => {
const repo = `https://api.github.com/repos/${config.gitRepo}/releases/latest`;
fetch(repo).then(async (response) => {
response = await response.json();
const latest = response.name;
const currentVer = config.build;
let status = 0; // 0 = Up-to-date, 1 = New update.
if (currentVer === latest) { status = 0; } // Anitrox is up to date
else if (currentVer < latest) { status = 1; } // Anitrox is not up to date
else if (currentVer > latest) { status = 0; } // Anitrox is ahead, Treat this as it being up to date.
if (status === 1) console.log(`\n✨ It must be your lucky day! Anitrox ${latest} is now available! Download it from github.com/${config.gitRepo}/releases!`); // Log to console about the new release!
});
};