Skip to content

Commit 586b73a

Browse files
committed
feat: scrape changesets (beta)
1 parent 0a701fb commit 586b73a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { JSDOM } from 'jsdom';
33
import { UnityChangeset } from './unityChangeset';
44

55
const UNITY_ARCHIVE_URL = 'https://unity3d.com/get-unity/download/archive';
6+
const UNITY_BETA_URL = 'https://unity3d.com/beta';
67

78
const getDocumentFromUrl = async (archiveUrl: RequestInfo) => {
89
const response = await fetch(archiveUrl);
@@ -46,3 +47,38 @@ export const scrapeArchivedChangesets = async (): Promise<UnityChangeset[]> => {
4647
.filter(href => UnityChangeset.isValid(href))
4748
.map(href => UnityChangeset.createFromHref(href));
4849
};
50+
51+
export const scrapeBetaChangesets = async (): Promise<UnityChangeset[]> => {
52+
const document = await getDocumentFromUrl(UNITY_BETA_URL);
53+
54+
const betas = new Set<string>();
55+
Array.from(document.querySelectorAll('a[href]'))
56+
.map((a) => a.getAttribute('href') as string)
57+
.filter((href) => /^\/(alpha|beta)\/\d{4}\.\d(a|b)$/.test(href))
58+
.forEach((href) => betas.add(href));
59+
60+
const downloads = new Set<string>();
61+
for (const beta of betas) {
62+
// [beta page] e.g. 'https://unity3d.com/beta/2020.2b'
63+
const betaPage = await getDocumentFromUrl(`https://unity3d.com${beta}`);
64+
Array.from(betaPage.querySelectorAll('a[href]'))
65+
.map((a) => a.getAttribute('href') as string)
66+
// [filter] e.g. '/unity/beta/2020.2.0b13'
67+
.filter((href) => /^\/unity\/(alpha|beta)\/\d{4}\.\d+\.\d+(a|b)\d+$/.test(href))
68+
.forEach((href) => downloads.add(href));
69+
}
70+
71+
const hrefs = new Set<string>();
72+
for (const download of downloads) {
73+
// [download page] e.g. https://unity3d.com/unity/beta/2020.2.0b13
74+
const downloadPage = await getDocumentFromUrl(`https://unity3d.com${download}`);
75+
Array.from(downloadPage.querySelectorAll('a[href]'))
76+
.map((a) => a.getAttribute('href') as string)
77+
// [filter] e.g. 'unityhub://2020.2.0b13/655e1a328b90'
78+
.filter((href) => UnityChangeset.isValid(href))
79+
.forEach((href) => hrefs.add(href));
80+
}
81+
82+
return Array.from(hrefs)
83+
.map(href => UnityChangeset.createFromHref(href));
84+
};

0 commit comments

Comments
 (0)