From 9f9cfc3e17cd4657e9b9c8349b100fde8746e5db Mon Sep 17 00:00:00 2001 From: Tianpao Date: Thu, 24 Jul 2025 11:22:01 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=A3=80=E6=B5=8B=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=AE=89=E8=A3=85Java=20fix=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=BD=A9=E8=89=B2=E5=AD=97=E4=BD=93=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 15 +-------------- package.json | 2 +- src/main.ts | 6 +++++- src/utils/logger.ts | 18 +++++++++--------- src/utils/utils.ts | 13 +++++++++++++ 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/package-lock.json b/package-lock.json index 91125d9..b2b1399 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index 2fc11b5..72835dd 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/main.ts b/src/main.ts index 48cead7..46f3816 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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); diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 96486bd..c5acd1c 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -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}` ); } } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 21d8053..b21021a 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -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 = (() => { + return new Promise((resolve) => { + exec("java -version", (err) => { + if (err) { + resolve(false); + } else { + resolve(true); + } + }); + }); +})();