feat:检测是否安装Java fix:修复彩色字体无法显示
This commit is contained in:
15
package-lock.json
generated
15
package-lock.json
generated
@@ -10,7 +10,6 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"adm-zip": "^0.5.16",
|
"adm-zip": "^0.5.16",
|
||||||
"chalk": "^5.4.1",
|
|
||||||
"cli-progress": "^3.12.0",
|
"cli-progress": "^3.12.0",
|
||||||
"dotenv": "^17.0.1",
|
"dotenv": "^17.0.1",
|
||||||
"fs-extra": "^11.3.0",
|
"fs-extra": "^11.3.0",
|
||||||
@@ -18,6 +17,7 @@
|
|||||||
"inquirer": "^12.6.3",
|
"inquirer": "^12.6.3",
|
||||||
"p-map": "^7.0.3",
|
"p-map": "^7.0.3",
|
||||||
"p-retry": "^6.2.1",
|
"p-retry": "^6.2.1",
|
||||||
|
"picocolors": "^1.1.1",
|
||||||
"smol-toml": "^1.4.1",
|
"smol-toml": "^1.4.1",
|
||||||
"yauzl": "^3.2.0"
|
"yauzl": "^3.2.0"
|
||||||
},
|
},
|
||||||
@@ -1937,18 +1937,6 @@
|
|||||||
"node": ">=4"
|
"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": {
|
"node_modules/chardet": {
|
||||||
"version": "0.7.0",
|
"version": "0.7.0",
|
||||||
"resolved": "https://registry.npmmirror.com/chardet/-/chardet-0.7.0.tgz",
|
"resolved": "https://registry.npmmirror.com/chardet/-/chardet-0.7.0.tgz",
|
||||||
@@ -4873,7 +4861,6 @@
|
|||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz",
|
"resolved": "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz",
|
||||||
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
|
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
|
||||||
"dev": true,
|
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/picomatch": {
|
"node_modules/picomatch": {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"adm-zip": "^0.5.16",
|
"adm-zip": "^0.5.16",
|
||||||
"chalk": "^5.4.1",
|
|
||||||
"cli-progress": "^3.12.0",
|
"cli-progress": "^3.12.0",
|
||||||
"dotenv": "^17.0.1",
|
"dotenv": "^17.0.1",
|
||||||
"fs-extra": "^11.3.0",
|
"fs-extra": "^11.3.0",
|
||||||
@@ -24,6 +23,7 @@
|
|||||||
"inquirer": "^12.6.3",
|
"inquirer": "^12.6.3",
|
||||||
"p-map": "^7.0.3",
|
"p-map": "^7.0.3",
|
||||||
"p-retry": "^6.2.1",
|
"p-retry": "^6.2.1",
|
||||||
|
"picocolors": "^1.1.1",
|
||||||
"smol-toml": "^1.4.1",
|
"smol-toml": "^1.4.1",
|
||||||
"yauzl": "^3.2.0"
|
"yauzl": "^3.2.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import fs from "node:fs";
|
|||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import { join, basename, dirname } from "node:path";
|
import { join, basename, dirname } from "node:path";
|
||||||
import { platform, what_platform } from "./platform/index.js";
|
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 fabric from "./ml_install/fabric.js";
|
||||||
import forge from "./ml_install/forge.js";
|
import forge from "./ml_install/forge.js";
|
||||||
import neoforge from "./ml_install/neoforge.js";
|
import neoforge from "./ml_install/neoforge.js";
|
||||||
@@ -106,6 +106,10 @@ async function install(
|
|||||||
loaderver: string,
|
loaderver: string,
|
||||||
path: string
|
path: string
|
||||||
) {
|
) {
|
||||||
|
if (!(await isInstallJava)){
|
||||||
|
LOGGER.error("请先安装Java!")
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "fabric":
|
case "fabric":
|
||||||
await fabric(minecraft, loaderver, path);
|
await fabric(minecraft, loaderver, path);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import chalk from "chalk";
|
import pc from "picocolors"
|
||||||
export const LOGGER = {
|
export const LOGGER = {
|
||||||
info(text: string) {
|
info(text: string) {
|
||||||
info(text);
|
info(text);
|
||||||
@@ -12,17 +12,17 @@ export const LOGGER = {
|
|||||||
};
|
};
|
||||||
function info(text: string) {
|
function info(text: string) {
|
||||||
console.log(
|
console.log(
|
||||||
`[${chalk.blue(
|
`[${pc.blue(
|
||||||
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
|
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) {
|
function warn(text: string) {
|
||||||
console.log(
|
console.log(
|
||||||
`[${chalk.blue(
|
`[${pc.blue(
|
||||||
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
|
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
|
||||||
)}](${process.pid})[${chalk.yellowBright("WARN")}]:${chalk.yellowBright(
|
)}](${process.pid})[${pc.yellowBright("WARN")}]:${pc.yellowBright(
|
||||||
text
|
text
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
@@ -30,15 +30,15 @@ function warn(text: string) {
|
|||||||
function error(error: object | string | unknown) {
|
function error(error: object | string | unknown) {
|
||||||
if (typeof error === "object") {
|
if (typeof error === "object") {
|
||||||
console.log(
|
console.log(
|
||||||
`[${chalk.blue(
|
`[${pc.blue(
|
||||||
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
|
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
|
||||||
)}](${process.pid})[${chalk.red("ERROR")}:${JSON.stringify(error)}`
|
)}](${process.pid})[${pc.red("ERROR")}:${JSON.stringify(error)}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
`[${chalk.blue(
|
`[${pc.blue(
|
||||||
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
|
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
|
||||||
)}](${process.pid})[${chalk.red("ERROR")}:${error}`
|
)}](${process.pid})[${pc.red("ERROR")}:${error}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import env from "dotenv";
|
|||||||
import { MultiBar } from "cli-progress";
|
import { MultiBar } from "cli-progress";
|
||||||
import { URL, fileURLToPath } from "node:url";
|
import { URL, fileURLToPath } from "node:url";
|
||||||
import { LOGGER } from "./logger.js";
|
import { LOGGER } from "./logger.js";
|
||||||
|
import { exec } from "node:child_process";
|
||||||
|
|
||||||
export async function readzipentry(
|
export async function readzipentry(
|
||||||
zipfile: yauzl.ZipFile,
|
zipfile: yauzl.ZipFile,
|
||||||
@@ -179,3 +180,15 @@ export const isDevelopment = (() => {
|
|||||||
env.config();
|
env.config();
|
||||||
return process.env.DEVELOPMENT;
|
return process.env.DEVELOPMENT;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
export const isInstallJava:Promise<boolean> = (() => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
exec("java -version", (err) => {
|
||||||
|
if (err) {
|
||||||
|
resolve(false);
|
||||||
|
} else {
|
||||||
|
resolve(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user