Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions .github/builds/mc_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,22 @@
*/

import * as fs from "fs"
import * as readline from "readline"
import * as path from "path"
import {fileURLToPath} from "url"

export async function getMcVersion() {
let lines = readline.createInterface({
input: fs.createReadStream("../../gradle.properties"),
crlfDelay: Infinity
})
const __dirname = path.dirname(fileURLToPath(import.meta.url))

let mcVersion = ""
export async function getMcVersion() {
const filePath = path.resolve(__dirname, "../../gradle/libs.versions.toml")

for await (const line of lines) {
if (line.startsWith("minecraft_version")) {
mcVersion = line.substring(line.indexOf("=") + 1)
break
}
if (!fs.existsSync(filePath)) {
throw new Error(`File not found: ${filePath}`)
}

if (mcVersion === "") {
console.log("Failed to read minecraft_version")
process.exit(1)
}
const content = await fs.promises.readFile(filePath, "utf-8")

const match = content.match(/^\s*minecraft\s*=\s*["']([^"']+)["']\s*$/m)
if (match) return match[1].trim()

return mcVersion
throw new Error(`Failed to find minecraft version in ${filePath}`)
}