Initial project scaffold for minecraft-java-manager. Adds package.json and package-lock.json, README update, index.js entrypoint and test.js. Introduces src modules: checker (detects Java version), installer (downloads JRE components with redirects, SHA1 validation, progress/events and concurrency), web (fetches launcher/runtime manifests and component data), systeminfo (platform key and install path resolution) and config (endpoints). Declares dependencies adm-zip and node-downloader-helper.
37 lines
856 B
JavaScript
37 lines
856 B
JavaScript
const childProcess = require("node:child_process")
|
|
|
|
function getJavaVersionOutput(defaultCommand = "java") {
|
|
try {
|
|
const command = childProcess.spawnSync(defaultCommand, ["-version"], {
|
|
encoding: "utf-8",
|
|
windowsHide: true,
|
|
})
|
|
|
|
if (command.error) {
|
|
return null
|
|
}
|
|
|
|
return command.stderr || command.stdout || ""
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
function parseJavaOutput(output) {
|
|
if (!output || typeof output !== "string") {
|
|
return null
|
|
}
|
|
|
|
const match = output.match(/version\s+"(?:1\.)?(\d+)/i)
|
|
return match ? parseInt(match[1], 10) : null
|
|
}
|
|
|
|
function isJavaCompatible(output, requiredMajor) {
|
|
return parseJavaOutput(output) === requiredMajor
|
|
}
|
|
|
|
module.exports = {
|
|
getJavaVersionOutput,
|
|
isJavaCompatible,
|
|
parseJavaOutput,
|
|
} |