mirror of
https://github.com/peaceiris/actions-hugo.git
synced 2025-06-20 20:25:29 +08:00

- Support macOS and Windows (Close #24 ) - Refactoring - Error handling - TypeScript - Prettier (Close #29 ) - GHA: Add upload-artifact step for test coverage - deps: Install husky
20 lines
718 B
TypeScript
20 lines
718 B
TypeScript
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
|
|
|
|
export default function getLatestVersion(): Promise<string> {
|
|
return new Promise((resolve, reject) => {
|
|
const xhr = new XMLHttpRequest();
|
|
const url: string = '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: string = result.versions.stable;
|
|
resolve(latestVersion);
|
|
} else if (xhr.readyState === 4 && xhr.status !== 200) {
|
|
reject(`ERROR: got status ${xhr.status} of ${url}`);
|
|
}
|
|
};
|
|
});
|
|
}
|