Skip to content

Commit

Permalink
Update smart buildscripts for Blabber and Impersonate
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 17, 2024
1 parent 100f834 commit 60a763b
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 45 deletions.
8 changes: 7 additions & 1 deletion jekyll_plugins/TabbedBuildscriptTag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Ladysnake
# instructions for a specific format
#
# Usage:
# "{%- buildscript dependencies={key1: value1, key2: value2} -%}
# "{%- buildscript [key1:value1], [key2:value2] -%}
# [build.gradle]
# Instructions for Groovy build.gradle
#
Expand All @@ -14,6 +14,10 @@ module Ladysnake
# [catalogue]
# Instructions for `libs.versions.toml`
# {%- endbuildscript -%}"
#
# By default, only the Minecraft versions relevant to the first mod in the list
# will be shown. You can add the show_all_versions parameter to the tag to make it
# so every Minecraft version that has at least one mod version for it gets displayed.
class TabbedBuildScriptTag < Liquid::Block
def initialize(tag_name, text, tokens)
super
Expand All @@ -24,11 +28,13 @@ def render(context)
body = super
mods = Hash[@input.scan(/\[(\w+):(\w+)\]/)]
tabs = Hash[TabbedTag.parse_tabs(body)]
show_all_versions = @input.include? "show_all_versions"

context["groovy"] = tabs["groovy"]
context["kts"] = tabs["kts"]
context["catalogue"] = tabs["catalogue"]
context["mods"] = mods
context["show_all_versions"] = show_all_versions

include = "{% include tabbed_buildscript.liquid mods=mods groovy=groovy kts=kts catalogue=catalogue %}"

Expand Down
4 changes: 2 additions & 2 deletions public/_includes/tabbed_buildscript.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<option>Loading...</option>
</select>
</fieldset>
{% if include.mods['cca'] %}
{% if include.mods['cca'] and include.mods.size == 1 %}
<fieldset class="smart-buildscript-controls" hidden="hidden">
<legend>Select a module:</legend>
<label>
Expand Down Expand Up @@ -62,7 +62,7 @@
{% endif %}
<script type="module">
import {setUpSmartBuildscript} from "/scripts/smart-buildscript.js";
setUpSmartBuildscript({ {% for mod in mods %}{{ mod[0] }}: '{{ mod[1] }}'{% unless forloop.last %}, {% endunless %}{% endfor %} });
setUpSmartBuildscript({ {% for mod in mods %}{{ mod[0] }}: '{{ mod[1] }}'{% unless forloop.last %}, {% endunless %}{% endfor %} }, {{ include.show_all_versions }});
</script>
{% endif %}
{{ result }}
13 changes: 8 additions & 5 deletions public/scripts/smart-buildscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ function pickDefaultVersion(versions) {
/**
*
* @param {[ModRef, Map<string, {mcVersion: McVersion, modVersions: ModVersion[]}>][]} projectVersions an array of pairs of mod name to available versions
* @param {string|undefined} primaryMod
* @return {Map<string, McIndexedVersion>}
*/
function indexVersions(projectVersions) {
function indexVersions(projectVersions, primaryMod) {
/** @type {Map<string, McIndexedVersion>} */
const result = new Map();
for (const [mod, versions] of projectVersions) {
Expand All @@ -36,7 +37,7 @@ function indexVersions(projectVersions) {
result.get(mcVersionId).modVersions.set(mod, modVersions);
}
}
return new Map([...result].sort(compareMcVersions));
return new Map([...result].filter(([_, v]) => primaryMod == null || v.modVersions.has(primaryMod)).sort(compareMcVersions));
}

function doReplaceVersion(modName, version = 'VERSION') {
Expand All @@ -59,11 +60,12 @@ function doReplaceCcaModule(module) {

/**
* @param {string} modName
* @param {string} modVersion
* @param {string|undefined} modVersion
* @returns {string}
*/
function getMavenGroup(modName, modVersion) {
if (modName === 'cca') {
if (modVersion == null) return 'io.github.onyxstudios';
const major = modVersion.split('.')[0];
if (major < 4) {
return '`see table below`';
Expand Down Expand Up @@ -124,9 +126,10 @@ function updateVersionSelects(projectVersions, mods) {

/**
* @param {Record<string, string>} modrinthProjectIds
* @param {boolean|undefined} showAllVersions if false, only the MC version relevant to the first mod in modrinthProjectIds will be displayed
* @returns {Promise<void>}
*/
export async function setUpSmartBuildscript(modrinthProjectIds) {
export async function setUpSmartBuildscript(modrinthProjectIds, showAllVersions) {
for (let controls of document.getElementsByClassName('smart-buildscript-controls')) {
controls.hidden = null;
for (let radio of controls.querySelectorAll('input[name=cca-module-picker]')) {
Expand All @@ -139,7 +142,7 @@ export async function setUpSmartBuildscript(modrinthProjectIds) {
([mod, modrinthProjectId]) =>
getVersions(modrinthProjectId).then((v) => [mod, v])
)
));
), showAllVersions ? undefined : mods[0]);

for (const versionSelect of document.getElementsByClassName('mc-version-select')) {
versionSelect.addEventListener('change', () => {
Expand Down
2 changes: 1 addition & 1 deletion public/tools/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ trinkets_version = <TRINKETS_VERSION>
```
{% endcapture %}

{%- buildscript
{%- buildscript show_all_versions
[blabber:2oRMVFgd],
[cca:K01OU20C],
[cloth:9s6osm5g],
Expand Down
39 changes: 14 additions & 25 deletions public/wiki/blabber/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,12 @@ video.

## Using Blabber (for developers)

If you are a developer, you can use Blabber as a library for your own project by inserting the following in your `build.gradle` :
If you are a developer, you can use Blabber as a library for your own project by inserting the following in your buildscript :

You can then add the library version to your `gradle.properties`file:

{%- buildscript %}
{%- buildscript [blabber:2oRMVFgd], [cca:K01OU20C] %}
[- groovy -]
Add the library version to your `gradle.properties`file:

`gradle.properties`:
```properties
# Blabber
Expand All @@ -546,11 +546,6 @@ repositories {
maven {
name = "Ladysnake Mods"
url = "https://maven.ladysnake.org/releases"
content {
includeGroup 'io.github.ladysnake'
includeGroup 'org.ladysnake'
includeGroupByRegex 'dev\\.onyxstudios.*'
}
}
maven {
name = "Nexus Repository Manager"
Expand All @@ -563,12 +558,14 @@ dependencies {
include "org.ladysnake:blabber:${blabber_version}"
// Blabber dependencies
include "me.lucko:fabric-permissions-api:${fpa_version}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${cca_version}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${cca_version}"
include "<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-base:${cca_version}"
include "<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-entity:${cca_version}"
}
```

[- kts -]
Add the library version to your `gradle.properties`file:

`gradle.properties`:
```properties
# Blabber
Expand All @@ -585,11 +582,6 @@ repositories {
maven {
name = "Ladysnake Mods"
url = "https://maven.ladysnake.org/releases"
content {
includeGroup("io.github.ladysnake")
includeGroup("org.ladysnake")
includeGroupByRegex("""dev\.onyxstudios.*""")
}
}
maven {
name = "Nexus Repository Manager"
Expand All @@ -605,12 +597,14 @@ dependencies {
include("org.ladysnake:blabber:${blabber_version}")
// Blabber dependencies
include("me.lucko:fabric-permissions-api:${fpa_version}")
include("dev.onyxstudios.cardinal-components-api:cardinal-components-base:${cca_version}")
include("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${cca_version}")
include("<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-base:${cca_version}")
include("<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-entity:${cca_version}")
}
```

[- catalogue -]
Add the library to your `libs.versions.toml`file:

`libs.versions.toml`:
```toml
[versions]
Expand All @@ -619,8 +613,8 @@ cardinalComponentsApi = '<CCA_VERSION>'
fabricPermissionsApi = '0.2-SNAPSHOT'

[libraries]
cca-base = { module = "dev.onyxstudios.cardinal-components-api:cardinal-components-base", version.ref = "cardinalComponentsApi" }
cca-entity = { module = "dev.onyxstudios.cardinal-components-api:cardinal-components-entity", version.ref = "cardinalComponentsApi" }
cca-base = { module = "<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-base", version.ref = "cardinalComponentsApi" }
cca-entity = { module = "<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-entity", version.ref = "cardinalComponentsApi" }
fpa = { module = "me.lucko:fabric-permissions-api", version.ref = "fabricPermissionsApi" }
blabber = { module = "org.ladysnake:blabber", version.ref = "blabber" }

Expand All @@ -634,11 +628,6 @@ repositories {
maven {
name = "Ladysnake Mods"
url = "https://maven.ladysnake.org/releases"
content {
includeGroup("io.github.ladysnake")
includeGroup("org.ladysnake")
includeGroupByRegex("""dev.onyxstudios.*""")
}
}
maven {
name = "Nexus Repository Manager"
Expand Down
84 changes: 73 additions & 11 deletions public/wiki/impersonate.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,22 @@ If you are a developer, you can use Impersonate as a library for your own projec

{%- buildscript [impersonate:xBZuWXoj], [cca:K01OU20C] -%}
[- groovy -]
`gradle.properties`
```properties
# Impersonate
impersonate_version = <IMPERSONATE_VERSION>
# Fabric Permissions API
fpa_version = 0.2-SNAPSHOT
# Cardinal Components
cca_version = <CCA_VERSION>
```

`build.gradle`
```gradle
repositories {
maven {
name = "Ladysnake Mods"
url = "https://maven.ladysnake.org/releases"
content {
includeGroupByRegex 'org\\.ladysnake.*'
includeGroupByRegex 'io\\.github\\.onyxstudios.*'
}
}
maven {
name = "Nexus Repository Manager"
Expand All @@ -72,13 +79,13 @@ dependencies {
include "org.ladysnake:impersonate:${impersonate_version}"
// Impersonate dependencies
include "me.lucko:fabric-permissions-api:${fpa_version}"
include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:${cca_version}"
include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-entity:${cca_version}"
include "<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-base:${cca_version}"
include "<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-entity:${cca_version}"
}
```

You can then add the library version to your `gradle.properties`file:

[- kts -]
`gradle.properties`
```properties
# Impersonate
impersonate_version = <IMPERSONATE_VERSION>
Expand All @@ -88,12 +95,67 @@ fpa_version = 0.2-SNAPSHOT
cca_version = <CCA_VERSION>
```

[- kts -]
{% include wip.liquid message="*For now, take a look at the groovy build.gradle tab*" %}
`build.gradle.kts`
```gradle
repositories {
maven {
name = "Ladysnake Mods"
url = "https://maven.ladysnake.org/releases"
}
maven {
name = "Nexus Repository Manager"
url = 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
dependencies {
modImplementation("org.ladysnake:impersonate:${impersonate_version}")
include("org.ladysnake:impersonate:${impersonate_version}")
// Impersonate dependencies
include("me.lucko:fabric-permissions-api:${fpa_version}")
include("<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-base:${cca_version}")
include("<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-entity:${cca_version}")
}
```

[- catalogue -]
{% include wip.liquid message="*For now, take a look at the groovy build.gradle tab*" %}
`libs.versions.toml`:
```toml
[versions]
impersonate = '<IMPERSONATE_VERSION>'
cardinalComponentsApi = '<CCA_VERSION>'
fabricPermissionsApi = '0.2-SNAPSHOT'

[libraries]
cca-base = { module = "<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-base", version.ref = "cardinalComponentsApi" }
cca-entity = { module = "<CCA_MAVEN_GROUP>.cardinal-components-api:cardinal-components-entity", version.ref = "cardinalComponentsApi" }
fpa = { module = "me.lucko:fabric-permissions-api", version.ref = "fabricPermissionsApi" }
impersonate = { module = "org.ladysnake:impersonate", version.ref = "impersonate" }

[bundles]
impersonate = [ "cca-base", "cca-entity", "fpa", "impersonate" ]
```

`build.gradle` or `build.gradle.kts`:
```kotlin
repositories {
maven {
name = "Ladysnake Mods"
url = "https://maven.ladysnake.org/releases"
}
maven {
name = "Nexus Repository Manager"
url = "https://oss.sonatype.org/content/repositories/snapshots"
}
}

dependencies {
// Replace modImplementation with modApi if you expose Impersonate's interfaces in your own API
modImplementation(libs.bundles.impersonate)
// Includes Impersonate and its dependencies as a Jar-in-Jar dependency (optional but recommended)
include(libs.bundles.impersonate)
}
```
{% endbuildscript %}

You can find the current version of Impersonate in the [releases](https://github.com/Ladysnake/Impersonate/releases) tab of the repository on Github,
Expand Down

0 comments on commit 60a763b

Please sign in to comment.