feat:最终成品
This commit is contained in:
@@ -9,8 +9,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"tsbuild": "tsc",
|
"tsbuild": "tsc",
|
||||||
"rollup": "rollup -c rollup.config.js",
|
"rollup": "rollup -c rollup.config.js",
|
||||||
"nexe": "nexe -i ./ndist/main.js --ico Dex.ico --build -t x86-22.13.0 --output ./ndist/main.exe",
|
"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\\main.exe",
|
"upx": ".\\dist_modules\\upx.exe .\\ndist\\DeEarthX.exe",
|
||||||
"build": "npm run tsbuild&&npm run rollup&&npm run nexe&&npm run upx",
|
"build": "npm run tsbuild&&npm run rollup&&npm run nexe&&npm run upx",
|
||||||
"test": "tsc&&node dist/main.js"
|
"test": "tsc&&node dist/main.js"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ interface Answers {
|
|||||||
}
|
}
|
||||||
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(),"instance")
|
unzip_path = join(getCurrnetDir().replace("ndist",""),"instance")
|
||||||
}
|
}
|
||||||
let zipnamew: string = ""
|
let zipnamew: string = ""
|
||||||
const argv = process.argv.slice(2)[0];
|
const argv = process.argv.slice(2)[0];
|
||||||
@@ -60,6 +60,7 @@ async function main(modpack_path: string) {
|
|||||||
zipfile.openReadStream(entry,(err,stream)=>{ //读取overrides文件夹下的所有文件和文件夹
|
zipfile.openReadStream(entry,(err,stream)=>{ //读取overrides文件夹下的所有文件和文件夹
|
||||||
const dir = dirname(zipfilex)
|
const dir = dirname(zipfilex)
|
||||||
fse.ensureDirSync(dir);
|
fse.ensureDirSync(dir);
|
||||||
|
console.log(zipfilex)
|
||||||
stream.pipe(fse.createWriteStream(zipfilex))
|
stream.pipe(fse.createWriteStream(zipfilex))
|
||||||
})
|
})
|
||||||
//console.log(entry.fileName)
|
//console.log(entry.fileName)
|
||||||
@@ -67,7 +68,7 @@ async function main(modpack_path: string) {
|
|||||||
} else {
|
} else {
|
||||||
const name: string = entry.fileName;
|
const name: string = entry.fileName;
|
||||||
dud_files.push(name);
|
dud_files.push(name);
|
||||||
if (name && name.endsWith(".json")) {
|
if (name.endsWith(".json")) {
|
||||||
pack_info = JSON.parse(
|
pack_info = JSON.parse(
|
||||||
(await readzipentry(zipfile, entry)).toString()
|
(await readzipentry(zipfile, entry)).toString()
|
||||||
);
|
);
|
||||||
@@ -81,8 +82,8 @@ async function main(modpack_path: string) {
|
|||||||
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 install(info.loader,info.minecraft,info.loader_version,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)
|
||||||
LOGGER.info("DeEarthX已将服务端制作完成!");
|
LOGGER.info("DeEarthX已将服务端制作完成!");
|
||||||
zipfile.close();
|
zipfile.close();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ export default async function install(
|
|||||||
.get(`version/${minecraftversion}/json`)
|
.get(`version/${minecraftversion}/json`)
|
||||||
.json()) as mcinfoX; //获取Minecraft版本JSON
|
.json()) as mcinfoX; //获取Minecraft版本JSON
|
||||||
const forgepath = path;
|
const forgepath = path;
|
||||||
console.log(loaderversion)
|
|
||||||
const forgedata = (
|
const forgedata = (
|
||||||
await gotx.get(
|
await gotx.get(
|
||||||
`forge/download?mcversion=${minecraftversion}&version=${loaderversion}&category=installer&format=jar`
|
`forge/download?mcversion=${minecraftversion}&version=${loaderversion}&category=installer&format=jar`
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import got from "got";
|
import got from "got";
|
||||||
|
import { join } from "node:path";
|
||||||
import { fastdownload, usemirror } from "../utils/utils.js";
|
import { fastdownload, usemirror } from "../utils/utils.js";
|
||||||
import { modpack_info, XPlatform } from "./index.js";
|
import { modpack_info, XPlatform } from "./index.js";
|
||||||
|
|
||||||
const cf_url = (()=>{if(usemirror){return "https://mod.mcimirror.top/curseforge"}else{return "https://api.curseforge.com"}})()
|
const cf_url = (() => {
|
||||||
|
if (usemirror) {
|
||||||
|
return "https://mod.mcimirror.top/curseforge";
|
||||||
|
} else {
|
||||||
|
return "https://api.curseforge.com";
|
||||||
|
}
|
||||||
|
})();
|
||||||
export interface CurseForgeManifest {
|
export interface CurseForgeManifest {
|
||||||
minecraft: {
|
minecraft: {
|
||||||
version: string;
|
version: string;
|
||||||
@@ -18,9 +25,7 @@ export class CurseForge implements XPlatform {
|
|||||||
if (result && local_manifest)
|
if (result && local_manifest)
|
||||||
result.minecraft = local_manifest.minecraft.version;
|
result.minecraft = local_manifest.minecraft.version;
|
||||||
const id = local_manifest.minecraft.modLoaders[0].id;
|
const id = local_manifest.minecraft.modLoaders[0].id;
|
||||||
const loader_all = id.match(
|
const loader_all = id.match(/(.*)-/) as RegExpMatchArray;
|
||||||
/(.*)-/
|
|
||||||
) as RegExpMatchArray;
|
|
||||||
result.loader = loader_all[1];
|
result.loader = loader_all[1];
|
||||||
result.loader_version = id.replace(loader_all[0], "");
|
result.loader_version = id.replace(loader_all[0], "");
|
||||||
return result;
|
return result;
|
||||||
@@ -29,27 +34,39 @@ export class CurseForge implements XPlatform {
|
|||||||
async downloadfile(manifest: object, path: string): Promise<void> {
|
async downloadfile(manifest: object, path: string): Promise<void> {
|
||||||
const local_manifest = manifest as CurseForgeManifest;
|
const local_manifest = manifest as CurseForgeManifest;
|
||||||
const FileID = JSON.stringify({
|
const FileID = JSON.stringify({
|
||||||
fileIds: local_manifest.files.map((file: { fileID: number; }) => file.fileID),
|
fileIds: local_manifest.files.map(
|
||||||
|
(file: { fileID: number }) => file.fileID
|
||||||
|
),
|
||||||
});
|
});
|
||||||
let tmp: [string, string] | string[][] = [];
|
let tmp: [string, string] | string[][] = [];
|
||||||
await got.post(cf_url+"/v1/mods/files",{
|
await got
|
||||||
|
.post(cf_url + "/v1/mods/files", {
|
||||||
body: FileID,
|
body: FileID,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"x-api-key":"$2a$10$ydk0TLDG/Gc6uPMdz7mad.iisj2TaMDytVcIW4gcVP231VKngLBKy"
|
"x-api-key":
|
||||||
}
|
"$2a$10$ydk0TLDG/Gc6uPMdz7mad.iisj2TaMDytVcIW4gcVP231VKngLBKy",
|
||||||
}).json().then((res:any)=>{
|
},
|
||||||
res.data.forEach((e: { fileName: string; downloadUrl: null|string; }) => {
|
})
|
||||||
|
.json()
|
||||||
|
.then((res: any) => {
|
||||||
|
res.data.forEach(
|
||||||
|
(e: { fileName: string; downloadUrl: null | string }) => {
|
||||||
if (e.fileName.endsWith(".zip") || e.downloadUrl == null) {
|
if (e.fileName.endsWith(".zip") || e.downloadUrl == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const unpath = join(path + "/mods/", e.fileName);
|
||||||
if (usemirror) {
|
if (usemirror) {
|
||||||
tmp.push(["https://mod.mcimirror.top"+new URL(e.downloadUrl).pathname,path+"/mods/" + e.fileName])
|
tmp.push([
|
||||||
|
"https://mod.mcimirror.top" + new URL(e.downloadUrl).pathname,
|
||||||
|
unpath,
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
tmp.push([e.downloadUrl,path+"/mods/" + e.fileName])
|
tmp.push([e.downloadUrl, unpath]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
})
|
await fastdownload(tmp as unknown as [string, string]); //下载文件
|
||||||
await fastdownload(tmp as unknown as [string, string]) //下载文件
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ export function platform(plat: string | undefined): XPlatform {
|
|||||||
break;
|
break;
|
||||||
case "modrinth":
|
case "modrinth":
|
||||||
platform = new Modrinth();
|
platform = new Modrinth();
|
||||||
|
break;
|
||||||
case "mcbbs":
|
case "mcbbs":
|
||||||
platform = new MCBBS();
|
platform = new MCBBS();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return platform;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,10 @@ export class MCBBS implements XPlatform {
|
|||||||
const local_manifest = manifest as MCBBSManifest;
|
const local_manifest = manifest as MCBBSManifest;
|
||||||
if (result && local_manifest)
|
if (result && local_manifest)
|
||||||
result.minecraft = local_manifest.minecraft.version;
|
result.minecraft = local_manifest.minecraft.version;
|
||||||
const loader_all = local_manifest.minecraft.modLoaders[0].id.match(
|
const id = local_manifest.minecraft.modLoaders[0].id;
|
||||||
/(.*)-/
|
const loader_all = id.match(/(.*)-/) as RegExpMatchArray;
|
||||||
) as RegExpMatchArray;
|
|
||||||
result.loader = loader_all[1];
|
result.loader = loader_all[1];
|
||||||
result.loader_version = loader_all[0];
|
result.loader_version = id.replace(loader_all[0], "");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import { mr_fastdownload, usemirror } from "../utils/utils.js";
|
import { mr_fastdownload, usemirror } from "../utils/utils.js";
|
||||||
import { modpack_info, XPlatform } from "./index.js";
|
import { modpack_info, XPlatform } from "./index.js";
|
||||||
|
import { join } from "node:path";
|
||||||
|
|
||||||
interface ModrinthManifest {
|
interface ModrinthManifest {
|
||||||
files: Array<{ path: string; downloads: string[]; fileSize: number; }>;
|
files: Array<{ path: string; downloads: string[]; fileSize: number; }>;
|
||||||
@@ -36,10 +37,11 @@ export class Modrinth implements XPlatform {
|
|||||||
if (e.path.endsWith(".zip")) {
|
if (e.path.endsWith(".zip")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const unpath = join(path,e.path)
|
||||||
if (usemirror){
|
if (usemirror){
|
||||||
tmp.push(["https://mod.mcimirror.top"+new URL(e.downloads[0]).pathname,path+e.path,String(e.fileSize)])
|
tmp.push(["https://mod.mcimirror.top"+new URL(e.downloads[0]).pathname,unpath,String(e.fileSize)])
|
||||||
}else{
|
}else{
|
||||||
tmp.push([e.downloads[0],path + e.path,String(e.fileSize)])
|
tmp.push([e.downloads[0],unpath,String(e.fileSize)])
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await mr_fastdownload(tmp as unknown as [string, string, string])
|
await mr_fastdownload(tmp as unknown as [string, string, string])
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export async function fastdownload(data:[string,string]){
|
|||||||
})
|
})
|
||||||
const totalBar = multibar.create(data.length, 0, {filename: '总文件数'})
|
const totalBar = multibar.create(data.length, 0, {filename: '总文件数'})
|
||||||
return await pMap(data,async(e)=>{
|
return await pMap(data,async(e)=>{
|
||||||
const size:number = await (async()=>{const head = (await got.head(e[0])).headers['content-length'];if(head){return Number(head)}else{return 0}})()
|
const size:number = await (async()=>{const head = (await got.head(e[0].replace("https://mod.mcimirror.top","https://edge.forgecdn.net"))).headers['content-length'];if(head){return Number(head)}else{return 0}})()
|
||||||
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()=>{
|
||||||
@@ -124,7 +124,7 @@ export async function xfastdownload(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const usemirror = (()=>{
|
export const usemirror = (()=>{
|
||||||
env.config()
|
env.config({debug:false})
|
||||||
const mirror = process.env.MIRROR
|
const mirror = process.env.MIRROR
|
||||||
if(mirror){
|
if(mirror){
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user