From 085b546fe8f64580909fd5da9ee7ef3abb03d186 Mon Sep 17 00:00:00 2001 From: Strokkur24 <133226102+Strokkur424@users.noreply.github.com> Date: Fri, 25 Oct 2024 22:52:08 +0200 Subject: [PATCH] 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 --- CONTRIBUTING.md | 1 + docs/paper/dev/getting-started/userdev.mdx | 13 ++++--------- src/components/versioning/VersionFormattedCode.tsx | 5 +++++ src/util/versionUtils.ts | 13 ++++++++++++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b898dafc3..4ca76e6a0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/docs/paper/dev/getting-started/userdev.mdx b/docs/paper/dev/getting-started/userdev.mdx index bc90ab12c..87e42331e 100644 --- a/docs/paper/dev/getting-started/userdev.mdx +++ b/docs/paper/dev/getting-started/userdev.mdx @@ -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" + +``` plugins { - id("io.papermc.paperweight.userdev") version "" + id("io.papermc.paperweight.userdev") version "%%_MAJ_MIN_PAT_USERDEV_%%" } ``` + 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. diff --git a/src/components/versioning/VersionFormattedCode.tsx b/src/components/versioning/VersionFormattedCode.tsx index 222fbf12f..cfa3ea95b 100644 --- a/src/components/versioning/VersionFormattedCode.tsx +++ b/src/components/versioning/VersionFormattedCode.tsx @@ -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 }); } diff --git a/src/util/versionUtils.ts b/src/util/versionUtils.ts index ff8029178..2e5c5337a 100644 --- a/src/util/versionUtils.ts +++ b/src/util/versionUtils.ts @@ -35,7 +35,17 @@ const createProjectVersionsValue = ( }); }; -export type Project = "paper" | "velocity"; +const createUserdevVersionsValue = (ttl: number = 5 * 60 * 1000): ExpiringValue => { + 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, @@ -48,6 +58,7 @@ export enum VersionType { const projects: Record> = { paper: createProjectVersionsValue("paper"), velocity: createProjectVersionsValue("velocity"), + userdev: createUserdevVersionsValue(), }; export interface DocusaurusVersion {