d46d0aa12e
Refactoring * feat: Add reject to Promise * feat: Add printing inputs * feat: Add error handling to getLatestVersion() * feat: show version of Hugo, Go, and Git (Close #23) * refactor: Get the latest version from Homebrew (Close #26) * refactor: enhance error message of promise reject Enhancement for workflow * gha: Add deps (test-prod job needs test job) * gha: Fix matrix testing * gha: comment out Build production step * gha: remove Dump step Update README * docs: update readme
21 lines
706 B
JavaScript
21 lines
706 B
JavaScript
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;
|