Skip to content

Commit

Permalink
Add script and workflow to generate core qmods
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTheMan827 authored Jul 23, 2024
1 parent bade2fc commit 931a48c
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM mcr.microsoft.com/vscode/devcontainers/base:debian-10

ENV DENO_INSTALL=/deno
RUN mkdir -p /deno \
&& curl -fsSL https://deno.land/x/install/install.sh | sh \
&& chown -R vscode /deno

ENV PATH=${DENO_INSTALL}/bin:${PATH} \
DENO_DIR=${DENO_INSTALL}/.cache/deno

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
24 changes: 24 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "Deno",
"dockerFile": "Dockerfile",
// Set *default* container specific settings.json values on container create.
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"denoland.vscode-deno",
"github.vscode-github-actions",
"ms-azuretools.vscode-docker"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
54 changes: 54 additions & 0 deletions .github/workflows/qmods.yml
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: '.'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.qmod
index.html
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"denoland.vscode-deno",
"github.vscode-github-actions",
"ms-azuretools.vscode-docker"
]
}
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 @@
#!/usr/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 = ".";
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 931a48c

Please sign in to comment.