Compare commits
4 Commits
ba8c21cd6c
...
1e35fac53b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e35fac53b | ||
|
|
63d318772a | ||
|
|
f2fa0c8bdf | ||
|
|
f0ead136fe |
50
package-lock.json
generated
50
package-lock.json
generated
@@ -25,9 +25,11 @@
|
||||
"@rollup/plugin-commonjs": "^28.0.6",
|
||||
"@rollup/plugin-json": "^6.1.0",
|
||||
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||
"@rollup/plugin-typescript": "^12.1.4",
|
||||
"@types/adm-zip": "^0.5.7",
|
||||
"@types/cli-progress": "^3.11.6",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/inquirer": "^9.0.8",
|
||||
"@types/yauzl": "^2.10.3",
|
||||
"nexe": "^5.0.0-beta.4",
|
||||
"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": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/@rollup/pluginutils/-/pluginutils-5.2.0.tgz",
|
||||
@@ -975,6 +1004,17 @@
|
||||
"integrity": "sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==",
|
||||
"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": {
|
||||
"version": "7.0.15",
|
||||
"resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz",
|
||||
@@ -1029,6 +1069,16 @@
|
||||
"dev": true,
|
||||
"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": {
|
||||
"version": "3.17.5",
|
||||
"resolved": "https://registry.npmmirror.com/@types/uglify-js/-/uglify-js-3.17.5.tgz",
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
"scripts": {
|
||||
"tsbuild": "tsc",
|
||||
"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",
|
||||
"upx": ".\\dist_modules\\upx.exe .\\ndist\\DeEarthX.exe",
|
||||
"build": "npm run tsbuild&&npm run rollup&&npm run nexe&&npm run upx",
|
||||
"nexe": "nexe -i ./dist/bundle.js --ico Dex.ico --build -t x86-22.13.0 --output ./dist/DeEarthX.exe",
|
||||
"upx": ".\\dist_modules\\upx.exe .\\dist\\DeEarthX.exe",
|
||||
"build": "npm run rollup&&npm run nexe&&npm run upx",
|
||||
"test": "tsc&&node dist/main.js"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -31,9 +31,11 @@
|
||||
"@rollup/plugin-commonjs": "^28.0.6",
|
||||
"@rollup/plugin-json": "^6.1.0",
|
||||
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||
"@rollup/plugin-typescript": "^12.1.4",
|
||||
"@types/adm-zip": "^0.5.7",
|
||||
"@types/cli-progress": "^3.11.6",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/inquirer": "^9.0.8",
|
||||
"@types/yauzl": "^2.10.3",
|
||||
"nexe": "^5.0.0-beta.4",
|
||||
"rollup": "^4.44.1",
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import typescript from '@rollup/plugin-typescript'
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs'
|
||||
import json from '@rollup/plugin-json';
|
||||
/** @type {import('rollup').RollupOptions} */
|
||||
// ---cut---
|
||||
export default {
|
||||
input: 'dist/main.js',
|
||||
input: 'src/main.ts',
|
||||
output: {
|
||||
file: 'ndist/bundle.js',
|
||||
format: 'es'
|
||||
file: 'dist/bundle.js',
|
||||
format: 'esm'
|
||||
},
|
||||
plugins:[
|
||||
resolve({preferBuiltins: false}),
|
||||
typescript(),
|
||||
resolve({preferBuiltins: true}),
|
||||
commonjs(),
|
||||
json()
|
||||
]
|
||||
|
||||
114
src/main.ts
114
src/main.ts
@@ -1,26 +1,27 @@
|
||||
import inquirer from "inquirer";
|
||||
import yauzl from "yauzl";
|
||||
import process from "node:process";
|
||||
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("ndist",""),"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) {
|
||||
@@ -28,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(!fse.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
|
||||
@@ -55,20 +56,26 @@ 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(!fse.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);
|
||||
if (name.endsWith(".json")) {
|
||||
//console.log((await readzipentry(zipfile, entry)))
|
||||
pack_info = JSON.parse(
|
||||
(await readzipentry(zipfile, entry)).toString()
|
||||
);
|
||||
@@ -78,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);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import cp from "child_process";
|
||||
import fsExtra from "fs-extra/esm";
|
||||
import fsExtra from "fs-extra";
|
||||
import got from "got";
|
||||
export default async function install(
|
||||
mcver: string,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import AdmZip from "adm-zip";
|
||||
import fsExtra from "fs-extra/esm";
|
||||
import fsExtra from "fs-extra";
|
||||
import gotx from "got";
|
||||
import { xfastdownload } from "../utils/utils.js";
|
||||
import { LOGGER } from "../utils/logger.js";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import pMap from "p-map";
|
||||
import pRetry from "p-retry";
|
||||
import fs from "node:fs"
|
||||
import fse from "fs-extra"
|
||||
import yauzl from "yauzl";
|
||||
import got from "got";
|
||||
@@ -8,14 +9,16 @@ import { MultiBar } from "cli-progress";
|
||||
import {URL, fileURLToPath } from "node:url";
|
||||
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>[] = [];
|
||||
return await new Promise((reslove, reject) => {
|
||||
zipfile.openReadStream(entry, (err, e) => {
|
||||
e.on("data", (chunk: Buffer) => {
|
||||
data.push(chunk);
|
||||
}).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]})
|
||||
try{
|
||||
await pRetry(async()=>{
|
||||
if(!fse.existsSync(e[1])){
|
||||
if(!fs.existsSync(e[1])){
|
||||
await got.get(e[0],{
|
||||
responseType:"buffer",
|
||||
}).on('downloadProgress',(progress)=>{
|
||||
@@ -103,7 +106,7 @@ export async function xfastdownload(
|
||||
url !== null &&
|
||||
url !== "" &&
|
||||
path !== null &&
|
||||
!fse.existsSync(e[1])
|
||||
!fs.existsSync(e[1])
|
||||
) {
|
||||
const res = (await got.get(e[0])).rawBody; //下载文件
|
||||
await fse.outputFile(e[1], res); //保存文件
|
||||
|
||||
Reference in New Issue
Block a user