Skip to content

Commit 531f47d

Browse files
zlataovceStrokkur424
authored andcommitted
refactor: build system dependency references
1 parent d01fffb commit 531f47d

File tree

24 files changed

+353
-275
lines changed

24 files changed

+353
-275
lines changed

CONTRIBUTING.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ To ensure a smooth and collaborative contribution process, please follow the gui
1212
5. [Version tags](#version-tags)
1313
6. [Automatic constant replacement](#automatic-constant-replacement)
1414
7. [Linking to Javadocs](#linking-to-javadocs)
15-
8. [Code of Conduct](#code-of-conduct)
15+
8. [Referencing a build system dependency](#referencing-a-build-system-dependency)
16+
9. [Code of Conduct](#code-of-conduct)
1617

1718
## Introduction
1819

@@ -181,6 +182,45 @@ For that, you can use the `jd:project_name[:module_name][:class_or_member_refere
181182
[java.sql's Connection](jd:java:java.sql:java.sql.Connection)
182183
```
183184

185+
## Referencing a build system dependency
186+
187+
If you wish to reference a build system (i.e. Gradle or Maven) dependency, you can use the `Dependency` component.
188+
189+
```mdxjs
190+
import { LATEST_ADVENTURE_API_RELEASE } from "/src/utils/versions";
191+
192+
{/* uses the "default" template */}
193+
<Dependency group="net.kyori" name="adventure-api" version={LATEST_ADVENTURE_API_RELEASE} />
194+
```
195+
196+
The `default` template is fit for use with a simple `implementation`/`compile`-scope dependency from Maven Central,
197+
however you can also make your own template.
198+
199+
If you need to declare the dependency in a unique way and/or need to add other configuration in the build script, simply use
200+
the `Tabs` component with the corresponding code blocks - **do not make a template unless you plan to use it more than once**.
201+
202+
```mdxjs
203+
import { Tabs, TabItem } from "@astrojs/starlight/components";
204+
205+
<Tabs syncKey="build-system">
206+
<TabItem label="Gradle (Kotlin)">
207+
```kotlin title="build.gradle.kts"
208+
// my awesome build script in Kotlin
209+
```
210+
</TabItem>
211+
<TabItem label="Gradle (Groovy)">
212+
```groovy title="build.gradle"
213+
// my awesome build script in Groovy
214+
```
215+
</TabItem>
216+
<TabItem label="Maven">
217+
```xml title="pom.xml"
218+
<!-- my awesome build script in XML -->
219+
```
220+
</TabItem>
221+
</Tabs>
222+
```
223+
184224
## Code of Conduct
185225

186226
Contributors are expected to follow the [Community Guidelines](https://papermc.io/community/guidelines) of the PaperMC organization in all

astro.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import d2 from "astro-d2";
44
import { defineConfig } from "astro/config";
55
import starlightLinksValidator from "starlight-links-validator";
66
import starlightSidebarTopics from "starlight-sidebar-topics";
7-
import miniMessageHighlight from "./src/assets/mm.tmLanguage.json";
87
import codeConstantsPlugin from "./src/utils/remark/code_const";
98
import javadocPlugin from "./src/utils/remark/javadoc";
9+
import miniMessageHighlight from "./src/utils/shiki/mm.tmLanguage.json";
1010
import {
11-
LATEST_ADVENTURE_ANSI_RELEASE,
1211
LATEST_ADVENTURE_API_RELEASE,
1312
LATEST_ADVENTURE_PLATFORM_MOD_RELEASE,
1413
LATEST_ADVENTURE_PLATFORM_RELEASE,
14+
LATEST_ANSI_RELEASE,
1515
LATEST_FOLIA_RELEASE,
1616
LATEST_MC_RELEASE,
1717
LATEST_PAPER_RELEASE,
@@ -553,7 +553,7 @@ export default defineConfig({
553553
LATEST_ADVENTURE_API_RELEASE,
554554
LATEST_ADVENTURE_PLATFORM_RELEASE,
555555
LATEST_ADVENTURE_PLATFORM_MOD_RELEASE,
556-
LATEST_ADVENTURE_ANSI_RELEASE,
556+
LATEST_ANSI_RELEASE,
557557
},
558558
},
559559
],

src/components/Dependency.astro

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
import { Code, TabItem, Tabs } from "@astrojs/starlight/components";
3+
import { LATEST_ADVENTURE_PLATFORM_MOD_RELEASE } from "../utils/versions";
4+
5+
type TemplateKey = "default" | "adventure-platform-mod";
6+
7+
interface Template {
8+
label: string;
9+
lang?: string;
10+
title?: string;
11+
code: string;
12+
}
13+
14+
const templates: Record<TemplateKey, Template[]> = {
15+
default: [
16+
{
17+
label: "Gradle (Kotlin)",
18+
lang: "kotlin",
19+
title: "build.gradle.kts",
20+
code: `repositories {
21+
mavenCentral()
22+
}
23+
24+
dependencies {
25+
implementation("\{GROUP}:\{NAME}:\{VERSION}")
26+
}`,
27+
},
28+
{
29+
label: "Gradle (Groovy)",
30+
lang: "groovy",
31+
title: "build.gradle",
32+
code: `repositories {
33+
mavenCentral()
34+
}
35+
36+
dependencies {
37+
implementation '\{GROUP}:\{NAME}:\{VERSION}'
38+
}`,
39+
},
40+
{
41+
label: "Maven",
42+
lang: "xml",
43+
title: "pom.xml",
44+
code: `<project>
45+
<dependencies>
46+
<dependency>
47+
<groupId>\{GROUP}</groupId>
48+
<artifactId>\{NAME}</artifactId>
49+
<version>\{VERSION}</version>
50+
</dependency>
51+
</dependencies>
52+
</project>`,
53+
},
54+
],
55+
"adventure-platform-mod": [
56+
{
57+
label: "Gradle (Kotlin)",
58+
lang: "kotlin",
59+
title: "build.gradle.kts",
60+
code: `repositories {
61+
// for development builds
62+
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/") {
63+
name = "sonatype-oss-snapshots1"
64+
mavenContent { snapshotsOnly() }
65+
}
66+
// for releases
67+
mavenCentral()
68+
}
69+
70+
dependencies {
71+
modImplementation(include("net.kyori:adventure-platform-\{NAME}:${LATEST_ADVENTURE_PLATFORM_MOD_RELEASE}")!!) // for Minecraft 1.21.5
72+
}`,
73+
},
74+
{
75+
label: "Gradle (Groovy)",
76+
lang: "groovy",
77+
title: "build.gradle",
78+
code: `repositories {
79+
// for development builds
80+
maven {
81+
name = 'sonatype-oss-snapshots1'
82+
url = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
83+
mavenContent { snapshotsOnly() }
84+
}
85+
// for releases
86+
mavenCentral()
87+
}
88+
89+
dependencies {
90+
modImplementation include('net.kyori:adventure-platform-\{NAME}:${LATEST_ADVENTURE_PLATFORM_MOD_RELEASE}') // for Minecraft 1.21.5
91+
}`,
92+
},
93+
],
94+
};
95+
96+
interface Props {
97+
group?: string;
98+
name?: string;
99+
version?: string;
100+
template?: TemplateKey;
101+
}
102+
103+
let { group = "", name = "", version = "", template } = Astro.props;
104+
template = template ?? "default";
105+
106+
const templateData = templates[template];
107+
if (!templateData) {
108+
throw new Error(`Template '${template}' not found`);
109+
}
110+
111+
const formatCode = (code: string): string => {
112+
return code.replaceAll("\{GROUP}", group).replaceAll("\{NAME}", name).replaceAll("\{VERSION}", version);
113+
};
114+
---
115+
116+
<Tabs syncKey="build-system">
117+
{
118+
templateData.map(({ label, lang, title, code }) => (
119+
<TabItem {label}>
120+
<Code {lang} {title} code={formatCode(code)} />
121+
</TabItem>
122+
))
123+
}
124+
</Tabs>

src/components/adventure/AdventureDependency.astro

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/components/adventure/ModPlatformDependency.astro

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)