forked from QuestPackageManager/bs-coremods
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script and workflow to generate core qmods
- Loading branch information
1 parent
bade2fc
commit 9ece801
Showing
5 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Simple workflow for deploying static content to GitHub Pages | ||
name: Build and deploy qmods | ||
|
||
on: | ||
# Runs on pushes targeting the default branch | ||
push: | ||
branches: ["main"] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | ||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
# Single deploy job since we're just deploying | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Pages | ||
uses: actions/configure-pages@v5 | ||
|
||
- name: Install Deno | ||
uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.x | ||
|
||
- name: Build core qmods | ||
run: ./build_coremods.ts | ||
|
||
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
qmod/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"denoland.vscode-deno" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/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 = "./qmods"; | ||
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, | ||
}); |