2019-09-16 01:27:57 +02:00
|
|
|
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
|
|
|
|
|
|
|
function getLatestVersion() {
|
2019-09-17 21:11:47 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2019-09-16 01:27:57 +02:00
|
|
|
const xhr = new XMLHttpRequest();
|
2019-09-17 21:11:47 +02:00
|
|
|
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);
|
2019-09-17 21:11:47 +02:00
|
|
|
const latestVersion = result.versions.stable;
|
2019-09-16 01:27:57 +02:00
|
|
|
resolve(latestVersion);
|
2019-09-17 21:11:47 +02:00
|
|
|
} 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;
|