Skip to content

Commit

Permalink
Use deno instead for qmod generation
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTheMan827 authored Jul 23, 2024
1 parent 1fe750e commit 02074f3
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 74 deletions.
83 changes: 9 additions & 74 deletions .github/workflows/qmods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,89 +31,24 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Build Core Qmods
env:
CORE_JSON: "core_mods.json"
DEPLOY_PATH: "qmods"
run: |
mkdir -p "$DEPLOY_PATH"
echo "<html><head><title>Beat Saber Core Mods</title></head><body><ul>" >> "$DEPLOY_PATH/index.html"
versionGreaterThan() {
local version1="$1"
local version2="$2"
if [[ $(printf "%s\n%s" "$version1" "$version2" | sort -V | head -n 1) != "$version1" ]]; then
return 0
else
return 1
fi
}
jq -r 'keys[]' "$CORE_JSON" | while read game_version; do
MODLOADER="QuestLoader"
if versionGreaterThan "$game_version" "1.28.0_4124311467"; then
MODLOADER="Scotland2"
fi
MOD="
{
\"_QPVersion\": \"0.1.1\",
\"name\": \"Core mods for $game_version\",
\"id\": \"CoreMods_$game_version\",
\"author\": \"QuestPackageManager\",
\"description\": \"Downloads all Core mods for Beat Saber version $game_version\",
\"version\": \"1.0.0\",
\"packageId\": \"com.beatgames.beatsaber\",
\"packageVersion\": \"$game_version\",
\"modloader\": \"$MODLOADER\",
\"modFiles\": [],
\"libraryFiles\": [],
\"fileCopies\": [],
\"copyExtensions\": [],
\"dependencies\": []
}
"
last_updated="$(jq -r --arg version "$game_version" '.[$version].lastUpdated' "$CORE_JSON")"
mod_count="$(jq -r --arg version "$game_version" '.[$version].mods | length' "$CORE_JSON")"
for (( i=0; i < $mod_count; i++ )); do
mod="$(jq -r --arg version "$game_version" --argjson index "$i" '.[$version].mods[$index]' "$CORE_JSON")"
mod_id=$(echo "$mod" | jq -r '.id')
mod_version=$(echo "$mod" | jq -r '.version')
mod_download_link=$(echo "$mod" | jq -r '.downloadLink')
dependency="$(jq -n \
--arg id "$mod_id" \
--arg version "^$mod_version" \
--arg downloadIfMissing "$mod_download_link" \
'{id: $id, version: $version, downloadIfMissing: $downloadIfMissing}')"
MOD="$(echo "$MOD" | jq --argjson new_object "$dependency" '.dependencies += [$new_object]')"
done
echo "$MOD" > mod.json
touch -d "$last_updated" mod.json
zip "$DEPLOY_PATH/$game_version.qmod" mod.json
touch -d "$last_updated" "$DEPLOY_PATH/$game_version.qmod"
echo "<li><a href=\"$game_version.qmod\">$game_version.qmod</a></li>" >> "$DEPLOY_PATH/index.html"
rm mod.json
done
- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Build core qmods
run: ./build_coremods.ts

echo "</ul></body></html>" >> "$DEPLOY_PATH/index.html"
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: 'qmods'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
qmod/
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"denoland.vscode-deno"
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"deno.enable": true,
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
}
104 changes: 104 additions & 0 deletions build_coremods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/env -S deno run --allow-read --allow-write --allow-run

// Import required modules
import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { compress } from "https://deno.land/x/[email protected]/mod.ts";
const {
mkdirSync,
readTextFileSync,
utimeSync,
writeTextFileSync,
removeSync,
} = Deno;

// Define constants
const deployPath = "./qmod";
const coreJsonPath = "./core_mods.json";
const indexPath = join(deployPath, "index.html");

// Create the deployment directory
mkdirSync(deployPath, { recursive: true });

// Write the starting HTML tags to index.html
writeTextFileSync(
indexPath,
"<html><head><title>Beat Saber Core Mods</title></head><body><ul>",
);

// Parse core_mods.json
const coreJson = JSON.parse(readTextFileSync(coreJsonPath));

// Loop through the game versions
for (const gameVersion in coreJson) {
const modLoader = gameVersion > "1.28.0_4124311467"
? "Scotland2"
: "QuestLoader";

// Defining mod object
const mod = {
_QPVersion: "0.1.1",
name: `Core mods for ${gameVersion}`,
id: `CoreMods_${gameVersion}`,
author: "QuestPackageManager",
description:
`Downloads all Core mods for Beat Saber version ${gameVersion}`,
version: "1.0.0",
packageId: "com.beatgames.beatsaber",
packageVersion: gameVersion,
modloader: modLoader,
modFiles: [],
libraryFiles: [],
fileCopies: [],
copyExtensions: [],
dependencies: coreJson[gameVersion].mods.map((
mod: {
id: string;
version: string;
downloadLink: string;
},
) => ({
id: mod.id,
version: `^${mod.version}`,
downloadIfMissing: mod.downloadLink,
})),
};

// Write the mod object to mod.json
const modJsonPath = "mod.json";
writeTextFileSync(modJsonPath, JSON.stringify(mod, null, 2));

// Update the modified time of mod.json
const lastUpdated = new Date(coreJson[gameVersion].lastUpdated);
utimeSync(modJsonPath, lastUpdated, lastUpdated);

// Set the zip file path
const zipPath = join(deployPath, `${gameVersion}.qmod`);

// Delete the archive if it already exists
try {
removeSync(zipPath);
} catch (_err) {
// Just ignore the error, the file doesn't exist most likely.
}

// Compress mod.json
await compress([modJsonPath], zipPath);

// Update the modified time of the archive
utimeSync(zipPath, lastUpdated, lastUpdated);

// Write the list item to index.html
writeTextFileSync(
indexPath,
`<li><a href="${gameVersion}.qmod">${gameVersion}.qmod</a></li>`,
{ append: true },
);

// Remove mod.json
removeSync(modJsonPath);
}

// Write the closing tags to index.html
writeTextFileSync(indexPath, "</ul></body></html>", {
append: true,
});

0 comments on commit 02074f3

Please sign in to comment.