feat:添加Eula
This commit is contained in:
116
src/main.ts
116
src/main.ts
@@ -1,27 +1,27 @@
|
||||
import inquirer from "inquirer";
|
||||
import yauzl from "yauzl";
|
||||
import process from "node:process";
|
||||
import fs from "node:fs"
|
||||
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 fabric from "./ml_install/fabric.js"
|
||||
import forge from "./ml_install/forge.js"
|
||||
import neoforge from "./ml_install/neoforge.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;
|
||||
}
|
||||
let unzip_path:string = ""
|
||||
if(isDevelopment){
|
||||
unzip_path = join("./","instance/")
|
||||
}else{
|
||||
unzip_path = join(getCurrnetDir().replace("dist",""),"instance")
|
||||
let unzip_path: string = "";
|
||||
if (isDevelopment) {
|
||||
unzip_path = join("./", "instance/");
|
||||
} else {
|
||||
unzip_path = join(getCurrnetDir().replace("dist", ""), "instance");
|
||||
}
|
||||
let zipnamew: string = ""
|
||||
let zipnamew: string = "";
|
||||
const argv = process.argv.slice(2)[0];
|
||||
|
||||
if (!argv) {
|
||||
@@ -29,25 +29,25 @@ if (!argv) {
|
||||
{ type: "input", name: "modpack_path", message: "请输入整合包路径" },
|
||||
]);
|
||||
if (answer.modpack_path) {
|
||||
initdir()
|
||||
initdir();
|
||||
await main(answer.modpack_path);
|
||||
}
|
||||
} else {
|
||||
initdir()
|
||||
initdir();
|
||||
await main(argv);
|
||||
}
|
||||
|
||||
function initdir(){
|
||||
if(!fs.existsSync(unzip_path)){
|
||||
fse.ensureDirSync(join(unzip_path,"rubbish"))
|
||||
function initdir() {
|
||||
if (!fs.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
|
||||
zipnamew = zipname;
|
||||
let dud_files: Array<string> = [];
|
||||
let pack_info: object;
|
||||
//unzip
|
||||
@@ -56,16 +56,21 @@ async function main(modpack_path: string) {
|
||||
zipfile.on("entry", async (entry) => {
|
||||
if (/\/$/.test(entry.fileName)) {
|
||||
} else if (entry.fileName.includes("overrides/")) {
|
||||
const zipfilex = join(unzip_path, zipname,entry.fileName.replace("overrides/",""))
|
||||
if(!fs.existsSync(zipfilex)){
|
||||
zipfile.openReadStream(entry,(err,stream)=>{ //读取overrides文件夹下的所有文件和文件夹
|
||||
const dir = dirname(zipfilex)
|
||||
fse.ensureDirSync(dir);
|
||||
console.log(zipfilex)
|
||||
stream.pipe(fse.createWriteStream(zipfilex))
|
||||
})
|
||||
//console.log(entry.fileName)
|
||||
}
|
||||
const zipfilex = join(
|
||||
unzip_path,
|
||||
zipname,
|
||||
entry.fileName.replace("overrides/", "")
|
||||
);
|
||||
if (!fs.existsSync(zipfilex)) {
|
||||
zipfile.openReadStream(entry, (err, stream) => {
|
||||
//读取overrides文件夹下的所有文件和文件夹
|
||||
const dir = dirname(zipfilex);
|
||||
fse.ensureDirSync(dir);
|
||||
console.log(zipfilex);
|
||||
stream.pipe(fse.createWriteStream(zipfilex));
|
||||
});
|
||||
//console.log(entry.fileName)
|
||||
}
|
||||
} else {
|
||||
const name: string = entry.fileName;
|
||||
dud_files.push(name);
|
||||
@@ -80,36 +85,45 @@ async function main(modpack_path: string) {
|
||||
});
|
||||
zipfile.on("end", async () => {
|
||||
//zip
|
||||
const dirx = join(unzip_path,zipname)
|
||||
const plat = platform(what_platform(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 DeEarthMain(join(dirx,"mods"),join(unzip_path,"rubbish"))
|
||||
await install(info.loader,info.minecraft,info.loader_version,dirx)
|
||||
await plat.downloadfile(pack_info, dirx);
|
||||
await DeEarthMain(join(dirx, "mods"), join(unzip_path, "rubbish"));
|
||||
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已将服务端制作完成!");
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
function getCurrnetDir() {
|
||||
const url = new URL(".", import.meta.url);
|
||||
return fileURLToPath(url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user