feat:基本最终完成
This commit is contained in:
75
src/main.ts
75
src/main.ts
@@ -1,13 +1,26 @@
|
||||
import inquirer from "inquirer";
|
||||
import yauzl from "yauzl";
|
||||
import process from "node:process";
|
||||
import { join, basename } from "node:path";
|
||||
import fse from "fs-extra";
|
||||
import { join, basename, dirname } from "node:path";
|
||||
import { platform, what_platform } from "./platform/index.js";
|
||||
import { readzipentry } from "./utils/utils.js";
|
||||
import { isDevelopment, 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"
|
||||
import { DeEarthMain } from "./utils/DeEarth.js";
|
||||
import { LOGGER } from "./utils/logger.js";
|
||||
import { fileURLToPath } from "node:url";
|
||||
interface Answers {
|
||||
modpack_path: string | undefined;
|
||||
}
|
||||
const unzip_path = "./instance";
|
||||
let unzip_path:string = ""
|
||||
if(isDevelopment){
|
||||
unzip_path = join("./","instance")
|
||||
}else{
|
||||
unzip_path = join(getCurrnetDir(),"instance")
|
||||
}
|
||||
let zipnamew: string = ""
|
||||
const argv = process.argv.slice(2)[0];
|
||||
|
||||
if (!argv) {
|
||||
@@ -15,16 +28,25 @@ if (!argv) {
|
||||
{ type: "input", name: "modpack_path", message: "请输入整合包路径" },
|
||||
]);
|
||||
if (answer.modpack_path) {
|
||||
initdir()
|
||||
await main(answer.modpack_path);
|
||||
}
|
||||
} else {
|
||||
initdir()
|
||||
await main(argv);
|
||||
}
|
||||
|
||||
function initdir(){
|
||||
if(!fse.existsSync(unzip_path)){
|
||||
fse.ensureDirSync(join(unzip_path,"rubbish"))
|
||||
}
|
||||
}
|
||||
|
||||
async function main(modpack_path: string) {
|
||||
const zipname = basename(modpack_path)
|
||||
const zipname= basename(modpack_path)
|
||||
.replace(".zip", "")
|
||||
.replace(".mrpack", "");
|
||||
zipnamew=zipname
|
||||
let dud_files: Array<string> = [];
|
||||
let pack_info: object;
|
||||
//unzip
|
||||
@@ -33,10 +55,15 @@ async function main(modpack_path: string) {
|
||||
zipfile.on("entry", async (entry) => {
|
||||
if (/\/$/.test(entry.fileName)) {
|
||||
} else if (entry.fileName.includes("overrides/")) {
|
||||
/*zipfile.openReadStream(entry,(err,stream)=>{ //读取overrides文件夹下的所有文件和文件夹
|
||||
|
||||
})*/
|
||||
const zipfilex = join(unzip_path, zipname,entry.fileName.replace("overrides/",""))
|
||||
if(!fse.existsSync(zipfilex)){
|
||||
zipfile.openReadStream(entry,(err,stream)=>{ //读取overrides文件夹下的所有文件和文件夹
|
||||
const dir = dirname(zipfilex)
|
||||
fse.ensureDirSync(dir);
|
||||
stream.pipe(fse.createWriteStream(zipfilex))
|
||||
})
|
||||
//console.log(entry.fileName)
|
||||
}
|
||||
} else {
|
||||
const name: string = entry.fileName;
|
||||
dud_files.push(name);
|
||||
@@ -45,15 +72,41 @@ async function main(modpack_path: string) {
|
||||
(await readzipentry(zipfile, entry)).toString()
|
||||
);
|
||||
}
|
||||
console.log(name);
|
||||
}
|
||||
zipfile.readEntry();
|
||||
});
|
||||
zipfile.on("end", () => {
|
||||
zipfile.on("end", async () => {
|
||||
//zip
|
||||
platform(what_platform(dud_files));
|
||||
//console.log(dud_files)
|
||||
const dirx = join(unzip_path,zipname)
|
||||
const plat = platform(what_platform(dud_files))
|
||||
const info = await plat.getinfo(pack_info);
|
||||
await plat.downloadfile(pack_info,dirx)
|
||||
await install(info.loader,info.minecraft,info.loader_version,dirx)
|
||||
await DeEarthMain(join(dirx,"mods"),join(unzip_path,"rubbish"))
|
||||
LOGGER.info("DeEarthX已将服务端制作完成!");
|
||||
zipfile.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function install(type: string,minecraft:string,loaderver:string,path:string){
|
||||
switch(type){
|
||||
case "fabric":
|
||||
await fabric(minecraft,loaderver,path)
|
||||
break;
|
||||
case "fabric-loader":
|
||||
await fabric(minecraft,loaderver,path)
|
||||
break;
|
||||
case "forge":
|
||||
await forge(minecraft,loaderver,path)
|
||||
break;
|
||||
case "neoforge":
|
||||
await neoforge(minecraft,loaderver,path)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrnetDir () {
|
||||
const url = new URL(".", import.meta.url);
|
||||
return fileURLToPath(url);
|
||||
}
|
||||
Reference in New Issue
Block a user