feat:检测是否安装Java fix:修复彩色字体无法显示

This commit is contained in:
Tianpao
2025-07-24 11:22:01 +08:00
parent 777d8e43aa
commit 9f9cfc3e17
5 changed files with 29 additions and 25 deletions

15
package-lock.json generated
View File

@@ -10,7 +10,6 @@
"license": "ISC",
"dependencies": {
"adm-zip": "^0.5.16",
"chalk": "^5.4.1",
"cli-progress": "^3.12.0",
"dotenv": "^17.0.1",
"fs-extra": "^11.3.0",
@@ -18,6 +17,7 @@
"inquirer": "^12.6.3",
"p-map": "^7.0.3",
"p-retry": "^6.2.1",
"picocolors": "^1.1.1",
"smol-toml": "^1.4.1",
"yauzl": "^3.2.0"
},
@@ -1937,18 +1937,6 @@
"node": ">=4"
}
},
"node_modules/chalk": {
"version": "5.4.1",
"resolved": "https://registry.npmmirror.com/chalk/-/chalk-5.4.1.tgz",
"integrity": "sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w==",
"license": "MIT",
"engines": {
"node": "^12.17.0 || ^14.13 || >=16.0.0"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/chardet": {
"version": "0.7.0",
"resolved": "https://registry.npmmirror.com/chardet/-/chardet-0.7.0.tgz",
@@ -4873,7 +4861,6 @@
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz",
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
"dev": true,
"license": "ISC"
},
"node_modules/picomatch": {

View File

@@ -16,7 +16,6 @@
},
"dependencies": {
"adm-zip": "^0.5.16",
"chalk": "^5.4.1",
"cli-progress": "^3.12.0",
"dotenv": "^17.0.1",
"fs-extra": "^11.3.0",
@@ -24,6 +23,7 @@
"inquirer": "^12.6.3",
"p-map": "^7.0.3",
"p-retry": "^6.2.1",
"picocolors": "^1.1.1",
"smol-toml": "^1.4.1",
"yauzl": "^3.2.0"
},

View File

@@ -5,7 +5,7 @@ import fs from "node:fs";
import fse from "fs-extra";
import { join, basename, dirname } from "node:path";
import { platform, what_platform } from "./platform/index.js";
import { isDevelopment, readzipentry } from "./utils/utils.js";
import { isDevelopment, isInstallJava, readzipentry } from "./utils/utils.js";
import fabric from "./ml_install/fabric.js";
import forge from "./ml_install/forge.js";
import neoforge from "./ml_install/neoforge.js";
@@ -106,6 +106,10 @@ async function install(
loaderver: string,
path: string
) {
if (!(await isInstallJava)){
LOGGER.error("请先安装Java")
return;
}
switch (type) {
case "fabric":
await fabric(minecraft, loaderver, path);

View File

@@ -1,4 +1,4 @@
import chalk from "chalk";
import pc from "picocolors"
export const LOGGER = {
info(text: string) {
info(text);
@@ -12,17 +12,17 @@ export const LOGGER = {
};
function info(text: string) {
console.log(
`[${chalk.blue(
`[${pc.blue(
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
)}](${process.pid})[${chalk.green("INFO")}]:${chalk.cyan(text)}`
)}](${process.pid})[${pc.green("INFO")}]:${pc.cyan(text)}`
);
}
function warn(text: string) {
console.log(
`[${chalk.blue(
`[${pc.blue(
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
)}](${process.pid})[${chalk.yellowBright("WARN")}]:${chalk.yellowBright(
)}](${process.pid})[${pc.yellowBright("WARN")}]:${pc.yellowBright(
text
)}`
);
@@ -30,15 +30,15 @@ function warn(text: string) {
function error(error: object | string | unknown) {
if (typeof error === "object") {
console.log(
`[${chalk.blue(
`[${pc.blue(
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
)}](${process.pid})[${chalk.red("ERROR")}:${JSON.stringify(error)}`
)}](${process.pid})[${pc.red("ERROR")}:${JSON.stringify(error)}`
);
} else {
console.log(
`[${chalk.blue(
`[${pc.blue(
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
)}](${process.pid})[${chalk.red("ERROR")}:${error}`
)}](${process.pid})[${pc.red("ERROR")}:${error}`
);
}
}

View File

@@ -8,6 +8,7 @@ import env from "dotenv";
import { MultiBar } from "cli-progress";
import { URL, fileURLToPath } from "node:url";
import { LOGGER } from "./logger.js";
import { exec } from "node:child_process";
export async function readzipentry(
zipfile: yauzl.ZipFile,
@@ -179,3 +180,15 @@ export const isDevelopment = (() => {
env.config();
return process.env.DEVELOPMENT;
})();
export const isInstallJava:Promise<boolean> = (() => {
return new Promise((resolve) => {
exec("java -version", (err) => {
if (err) {
resolve(false);
} else {
resolve(true);
}
});
});
})();