From 02074f3c2d8053b0f8c8017c85496854d2e5d753 Mon Sep 17 00:00:00 2001
From: Daniel <790119+DanTheMan827@users.noreply.github.com>
Date: Tue, 23 Jul 2024 17:14:04 +0000
Subject: [PATCH] Use deno instead for qmod generation
---
.github/workflows/qmods.yml | 83 ++++------------------------
.gitignore | 1 +
.vscode/extensions.json | 5 ++
.vscode/settings.json | 7 +++
build_coremods.ts | 104 ++++++++++++++++++++++++++++++++++++
5 files changed, 126 insertions(+), 74 deletions(-)
create mode 100644 .gitignore
create mode 100644 .vscode/extensions.json
create mode 100644 .vscode/settings.json
create mode 100755 build_coremods.ts
diff --git a/.github/workflows/qmods.yml b/.github/workflows/qmods.yml
index 4d79940..dc95151 100644
--- a/.github/workflows/qmods.yml
+++ b/.github/workflows/qmods.yml
@@ -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 "
Beat Saber Core Mods" >> "$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 "- $game_version.qmod
" >> "$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 "
" >> "$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
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ae25cc8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+qmod/
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 0000000..3bfc872
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,5 @@
+{
+ "recommendations": [
+ "denoland.vscode-deno"
+ ]
+}
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..bed5519
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,7 @@
+{
+ "deno.enable": true,
+ "editor.formatOnSave": true,
+ "files.trimTrailingWhitespace": true,
+ "files.insertFinalNewline": true,
+ "files.trimFinalNewlines": true
+}
diff --git a/build_coremods.ts b/build_coremods.ts
new file mode 100755
index 0000000..528592b
--- /dev/null
+++ b/build_coremods.ts
@@ -0,0 +1,104 @@
+#!/bin/env -S deno run --allow-read --allow-write --allow-run
+
+// Import required modules
+import { join } from "https://deno.land/std@0.224.0/path/mod.ts";
+import { compress } from "https://deno.land/x/zip@v1.2.5/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,
+ "Beat Saber Core Mods",
+);
+
+// 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,
+ `- ${gameVersion}.qmod
`,
+ { append: true },
+ );
+
+ // Remove mod.json
+ removeSync(modJsonPath);
+}
+
+// Write the closing tags to index.html
+writeTextFileSync(indexPath, "
", {
+ append: true,
+});