Skip to content

Commit 085b546

Browse files
authored
feat: fetch userdev version dynamically (#492)
* Make userdev version be fetched dynamically * Git refused to commit my created file smh * Try fix format * pnpm format * Format fix version 3 * Move Userdev component into VersionFormattedCode and document in CONTRIBUTING.md * Move util method to util lfile * Cleanup * Remove redundant information * Remove request headers * Fix format * Add a newline * Add newline 2
1 parent 2a27a36 commit 085b546

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ of a few ways:
148148
%%_MAJ_MIN_PAT_MC_%% - Major-Minor-Patch Paper Version (E.g. 1.20.4)
149149
%%_MAJ_MIN_VEL_%% - Major Velocity Version (E.g. 3.1.0)
150150
%%_MAJ_MIN_PAT_VEL_%% - Major-Minor-Patch Velocity Version (E.g. 3.1.1-SNAPSHOT)
151+
%%_MAJ_MIN_PAT_USERDEV_%% - Latest Paperweight-Userdev Version (E.g. 1.7.3)
151152
````
152153

153154
When the major version of the software changes, the docs will still need to have a "snapshot" created to keep documentation

docs/paper/dev/getting-started/userdev.mdx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,13 @@ See [here](#1205-and-beyond) for more details.
3838
## Adding the plugin
3939
Add the plugin to your `build.gradle.kts` file.
4040

41-
:::info
42-
43-
You can find the latest release of **paperweight-userdev** on the [Gradle Plugin
44-
Portal](https://plugins.gradle.org/plugin/io.papermc.paperweight.userdev).
45-
46-
:::
47-
48-
```kotlin title="build.gradle.kts"
41+
<VersionFormattedCode language={"kotlin"} title={"build.gradle.kts"}>
42+
```
4943
plugins {
50-
id("io.papermc.paperweight.userdev") version "<insert_latest_version>"
44+
id("io.papermc.paperweight.userdev") version "%%_MAJ_MIN_PAT_USERDEV_%%"
5145
}
5246
```
47+
</VersionFormattedCode>
5348

5449
The latest version of `paperweight-userdev` supports dev bundles for Minecraft 1.17.1 and newer, so it's best practice to keep it up to date!
5550
Only the latest version of `paperweight-userdev` is officially supported, and we will ask you to update first if you are having problems with old versions.

src/components/versioning/VersionFormattedCode.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ export default function VersionFormattedCode({
4747
await getProjectVersion("velocity", versionMeta)
4848
);
4949

50+
code = code.replace(
51+
/%%_MAJ_MIN_PAT_USERDEV_%%/g,
52+
await getProjectVersion("userdev", versionMeta)
53+
);
54+
5055
if (mounted.current) {
5156
setFormattedCode({ code, inline });
5257
}

src/util/versionUtils.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ const createProjectVersionsValue = (
3535
});
3636
};
3737

38-
export type Project = "paper" | "velocity";
38+
const createUserdevVersionsValue = (ttl: number = 5 * 60 * 1000): ExpiringValue<string[]> => {
39+
return new ExpiringValue(ttl, async () => {
40+
const json = await fetch("https://api.github.com/repos/PaperMC/paperweight/tags").then((r) =>
41+
r.json()
42+
);
43+
44+
return json.map((e) => e.name.substring(1)).reverse();
45+
});
46+
};
47+
48+
export type Project = "paper" | "velocity" | "userdev";
3949

4050
export enum VersionType {
4151
Major,
@@ -48,6 +58,7 @@ export enum VersionType {
4858
const projects: Record<Project, ExpiringValue<string[]>> = {
4959
paper: createProjectVersionsValue("paper"),
5060
velocity: createProjectVersionsValue("velocity"),
61+
userdev: createUserdevVersionsValue(),
5162
};
5263

5364
export interface DocusaurusVersion {

0 commit comments

Comments
 (0)