Files
minecraft-java-manager/index.js
T
2026-09-06 04:58:10 +02:00

28 lines
1.3 KiB
JavaScript

const installer = require("./src/installer")
const checker = require("./src/checker")
const sysinfo = require("./src/systeminfo")
const web = require("./src/web")
async function isJavaInstalledAndCompatibleFor(mcVersion, customExec = "java") {
const mcVersionManifestUrl = await web.getVersionManifest(mcVersion)
const requiredJRE = await web.getRequiredJREFor(mcVersionManifestUrl)
const checkJRECommand = checker.getJavaVersionOutput(customExec)
const isJavaCompatible = checker.isJavaCompatible(checkJRECommand, requiredJRE.majorVersion)
return isJavaCompatible
}
async function installJava(mcVersion, customExec = null) {
const versionManifest = await web.getVersionManifest(mcVersion)
const requiredComponent = await web.getRequiredJREFor(versionManifest)
const { component, majorVersion } = requiredComponent
const installationPath = await sysinfo.determineInstallationPath(component, majorVersion, customExec)
const requiredComponentDetails = await web.getJREComponentDetails(component, sysinfo.getPlatformKey())
const requiredComponentManifest = await web.getJREComponentManifest(requiredComponentDetails[0].manifest.url)
return installer.downloadJavaComponent(requiredComponentManifest, installationPath)
}
module.exports = {
isJavaInstalledAndCompatibleFor,
installJava
}