|
1 | | -(async () => { |
2 | | - |
3 | | - const URL = "ornithemc.net"; |
4 | | - const META = "meta." + URL; |
5 | | - const VERSION = "v3"; |
6 | | - |
7 | | - |
8 | | - function makeMetaUrl(...pathComponents) { |
9 | | - let url = META + "/" + VERSION; |
10 | | - for (const pathComponent of pathComponents) { |
11 | | - url += "/"; |
12 | | - url += pathComponent; |
13 | | - } |
14 | | - return "https://" + url; |
15 | | - } |
16 | | - |
17 | | - async function getFromMeta(...pathComponents) { |
18 | | - const response = await fetch(makeMetaUrl(...pathComponents)); |
19 | | - return response.json(); |
20 | | - } |
21 | | - |
22 | | - async function getMinecraftVersionsMeta() { |
23 | | - return await getFromMeta("versions", "game"); |
24 | | - } |
25 | | - |
26 | | - async function getFeatherVersionMeta(mcVersion) { |
27 | | - return await getFromMeta("versions", "feather", mcVersion); |
28 | | - } |
29 | | - |
30 | | - async function getRavenVersionMeta(mcVersion) { |
31 | | - return await getFromMeta("versions", "raven", mcVersion); |
32 | | - } |
33 | | - |
34 | | - async function getSparrowVersionMeta(mcVersion) { |
35 | | - return await getFromMeta("versions", "sparrow", mcVersion); |
36 | | - } |
37 | | - |
38 | | - async function getNestsVersionMeta(mcVersion) { |
39 | | - return await getFromMeta("versions", "nests", mcVersion); |
40 | | - } |
41 | | - |
42 | | - async function getLoaderVersionsMeta(loader) { |
43 | | - return await getFromMeta("versions", loader + "-loader"); |
44 | | - } |
45 | | - |
46 | | - async function getOslVersionsMeta() { |
47 | | - return await getFromMeta("versions", "osl"); |
48 | | - } |
49 | | - |
50 | | - function compareVersion(sv1, sv2) { |
51 | | - function rec(v1, v2) { |
52 | | - if (v1.length === 0 && v2.length === 0) return 0; |
53 | | - if (v1.length === 0) return 1; |
54 | | - if (v2.length === 0) return -1; |
55 | | - const [head1, ...tail1] = v1; |
56 | | - const [head2, ...tail2] = v2; |
57 | | - const ih1 = parseInt(head1); |
58 | | - const ih2 = parseInt(head2); |
59 | | - if (ih1 < ih2) return 1; |
60 | | - if (ih1 > ih2) return -1; |
61 | | - return rec(tail1, tail2); |
62 | | - } |
63 | | - |
64 | | - return rec(sv1.split("."), sv2.split(".")); |
65 | | - } |
66 | | - |
67 | | - async function getMinecraftVersions() { |
68 | | - return await getMinecraftVersionsMeta() |
69 | | - .then(l => l.map(v => v.version)); |
70 | | - } |
71 | | - |
72 | | - async function getMinecraftStableVersions() { |
73 | | - return await getMinecraftVersionsMeta() |
74 | | - .then(l => l.filter(v => v.stable)) |
75 | | - .then(l => l.map(v => v.version)); |
76 | | - } |
77 | | - |
78 | | - async function getLatestFeatherBuild(mcVersion) { |
79 | | - return await getFeatherVersionMeta(mcVersion) |
80 | | - .then(l => l.sort((e1, e2) => e2.build - e1.build)) |
81 | | - .then(s => { console.log(s); return s; }) |
82 | | - .then(([head, ..._]) => head) |
83 | | - .then(e => e !== undefined ? e.build : null); |
84 | | - } |
85 | | - |
86 | | - async function getLatestRavenBuild(mcVersion) { |
87 | | - return await getRavenVersionMeta(mcVersion) |
88 | | - .then(l => l.sort((e1, e2) => e2.build - e1.build)) |
89 | | - .then(([head, ..._]) => head) |
90 | | - .then(e => e !== undefined ? e.build : null); |
91 | | - } |
92 | | - |
93 | | - async function getLatestSparrowBuild(mcVersion) { |
94 | | - return await getSparrowVersionMeta(mcVersion) |
95 | | - .then(l => l.sort((e1, e2) => e2.build - e1.build)) |
96 | | - .then(([head, ..._]) => head) |
97 | | - .then(e => e !== undefined ? e.build : null); |
98 | | - } |
99 | | - |
100 | | - async function getLatestNestsBuild(mcVersion) { |
101 | | - return await getNestsVersionMeta(mcVersion) |
102 | | - .then(l => l.sort((e1, e2) => e2.build - e1.build)) |
103 | | - .then(([head, ..._]) => head) |
104 | | - .then(e => e !== undefined ? e.build : null); |
105 | | - } |
106 | | - |
107 | | - async function getLatestLoader(loader) { |
108 | | - return await getLoaderVersionsMeta(loader) |
109 | | - .then(l => l.filter(e => e.stable)) |
110 | | - .then(([head, ..._]) => head) |
111 | | - .then(e => e.version); |
112 | | - } |
113 | | - |
114 | | - async function getLatestOsl() { |
115 | | - return await getOslVersionsMeta() |
116 | | - .then(l => l.sort((e1, e2) => compareVersion(e1.version, e2.version))) |
117 | | - .then(([head, ..._]) => head) |
118 | | - .then(e => e.version); |
119 | | - } |
| 1 | +import { |
| 2 | + getMinecraftStableVersions, |
| 3 | + getMinecraftVersions, |
| 4 | + getLatestLoader, |
| 5 | + getLatestOsl, |
| 6 | + getLatestFeatherBuild, |
| 7 | + getLatestRavenBuild, |
| 8 | + getLatestSparrowBuild, |
| 9 | + getLatestNestsBuild |
| 10 | +} from "./meta_maven_utils.js"; |
120 | 11 |
|
| 12 | +(async () => { |
121 | 13 | const minecraftStableVersions = await getMinecraftStableVersions(); |
122 | 14 | const minecraftAllVersions = await getMinecraftVersions(); |
123 | 15 |
|
|
0 commit comments