2019-09-15 20:54:38 +02:00
|
|
|
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
|
|
|
|
2019-09-15 20:43:48 +02:00
|
|
|
function getLatestVersion() {
|
2019-09-16 01:04:23 +02:00
|
|
|
// return new Promise((resolve, reject) => {
|
|
|
|
return new Promise(resolve => {
|
2019-09-15 20:43:48 +02:00
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
const url = "https://api.github.com/repos/gohugoio/hugo/releases/latest";
|
|
|
|
xhr.open("GET", url);
|
|
|
|
xhr.send();
|
2019-09-15 20:16:06 +02:00
|
|
|
|
2019-09-15 20:43:48 +02:00
|
|
|
xhr.onreadystatechange = function() {
|
|
|
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
|
|
const result = JSON.parse(xhr.responseText);
|
|
|
|
const latestURL = result["assets"][0].browser_download_url;
|
|
|
|
const latestVersion = latestURL.match(/(\d+).(\d+).(\d+)/g)[0];
|
2019-09-15 20:16:06 +02:00
|
|
|
|
2019-09-15 20:43:48 +02:00
|
|
|
resolve(latestVersion);
|
2019-09-16 01:04:23 +02:00
|
|
|
// } else {
|
|
|
|
// reject(`ERROR: got status ${xhr.status}`);
|
2019-09-15 20:43:48 +02:00
|
|
|
}
|
|
|
|
};
|
2019-09-15 20:16:06 +02:00
|
|
|
});
|
2019-09-15 20:43:48 +02:00
|
|
|
}
|
2019-09-15 20:16:06 +02:00
|
|
|
|
|
|
|
module.exports = getLatestVersion;
|