Skip to content

Commit

Permalink
feat: fetch userdev version dynamically (#492)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Strokkur424 authored Oct 25, 2024
1 parent 2a27a36 commit 085b546
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
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
13 changes: 12 additions & 1 deletion src/util/versionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 +58,7 @@ export enum VersionType {
const projects: Record<Project, ExpiringValue<string[]>> = {
paper: createProjectVersionsValue("paper"),
velocity: createProjectVersionsValue("velocity"),
userdev: createUserdevVersionsValue(),
};

export interface DocusaurusVersion {
Expand Down

0 comments on commit 085b546

Please sign in to comment.