Skip to content

Commit 7754086

Browse files
committed
Add/improve dynamic mod version fetching
1 parent a245370 commit 7754086

File tree

7 files changed

+73
-98
lines changed

7 files changed

+73
-98
lines changed

astro.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import javadocPlugin from "./src/utils/remark/javadoc";
1010
import {
1111
LATEST_ADVENTURE_ANSI_RELEASE,
1212
LATEST_ADVENTURE_API_RELEASE,
13+
LATEST_ADVENTURE_PLATFORM_MOD_RELEASE,
1314
LATEST_ADVENTURE_PLATFORM_RELEASE,
1415
LATEST_MC_RELEASE,
1516
LATEST_PAPER_RELEASE,
@@ -520,6 +521,7 @@ export default defineConfig({
520521
LATEST_USERDEV_RELEASE,
521522
LATEST_ADVENTURE_API_RELEASE,
522523
LATEST_ADVENTURE_PLATFORM_RELEASE,
524+
LATEST_ADVENTURE_PLATFORM_MOD_RELEASE,
523525
LATEST_ADVENTURE_ANSI_RELEASE,
524526
},
525527
},
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
import { Tabs, TabItem, Code } from "@astrojs/starlight/components";
3+
import { LATEST_ADVENTURE_PLATFORM_MOD_RELEASE } from "/src/utils/versions";
4+
5+
interface Props {
6+
platform: string;
7+
}
8+
9+
const props: Props = Astro.props;
10+
const mavenCoords = `net.kyori:adventure-platform-${props.platform}:${LATEST_ADVENTURE_PLATFORM_MOD_RELEASE}`;
11+
12+
const groovy = `
13+
repositories {
14+
// for development builds
15+
maven {
16+
name = "sonatype-oss-snapshots1"
17+
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
18+
mavenContent { snapshotsOnly() }
19+
}
20+
// for releases
21+
mavenCentral()
22+
}
23+
24+
dependencies {
25+
modImplementation include("${mavenCoords}") // for Minecraft 1.21.5
26+
}
27+
`;
28+
29+
const kotlin = `
30+
repositories {
31+
// for development builds
32+
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/") {
33+
name = "sonatype-oss-snapshots1"
34+
mavenContent { snapshotsOnly() }
35+
}
36+
// for releases
37+
mavenCentral()
38+
}
39+
40+
dependencies {
41+
modImplementation(include("${mavenCoords}")!!) // for Minecraft 1.21.5
42+
}
43+
`;
44+
---
45+
46+
<Tabs syncKey="build-system">
47+
<TabItem label="Gradle (Groovy)">
48+
<Code lang="groovy" code={groovy} />
49+
</TabItem>
50+
<TabItem label="Gradle (Kotlin)">
51+
<Code lang="kotlin" code={kotlin} />
52+
</TabItem>
53+
</Tabs>

src/content/docs/adventure/platform/fabric.mdx

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Fabric
33
description: The Fabric Adventure implementation.
44
---
55

6-
import { Tabs, TabItem } from "@astrojs/starlight/components"
6+
import ModPlatformDependency from "/src/components/adventure/ModPlatformDependency.astro";
77

88
Adventure supports Fabric on *Minecraft: Java Edition* 1.16 and up, for both server-side and client-side use. Each major version of Minecraft
99
will usually require a new release of the platform.
@@ -25,44 +25,7 @@ Starting with Minecraft 1.21.2, both platforms have version 6.x published.
2525
The Fabric platform is packaged as a mod, designed to be included in mods via jar-in-jar packaging.
2626
As with the rest of the Adventure projects, releases are distributed on Maven Central, and snapshots on Sonatype OSS:
2727

28-
// TODO: Make this a component + insert version placeholder
29-
<Tabs syncKey="build-system">
30-
<TabItem label="Gradle (Groovy)">
31-
```groovy
32-
repositories {
33-
// for development builds
34-
maven {
35-
name = "sonatype-oss-snapshots1"
36-
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
37-
mavenContent { snapshotsOnly() }
38-
}
39-
// for releases
40-
mavenCentral()
41-
}
42-
43-
dependencies {
44-
modImplementation include("net.kyori:adventure-platform-fabric:|mod_version|") // for Minecraft 1.21.5
45-
}
46-
```
47-
</TabItem>
48-
<TabItem label="Gradle (Kotlin)">
49-
```kts
50-
repositories {
51-
// for development builds
52-
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/") {
53-
name = "sonatype-oss-snapshots1"
54-
mavenContent { snapshotsOnly() }
55-
}
56-
// for releases
57-
mavenCentral()
58-
}
59-
60-
dependencies {
61-
modImplementation(include("net.kyori:adventure-platform-fabric:|modversion|")!!) // for Minecraft 1.21.5
62-
}
63-
```
64-
</TabItem>
65-
</Tabs>
28+
<ModPlatformDependency platform="fabric" />
6629

6730
The Fabric platform requires *fabric-api-base* in order to provide the locale change event, *fabric-command-api-v2* for the callback click event,
6831
and can optionally use [Colonel](https://gitlab.com/stellardrift/colonel) (or *fabric-networking-api-v1*) to allow the `Component` and `Key` argument

src/content/docs/adventure/platform/modded.mdx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ then you don't need to use this artifact explicitly. This is because both platfo
2424

2525
As with the rest of the Adventure projects, releases are distributed on Maven Central, and snapshots on Sonatype OSS:
2626

27-
// TODO: Make this a component + insert version placeholder
2827
<Tabs syncKey="build-system">
2928
<TabItem label="Gradle (Groovy)">
30-
```groovy
29+
```groovy replace
3130
repositories {
3231
// for development builds
3332
maven {
@@ -41,15 +40,15 @@ As with the rest of the Adventure projects, releases are distributed on Maven Ce
4140
4241
dependencies {
4342
// Loom project
44-
modCompileOnly("net.kyori:adventure-platform-mod-shared-fabric-repack:|mod_version|") // for Minecraft 1.21.5
43+
modCompileOnly("net.kyori:adventure-platform-mod-shared-fabric-repack:\{LATEST_ADVENTURE_PLATFORM_MOD_RELEASE}") // for Minecraft 1.21.5
4544
4645
// NeoGradle/ModDevGradle/VanillaGradle project
47-
compileOnly("net.kyori:adventure-platform-mod-shared:|mod_version|") // for Minecraft 1.21.5
46+
compileOnly("net.kyori:adventure-platform-mod-shared:\{LATEST_ADVENTURE_PLATFORM_MOD_RELEASE}") // for Minecraft 1.21.5
4847
}
4948
```
5049
</TabItem>
5150
<TabItem label="Gradle (Kotlin)">
52-
```kts
51+
```kts replace
5352
repositories {
5453
// for development builds
5554
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/") {
@@ -62,10 +61,10 @@ As with the rest of the Adventure projects, releases are distributed on Maven Ce
6261

6362
dependencies {
6463
// Loom project
65-
modCompileOnly("net.kyori:adventure-platform-mod-shared-fabric-repack:|mod_version|") // for Minecraft 1.21.5
64+
modCompileOnly("net.kyori:adventure-platform-mod-shared-fabric-repack:\{LATEST_ADVENTURE_PLATFORM_MOD_RELEASE}") // for Minecraft 1.21.5
6665

6766
// NeoGradle/ModDevGradle/VanillaGradle project
68-
compileOnly("net.kyori:adventure-platform-mod-shared:|mod_version|") // for Minecraft 1.21.5
67+
compileOnly("net.kyori:adventure-platform-mod-shared:\{LATEST_ADVENTURE_PLATFORM_MOD_RELEASE}") // for Minecraft 1.21.5
6968
}
7069
```
7170
</TabItem>

src/content/docs/adventure/platform/neoforge.mdx

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: NeoForge
33
description: The NeoForge Adventure implementation.
44
---
55

6-
import { Tabs, TabItem } from "@astrojs/starlight/components"
6+
import ModPlatformDependency from "/src/components/adventure/ModPlatformDependency.astro";
77

88
Adventure supports NeoForge on *Minecraft: Java Edition* 1.21 and up, for both server-side and client-side use. Each major version of Minecraft will usually require
99
a new release of the platform.
@@ -15,44 +15,7 @@ The platform supports all features, including localization and custom renderers.
1515
The NeoForge platform is packaged as a mod, designed to be included in mods via jar-in-jar packaging. As with the rest of the Adventure projects,
1616
releases are distributed on Maven Central, and snapshots on Sonatype OSS:
1717

18-
// TODO: Make this a component + insert version placeholder
19-
<Tabs syncKey="build-system">
20-
<TabItem label="Gradle (Groovy)">
21-
```groovy
22-
repositories {
23-
// for development builds
24-
maven {
25-
name = "sonatype-oss-snapshots1"
26-
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
27-
mavenContent { snapshotsOnly() }
28-
}
29-
// for releases
30-
mavenCentral()
31-
}
32-
33-
dependencies {
34-
implementation jarJar("net.kyori:adventure-platform-neoforge:|mod_version|") // for Minecraft 1.21.5
35-
}
36-
```
37-
</TabItem>
38-
<TabItem label="Gradle (Kotlin)">
39-
```kts
40-
repositories {
41-
// for development builds
42-
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/") {
43-
name = "sonatype-oss-snapshots1"
44-
mavenContent { snapshotsOnly() }
45-
}
46-
// for releases
47-
mavenCentral()
48-
}
49-
50-
dependencies {
51-
implementation(jarJar("net.kyori:adventure-platform-neoforge:|mod_version|")!!) // for Minecraft 1.21.5
52-
}
53-
```
54-
</TabItem>
55-
</Tabs>
18+
<ModPlatformDependency platform="neoforge" />
5619

5720
:::danger[Attention]
5821

src/utils/releases.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ interface Release {
44
published: string;
55
url: string;
66
tag: string;
7+
tag_name: string;
78
}
89

910
const token = process.env.GITHUB_TOKEN;
@@ -43,6 +44,7 @@ export async function fetchRelease(repo: string): Promise<Release[]> {
4344
published: obj.published_at ?? "2000-01-01",
4445
url: obj.html_url ?? "about:blank",
4546
tag: obj.tag_name?.replaceAll(".", "-") ?? "none",
47+
tag_name: obj.tag_name ?? "v1.0.0"
4648
};
4749
})
4850
// Post-processing
@@ -78,19 +80,7 @@ function handleRegex(obj: Release, regex: RegExp, onMatch: (match: string) => st
7880
}
7981

8082
const alreadyMatched: string[] = [];
81-
let result = obj.body.matchAll(regex);
82-
if (result == null) {
83-
console.warn("Result of match was null.");
84-
return;
85-
}
86-
87-
console.info(result);
88-
if (result.map == null) {
89-
console.warn("Yeah it cannot find the map method");
90-
return;
91-
}
92-
93-
result
83+
obj.body.matchAll(regex)
9484
.map((match) => match[0])
9585
.forEach((match) => {
9686
if (alreadyMatched.find((e) => e == match) != null) {

src/utils/versions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ const adventurePlatformVersions: string[] = await fetchGitHubTags("KyoriPowered/
6767

6868
export const LATEST_ADVENTURE_PLATFORM_RELEASE = adventurePlatformVersions[0];
6969

70+
const adventurePlatformModVersions: string[] = await fetchGitHubTags("KyoriPowered/adventure-platform-mod");
71+
72+
export const LATEST_ADVENTURE_PLATFORM_MOD_RELEASE = adventurePlatformModVersions[0];
73+
7074
const adventureAnsiVersions: string[] = await fetchGitHubTags("KyoriPowered/ansi");
7175

7276
export const LATEST_ADVENTURE_ANSI_RELEASE = adventureAnsiVersions[0];
@@ -79,5 +83,6 @@ export const LATEST_RELEASES: Record<string, string> = {
7983
userdev: LATEST_USERDEV_RELEASE,
8084
"adventure-api": LATEST_ADVENTURE_API_RELEASE,
8185
"adventure-platform": LATEST_ADVENTURE_PLATFORM_RELEASE,
86+
"adventure-platform-mod": LATEST_ADVENTURE_PLATFORM_MOD_RELEASE,
8287
"adventure-ansi": LATEST_ADVENTURE_ANSI_RELEASE,
8388
};

0 commit comments

Comments
 (0)