Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make userdev version be fetched dynamically #492

Merged
merged 15 commits into from
Oct 25, 2024
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ of a few ways:
%%_MAJ_MIN_PAT_MC_%% - Major-Minor-Patch Paper Version (E.g. 1.20.4)
%%_MAJ_MIN_VEL_%% - Major Velocity Version (E.g. 3.1.0)
%%_MAJ_MIN_PAT_VEL_%% - Major-Minor-Patch Velocity Version (E.g. 3.1.1-SNAPSHOT)
%%_MAJ_MIN_PAT_USERDEV_%% - Latest Paperweight-Userdev Version (E.g. 1.7.3)
````

When the major version of the software changes, the docs will still need to have a "snapshot" created to keep documentation
Expand Down
13 changes: 4 additions & 9 deletions docs/paper/dev/getting-started/userdev.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,13 @@ See [here](#1205-and-beyond) for more details.
## Adding the plugin
Add the plugin to your `build.gradle.kts` file.

:::info

You can find the latest release of **paperweight-userdev** on the [Gradle Plugin
Portal](https://plugins.gradle.org/plugin/io.papermc.paperweight.userdev).

:::

```kotlin title="build.gradle.kts"
<VersionFormattedCode language={"kotlin"} title={"build.gradle.kts"}>
```
plugins {
id("io.papermc.paperweight.userdev") version "<insert_latest_version>"
id("io.papermc.paperweight.userdev") version "%%_MAJ_MIN_PAT_USERDEV_%%"
}
```
</VersionFormattedCode>

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!
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.
Expand Down
5 changes: 5 additions & 0 deletions src/components/versioning/VersionFormattedCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export default function VersionFormattedCode({
await getProjectVersion("velocity", versionMeta)
);

code = code.replace(
/%%_MAJ_MIN_PAT_USERDEV_%%/g,
await getProjectVersion("userdev", versionMeta)
);

if (mounted.current) {
setFormattedCode({ code, inline });
}
Expand Down
14 changes: 12 additions & 2 deletions src/util/versionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class ExpiringValue<T> {
return this._value;
}
}

zlataovce marked this conversation as resolved.
Show resolved Hide resolved
const createProjectVersionsValue = (
project: string,
ttl: number = 5 * 60 * 1000
Expand All @@ -35,7 +34,17 @@ const createProjectVersionsValue = (
});
};

export type Project = "paper" | "velocity";
const createUserdevVersionsValue = (ttl: number = 5 * 60 * 1000): ExpiringValue<string[]> => {
return new ExpiringValue(ttl, async () => {
const json = await fetch("https://api.github.com/repos/PaperMC/paperweight/tags").then((r) =>
r.json()
);

return json.map((e) => e.name.substring(1)).reverse();
});
};

export type Project = "paper" | "velocity" | "userdev";

export enum VersionType {
Major,
Expand All @@ -48,6 +57,7 @@ export enum VersionType {
const projects: Record<Project, ExpiringValue<string[]>> = {
paper: createProjectVersionsValue("paper"),
velocity: createProjectVersionsValue("velocity"),
userdev: createUserdevVersionsValue(),
};

export interface DocusaurusVersion {
Expand Down