actions-hugo/lib/get-latest-version.js

22 lines
706 B
JavaScript
Raw Normal View History

2019-09-16 01:27:57 +02:00
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
function getLatestVersion() {
return new Promise((resolve, reject) => {
2019-09-16 01:27:57 +02:00
const xhr = new XMLHttpRequest();
const url = "https://formulae.brew.sh/api/formula/hugo.json";
2019-09-16 01:27:57 +02:00
xhr.open("GET", url);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
const result = JSON.parse(xhr.responseText);
const latestVersion = result.versions.stable;
2019-09-16 01:27:57 +02:00
resolve(latestVersion);
} else if (xhr.readyState === 4 && xhr.status !== 200) {
reject(`ERROR: got status ${xhr.status} of ${url}`);
2019-09-16 01:27:57 +02:00
}
};
});
}
module.exports = getLatestVersion;