refactor: move source codes to lib directory, Close #30

This commit is contained in:
peaceiris 2019-09-18 07:24:59 +09:00
parent 25a3456032
commit dda41c42cc
4 changed files with 3 additions and 3 deletions

21
lib/get-latest-version.js Normal file
View file

@ -0,0 +1,21 @@
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
function getLatestVersion() {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
const url = "https://formulae.brew.sh/api/formula/hugo.json";
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;
resolve(latestVersion);
} else if (xhr.readyState === 4 && xhr.status !== 200) {
reject(`ERROR: got status ${xhr.status} of ${url}`);
}
};
});
}
module.exports = getLatestVersion;