Skip to content

Commit 4ceb15e

Browse files
committed
Add compile-all.sh and versions.json for multi-version builds
1 parent be83bb1 commit 4ceb15e

2 files changed

Lines changed: 150 additions & 0 deletions

File tree

compile-all.sh

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/bin/bash
2+
3+
# Multi-version build script
4+
# Builds all Minecraft versions defined in versions.json
5+
# Usage: ./compile-all.sh [-c] [-w] [-n] [--dry-run]
6+
# -c : clean before each build
7+
# -w : disable Gradle warnings
8+
# -n : no Gradle daemon
9+
# --dry-run : simulate without building
10+
11+
SCRIPT_VERSION="1.0.0"
12+
CONFIG_FILE="versions.json"
13+
CLEAN=false
14+
WARN=false
15+
NO_DAEMON=false
16+
DRY_RUN=false
17+
18+
usage() {
19+
echo "Usage: $0 [-c] [-w] [-n] [--dry-run]"
20+
echo " -c : clean before each build"
21+
echo " -w : disable Gradle warnings"
22+
echo " -n : no Gradle daemon"
23+
echo " --dry-run : simulate without building"
24+
exit 0
25+
}
26+
27+
PARSED=$(getopt -o cwnh --long dry-run -n "$0" -- "$@")
28+
if [ $? -ne 0 ]; then usage; fi
29+
eval set -- "$PARSED"
30+
while true; do
31+
case "$1" in
32+
-c) CLEAN=true; shift ;;
33+
-w) WARN=true; shift ;;
34+
-n) NO_DAEMON=true; shift ;;
35+
--dry-run) DRY_RUN=true; shift ;;
36+
-h|--help) usage ;;
37+
--) shift; break ;;
38+
*) usage ;;
39+
esac
40+
done
41+
42+
if [ ! -f "$CONFIG_FILE" ]; then
43+
echo "Error: $CONFIG_FILE not found."
44+
exit 1
45+
fi
46+
47+
LAUNCHER_DIR=$(jq -r '.launcherDir // empty' "$CONFIG_FILE")
48+
LOCATION=$(jq -r '.location // empty' "$CONFIG_FILE")
49+
VERSIONS=$(jq -c '.versions[]' "$CONFIG_FILE")
50+
51+
if [ -z "$VERSIONS" ]; then
52+
echo "Error: no versions defined in $CONFIG_FILE"
53+
exit 1
54+
fi
55+
56+
echo "=========================================="
57+
echo " StackableTools - Multi-version Builder "
58+
echo "=========================================="
59+
echo ""
60+
61+
BUILD_ALL_SUCCESS=true
62+
63+
while read -r version_data; do
64+
MC_VERSION=$(echo "$version_data" | jq -r '.version')
65+
MINECRAFT_VER=$(echo "$version_data" | jq -r '.minecraft_version')
66+
YARN=$(echo "$version_data" | jq -r '.yarn_mappings')
67+
FABRIC_API=$(echo "$version_data" | jq -r '.fabric_api_version')
68+
69+
echo "--- Building for Minecraft $MC_VERSION ($MINECRAFT_VER) ---"
70+
71+
if [ "$DRY_RUN" = true ]; then
72+
echo " [DRY-RUN] Would build: -PmcVersion=$MC_VERSION -Pminecraft_version=$MINECRAFT_VER -Pyarn_mappings=$YARN -Pfabric_api_version=$FABRIC_API"
73+
echo ""
74+
continue
75+
fi
76+
77+
GRADLE_ARGS=()
78+
$CLEAN && GRADLE_ARGS+=(clean)
79+
GRADLE_ARGS+=(build)
80+
$NO_DAEMON && GRADLE_ARGS+=(--no-daemon)
81+
$WARN && GRADLE_ARGS+=(--warning-mode=none)
82+
83+
START_TIME=$(date +%s)
84+
./gradlew "${GRADLE_ARGS[@]}" \
85+
-PmcVersion="$MC_VERSION" \
86+
-Pminecraft_version="$MINECRAFT_VER" \
87+
-Pyarn_mappings="$YARN" \
88+
-Pfabric_api_version="$FABRIC_API" \
89+
2>&1 | while IFS= read -r line; do echo " $line"; done
90+
91+
EXIT_CODE=${PIPESTATUS[0]}
92+
END_TIME=$(date +%s)
93+
DURATION=$((END_TIME - START_TIME))
94+
95+
if [ $EXIT_CODE -eq 0 ]; then
96+
JAR_PATH=$(ls build/libs/*.jar 2>/dev/null | grep -v "\-sources" | grep -v "\-dev" | head -n 1)
97+
98+
if [ -n "$JAR_PATH" ]; then
99+
INSTANCE_DIR=$(echo "$version_data" | jq -r '.instanceDir // empty')
100+
if [ -z "$INSTANCE_DIR" ] || [ "$INSTANCE_DIR" = "null" ]; then
101+
INSTANCE_DIR=$(jq -r --arg v "$MC_VERSION" '.instances[$v] // empty' "$CONFIG_FILE")
102+
fi
103+
104+
if [ -n "$LAUNCHER_DIR" ] && [ "$LAUNCHER_DIR" != "null" ] && [ -n "$INSTANCE_DIR" ]; then
105+
DEST_DIR="${LAUNCHER_DIR%/}/${INSTANCE_DIR%/}/${LOCATION%/}/"
106+
mkdir -p "$DEST_DIR"
107+
cp "$JAR_PATH" "$DEST_DIR"
108+
echo " -> Copied to $DEST_DIR"
109+
else
110+
echo " -> JAR: $JAR_PATH (no deploy target configured)"
111+
fi
112+
fi
113+
echo " [OK] Built in ${DURATION}s"
114+
else
115+
echo " [FAIL] Build failed in ${DURATION}s"
116+
BUILD_ALL_SUCCESS=false
117+
fi
118+
echo ""
119+
done <<< "$VERSIONS"
120+
121+
echo "=========================================="
122+
if $BUILD_ALL_SUCCESS; then
123+
echo " All versions built successfully!"
124+
else
125+
echo " Some versions failed to build."
126+
exit 1
127+
fi
128+
echo "=========================================="

versions.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"launcherDir": "/home/yoann/.var/app/org.freesmTeam.freesmlauncher/data/FreesmLauncher/",
3+
"location": "minecraft/mods/",
4+
"instances": {
5+
"1.20.4": "instances/1.20.4/",
6+
"1.20.5": "instances/1.20.5/"
7+
},
8+
"versions": [
9+
{
10+
"version": "1.20.4",
11+
"minecraft_version": "1.20.4",
12+
"yarn_mappings": "1.20.4+build.3",
13+
"fabric_api_version": "0.97.3+1.20.4"
14+
},
15+
{
16+
"version": "1.20.5",
17+
"minecraft_version": "1.20.5",
18+
"yarn_mappings": "1.20.5+build.1",
19+
"fabric_api_version": "0.97.3+1.20.5"
20+
}
21+
]
22+
}

0 commit comments

Comments
 (0)