Compare commits

...

4 Commits

Author SHA1 Message Date
Tianpao
1e35fac53b feat:添加Eula 2025-07-09 11:49:13 +08:00
Tianpao
63d318772a refactor:package build 2025-07-09 10:54:01 +08:00
Tianpao
f2fa0c8bdf fix:unzip error 2025-07-09 10:20:20 +08:00
Tianpao
f0ead136fe fix:修复modrinth json读取失败 2025-07-08 21:57:55 +08:00
7 changed files with 138 additions and 65 deletions

50
package-lock.json generated
View File

@@ -25,9 +25,11 @@
"@rollup/plugin-commonjs": "^28.0.6", "@rollup/plugin-commonjs": "^28.0.6",
"@rollup/plugin-json": "^6.1.0", "@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.1", "@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-typescript": "^12.1.4",
"@types/adm-zip": "^0.5.7", "@types/adm-zip": "^0.5.7",
"@types/cli-progress": "^3.11.6", "@types/cli-progress": "^3.11.6",
"@types/fs-extra": "^11.0.4", "@types/fs-extra": "^11.0.4",
"@types/inquirer": "^9.0.8",
"@types/yauzl": "^2.10.3", "@types/yauzl": "^2.10.3",
"nexe": "^5.0.0-beta.4", "nexe": "^5.0.0-beta.4",
"rollup": "^4.44.1", "rollup": "^4.44.1",
@@ -556,6 +558,33 @@
} }
} }
}, },
"node_modules/@rollup/plugin-typescript": {
"version": "12.1.4",
"resolved": "https://registry.npmmirror.com/@rollup/plugin-typescript/-/plugin-typescript-12.1.4.tgz",
"integrity": "sha512-s5Hx+EtN60LMlDBvl5f04bEiFZmAepk27Q+mr85L/00zPDn1jtzlTV6FWn81MaIwqfWzKxmOJrBWHU6vtQyedQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@rollup/pluginutils": "^5.1.0",
"resolve": "^1.22.1"
},
"engines": {
"node": ">=14.0.0"
},
"peerDependencies": {
"rollup": "^2.14.0||^3.0.0||^4.0.0",
"tslib": "*",
"typescript": ">=3.7.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
},
"tslib": {
"optional": true
}
}
},
"node_modules/@rollup/pluginutils": { "node_modules/@rollup/pluginutils": {
"version": "5.2.0", "version": "5.2.0",
"resolved": "https://registry.npmmirror.com/@rollup/pluginutils/-/pluginutils-5.2.0.tgz", "resolved": "https://registry.npmmirror.com/@rollup/pluginutils/-/pluginutils-5.2.0.tgz",
@@ -975,6 +1004,17 @@
"integrity": "sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==", "integrity": "sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/inquirer": {
"version": "9.0.8",
"resolved": "https://registry.npmmirror.com/@types/inquirer/-/inquirer-9.0.8.tgz",
"integrity": "sha512-CgPD5kFGWsb8HJ5K7rfWlifao87m4ph8uioU7OTncJevmE/VLIqAAjfQtko578JZg7/f69K4FgqYym3gNr7DeA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/through": "*",
"rxjs": "^7.2.0"
}
},
"node_modules/@types/json-schema": { "node_modules/@types/json-schema": {
"version": "7.0.15", "version": "7.0.15",
"resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz", "resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz",
@@ -1029,6 +1069,16 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/through": {
"version": "0.0.33",
"resolved": "https://registry.npmmirror.com/@types/through/-/through-0.0.33.tgz",
"integrity": "sha512-HsJ+z3QuETzP3cswwtzt2vEIiHBk/dCcHGhbmG5X3ecnwFD/lPrMpliGXxSCg03L9AhrdwA4Oz/qfspkDW+xGQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/uglify-js": { "node_modules/@types/uglify-js": {
"version": "3.17.5", "version": "3.17.5",
"resolved": "https://registry.npmmirror.com/@types/uglify-js/-/uglify-js-3.17.5.tgz", "resolved": "https://registry.npmmirror.com/@types/uglify-js/-/uglify-js-3.17.5.tgz",

View File

@@ -9,9 +9,9 @@
"scripts": { "scripts": {
"tsbuild": "tsc", "tsbuild": "tsc",
"rollup": "rollup -c rollup.config.js", "rollup": "rollup -c rollup.config.js",
"nexe": "nexe -i ./ndist/bundle.js --ico Dex.ico --build -t x86-22.13.0 --output ./ndist/DeEarthX.exe", "nexe": "nexe -i ./dist/bundle.js --ico Dex.ico --build -t x86-22.13.0 --output ./dist/DeEarthX.exe",
"upx": ".\\dist_modules\\upx.exe .\\ndist\\DeEarthX.exe", "upx": ".\\dist_modules\\upx.exe .\\dist\\DeEarthX.exe",
"build": "npm run tsbuild&&npm run rollup&&npm run nexe&&npm run upx", "build": "npm run rollup&&npm run nexe&&npm run upx",
"test": "tsc&&node dist/main.js" "test": "tsc&&node dist/main.js"
}, },
"dependencies": { "dependencies": {
@@ -31,9 +31,11 @@
"@rollup/plugin-commonjs": "^28.0.6", "@rollup/plugin-commonjs": "^28.0.6",
"@rollup/plugin-json": "^6.1.0", "@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.1", "@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-typescript": "^12.1.4",
"@types/adm-zip": "^0.5.7", "@types/adm-zip": "^0.5.7",
"@types/cli-progress": "^3.11.6", "@types/cli-progress": "^3.11.6",
"@types/fs-extra": "^11.0.4", "@types/fs-extra": "^11.0.4",
"@types/inquirer": "^9.0.8",
"@types/yauzl": "^2.10.3", "@types/yauzl": "^2.10.3",
"nexe": "^5.0.0-beta.4", "nexe": "^5.0.0-beta.4",
"rollup": "^4.44.1", "rollup": "^4.44.1",

View File

@@ -1,16 +1,18 @@
import typescript from '@rollup/plugin-typescript'
import resolve from '@rollup/plugin-node-resolve'; import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs' import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'; import json from '@rollup/plugin-json';
/** @type {import('rollup').RollupOptions} */ /** @type {import('rollup').RollupOptions} */
// ---cut--- // ---cut---
export default { export default {
input: 'dist/main.js', input: 'src/main.ts',
output: { output: {
file: 'ndist/bundle.js', file: 'dist/bundle.js',
format: 'es' format: 'esm'
}, },
plugins:[ plugins:[
resolve({preferBuiltins: false}), typescript(),
resolve({preferBuiltins: true}),
commonjs(), commonjs(),
json() json()
] ]

View File

@@ -1,26 +1,27 @@
import inquirer from "inquirer"; import inquirer from "inquirer";
import yauzl from "yauzl"; import yauzl from "yauzl";
import process from "node:process"; import process from "node:process";
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, 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";
import { DeEarthMain } from "./utils/DeEarth.js"; import { DeEarthMain } from "./utils/DeEarth.js";
import { LOGGER } from "./utils/logger.js"; import { LOGGER } from "./utils/logger.js";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
interface Answers { interface Answers {
modpack_path: string | undefined; modpack_path: string | undefined;
} }
let unzip_path:string = "" let unzip_path: string = "";
if (isDevelopment) { if (isDevelopment) {
unzip_path = join("./","instance/") unzip_path = join("./", "instance/");
} else { } else {
unzip_path = join(getCurrnetDir().replace("ndist",""),"instance") unzip_path = join(getCurrnetDir().replace("dist", ""), "instance");
} }
let zipnamew: string = "" let zipnamew: string = "";
const argv = process.argv.slice(2)[0]; const argv = process.argv.slice(2)[0];
if (!argv) { if (!argv) {
@@ -28,17 +29,17 @@ if (!argv) {
{ type: "input", name: "modpack_path", message: "请输入整合包路径" }, { type: "input", name: "modpack_path", message: "请输入整合包路径" },
]); ]);
if (answer.modpack_path) { if (answer.modpack_path) {
initdir() initdir();
await main(answer.modpack_path); await main(answer.modpack_path);
} }
} else { } else {
initdir() initdir();
await main(argv); await main(argv);
} }
function initdir() { function initdir() {
if(!fse.existsSync(unzip_path)){ if (!fs.existsSync(unzip_path)) {
fse.ensureDirSync(join(unzip_path,"rubbish")) fse.ensureDirSync(join(unzip_path, "rubbish"));
} }
} }
@@ -46,7 +47,7 @@ async function main(modpack_path: string) {
const zipname = basename(modpack_path) const zipname = basename(modpack_path)
.replace(".zip", "") .replace(".zip", "")
.replace(".mrpack", ""); .replace(".mrpack", "");
zipnamew=zipname zipnamew = zipname;
let dud_files: Array<string> = []; let dud_files: Array<string> = [];
let pack_info: object; let pack_info: object;
//unzip //unzip
@@ -55,20 +56,26 @@ async function main(modpack_path: string) {
zipfile.on("entry", async (entry) => { zipfile.on("entry", async (entry) => {
if (/\/$/.test(entry.fileName)) { if (/\/$/.test(entry.fileName)) {
} else if (entry.fileName.includes("overrides/")) { } else if (entry.fileName.includes("overrides/")) {
const zipfilex = join(unzip_path, zipname,entry.fileName.replace("overrides/","")) const zipfilex = join(
if(!fse.existsSync(zipfilex)){ unzip_path,
zipfile.openReadStream(entry,(err,stream)=>{ //读取overrides文件夹下的所有文件和文件夹 zipname,
const dir = dirname(zipfilex) entry.fileName.replace("overrides/", "")
);
if (!fs.existsSync(zipfilex)) {
zipfile.openReadStream(entry, (err, stream) => {
//读取overrides文件夹下的所有文件和文件夹
const dir = dirname(zipfilex);
fse.ensureDirSync(dir); fse.ensureDirSync(dir);
console.log(zipfilex) console.log(zipfilex);
stream.pipe(fse.createWriteStream(zipfilex)) stream.pipe(fse.createWriteStream(zipfilex));
}) });
//console.log(entry.fileName) //console.log(entry.fileName)
} }
} else { } else {
const name: string = entry.fileName; const name: string = entry.fileName;
dud_files.push(name); dud_files.push(name);
if (name.endsWith(".json")) { if (name.endsWith(".json")) {
//console.log((await readzipentry(zipfile, entry)))
pack_info = JSON.parse( pack_info = JSON.parse(
(await readzipentry(zipfile, entry)).toString() (await readzipentry(zipfile, entry)).toString()
); );
@@ -78,31 +85,40 @@ async function main(modpack_path: string) {
}); });
zipfile.on("end", async () => { zipfile.on("end", async () => {
//zip //zip
const dirx = join(unzip_path,zipname) const dirx = join(unzip_path, zipname);
const plat = platform(what_platform(dud_files)) const plat = platform(what_platform(dud_files));
const info = await plat.getinfo(pack_info); const info = await plat.getinfo(pack_info);
await plat.downloadfile(pack_info,dirx) await plat.downloadfile(pack_info, dirx);
await DeEarthMain(join(dirx,"mods"),join(unzip_path,"rubbish")) await DeEarthMain(join(dirx, "mods"), join(unzip_path, "rubbish"));
await install(info.loader,info.minecraft,info.loader_version,dirx) await install(info.loader, info.minecraft, info.loader_version, dirx);
fs.writeFileSync(
join(dirx, "instance.zip"),
"#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA).\n#This serverpack created by DeEarthX\neula=true"
);
LOGGER.info("DeEarthX已将服务端制作完成"); LOGGER.info("DeEarthX已将服务端制作完成");
zipfile.close(); zipfile.close();
}); });
}); });
} }
async function install(type: string,minecraft:string,loaderver:string,path:string){ async function install(
type: string,
minecraft: string,
loaderver: string,
path: string
) {
switch (type) { switch (type) {
case "fabric": case "fabric":
await fabric(minecraft,loaderver,path) await fabric(minecraft, loaderver, path);
break; break;
case "fabric-loader": case "fabric-loader":
await fabric(minecraft,loaderver,path) await fabric(minecraft, loaderver, path);
break; break;
case "forge": case "forge":
await forge(minecraft,loaderver,path) await forge(minecraft, loaderver, path);
break; break;
case "neoforge": case "neoforge":
await neoforge(minecraft,loaderver,path) await neoforge(minecraft, loaderver, path);
break; break;
} }
} }

View File

@@ -1,5 +1,5 @@
import cp from "child_process"; import cp from "child_process";
import fsExtra from "fs-extra/esm"; import fsExtra from "fs-extra";
import got from "got"; import got from "got";
export default async function install( export default async function install(
mcver: string, mcver: string,

View File

@@ -1,5 +1,5 @@
import AdmZip from "adm-zip"; import AdmZip from "adm-zip";
import fsExtra from "fs-extra/esm"; import fsExtra from "fs-extra";
import gotx from "got"; import gotx from "got";
import { xfastdownload } from "../utils/utils.js"; import { xfastdownload } from "../utils/utils.js";
import { LOGGER } from "../utils/logger.js"; import { LOGGER } from "../utils/logger.js";

View File

@@ -1,5 +1,6 @@
import pMap from "p-map"; import pMap from "p-map";
import pRetry from "p-retry"; import pRetry from "p-retry";
import fs from "node:fs"
import fse from "fs-extra" import fse from "fs-extra"
import yauzl from "yauzl"; import yauzl from "yauzl";
import got from "got"; import got from "got";
@@ -8,14 +9,16 @@ 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";
export async function readzipentry(zipfile: yauzl.ZipFile, entry: yauzl.Entry):Promise<string|Buffer> { export async function readzipentry(zipfile: yauzl.ZipFile, entry: yauzl.Entry):Promise<string> {
const data: Buffer<ArrayBufferLike>[] = []; const data: Buffer<ArrayBufferLike>[] = [];
return await new Promise((reslove, reject) => { return await new Promise((reslove, reject) => {
zipfile.openReadStream(entry, (err, e) => { zipfile.openReadStream(entry, (err, e) => {
e.on("data", (chunk: Buffer) => { e.on("data", (chunk: Buffer) => {
data.push(chunk); data.push(chunk);
}).on("end", () => { }).on("end", () => {
reslove(data.toString()); if (data.length !== 0&&typeof data !== "string"){
reslove(Buffer.concat(data).toString());
}
}); });
}); });
}); });
@@ -33,7 +36,7 @@ export async function fastdownload(data:[string,string]){
const bar = multibar.create(size, 0, {filename: e[1]}) const bar = multibar.create(size, 0, {filename: e[1]})
try{ try{
await pRetry(async()=>{ await pRetry(async()=>{
if(!fse.existsSync(e[1])){ if(!fs.existsSync(e[1])){
await got.get(e[0],{ await got.get(e[0],{
responseType:"buffer", responseType:"buffer",
}).on('downloadProgress',(progress)=>{ }).on('downloadProgress',(progress)=>{
@@ -103,7 +106,7 @@ export async function xfastdownload(
url !== null && url !== null &&
url !== "" && url !== "" &&
path !== null && path !== null &&
!fse.existsSync(e[1]) !fs.existsSync(e[1])
) { ) {
const res = (await got.get(e[0])).rawBody; //下载文件 const res = (await got.get(e[0])).rawBody; //下载文件
await fse.outputFile(e[1], res); //保存文件 await fse.outputFile(e[1], res); //保存文件