Compare commits
4 Commits
9f9cfc3e17
...
f65dea29f5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f65dea29f5 | ||
|
|
9d77fa53c7 | ||
|
|
d8d8c4051a | ||
|
|
32f7473533 |
28
src/main.ts
28
src/main.ts
@@ -5,7 +5,7 @@ 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, isInstallJava, readzipentry } from "./utils/utils.js";
|
import { type ForgeInfo, isDevelopment, isInstallJava, 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";
|
||||||
@@ -39,7 +39,7 @@ if (!argv) {
|
|||||||
|
|
||||||
function initdir() {
|
function initdir() {
|
||||||
if (!fs.existsSync(unzip_path)) {
|
if (!fs.existsSync(unzip_path)) {
|
||||||
fse.ensureDirSync(join(unzip_path, "rubbish"));
|
fse.ensureDirSync(join(unzip_path, ".rubbish"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,12 +88,13 @@ 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 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(
|
fs.writeFileSync(
|
||||||
join(dirx, "eula.txt"),
|
join(dirx, "eula.txt"),
|
||||||
"#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(QQ_Group:559349662)\neula=true"
|
"#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(QQ_Group:559349662)\neula=true"
|
||||||
);
|
);
|
||||||
|
await garcol(dirx,{minecraft_verison: info.minecraft, forge_verison: info.loader_version}).catch((e)=>{});
|
||||||
LOGGER.info("DeEarthX已将服务端制作完成!");
|
LOGGER.info("DeEarthX已将服务端制作完成!");
|
||||||
zipfile.close();
|
zipfile.close();
|
||||||
});
|
});
|
||||||
@@ -116,6 +117,9 @@ async function install(
|
|||||||
break;
|
break;
|
||||||
case "fabric-loader":
|
case "fabric-loader":
|
||||||
await fabric(minecraft, loaderver, path);
|
await fabric(minecraft, loaderver, path);
|
||||||
|
const com = "java -jar fabric-server-launch.jar"
|
||||||
|
fs.writeFileSync(join(path,'run.bat'),com)
|
||||||
|
fs.writeFileSync(join(path,'run.sh'),com)
|
||||||
break;
|
break;
|
||||||
case "forge":
|
case "forge":
|
||||||
await forge(minecraft, loaderver, path);
|
await forge(minecraft, loaderver, path);
|
||||||
@@ -126,6 +130,24 @@ async function install(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function garcol(p:string,fi:ForgeInfo): Promise<void> {
|
||||||
|
return new Promise((resolve,reject)=>{
|
||||||
|
try{
|
||||||
|
LOGGER.info("正在删除垃圾文件......")
|
||||||
|
const x = [`Forge-${fi.minecraft_verison}-${fi.forge_verison}.jar`,`installer.log`,`installer.jar`,`fabric-installer-1.0.3.jar`,`options.txt`,`shaderpacks/`,`resourcepacks/`,'essential/']
|
||||||
|
for (let i=0;i<x.length;i++){
|
||||||
|
try{
|
||||||
|
fs.rmSync(join(p, x[i]),{recursive: true, force: true})
|
||||||
|
}catch(e){}
|
||||||
|
}
|
||||||
|
resolve()
|
||||||
|
}catch(err){
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function getCurrnetDir() {
|
function getCurrnetDir() {
|
||||||
const url = new URL(".", import.meta.url);
|
const url = new URL(".", import.meta.url);
|
||||||
return fileURLToPath(url);
|
return fileURLToPath(url);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import cp from "child_process";
|
import cp from "child_process";
|
||||||
import fsExtra from "fs-extra";
|
import fsExtra from "fs-extra";
|
||||||
import got from "got";
|
import got from "got";
|
||||||
|
import { usemirror } from "../utils/utils.js";
|
||||||
export default async function install(
|
export default async function install(
|
||||||
mcver: string,
|
mcver: string,
|
||||||
fabricver: string,
|
fabricver: string,
|
||||||
@@ -8,12 +9,12 @@ export default async function install(
|
|||||||
) {
|
) {
|
||||||
const data = (
|
const data = (
|
||||||
await got.get(
|
await got.get(
|
||||||
`https://maven.fabricmc.net/net/fabricmc/fabric-installer/1.0.1/fabric-installer-1.0.1.jar`
|
`https://maven.fabricmc.net/net/fabricmc/fabric-installer/1.0.3/fabric-installer-1.0.3.jar`
|
||||||
)
|
)
|
||||||
).rawBody;
|
).rawBody;
|
||||||
fsExtra.outputFileSync(path+"/fabric-installer-1.0.1.jar", data);
|
fsExtra.outputFileSync(path+"/fabric-installer-1.0.3.jar", data);
|
||||||
cp.execSync(
|
cp.execSync(
|
||||||
`java -jar fabric-installer-1.0.1.jar server -mcver ${mcver} -loader ${fabricver}`,
|
`java -jar fabric-installer-1.0.3.jar server -mcver ${mcver} -loader ${fabricver}`,
|
||||||
{ cwd: path, stdio: "ignore" }
|
{ cwd: path, stdio: "ignore" }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ import { LOGGER } from "../utils/logger.js";
|
|||||||
|
|
||||||
const gotx = got.extend({
|
const gotx = got.extend({
|
||||||
prefixUrl: "https://bmclapi2.bangbang93.com",
|
prefixUrl: "https://bmclapi2.bangbang93.com",
|
||||||
headers: { "User-Agent": "DeEarthX V2" },
|
headers: { "User-Agent": "DeEarthX" },
|
||||||
});
|
});
|
||||||
|
|
||||||
interface mcinfoX {
|
interface mcinfoX {
|
||||||
@@ -24,12 +24,12 @@ export default async function install(
|
|||||||
) {
|
) {
|
||||||
//instance
|
//instance
|
||||||
const mcinfo = (await gotx
|
const mcinfo = (await gotx
|
||||||
.get(`version/${minecraftversion}/json`)
|
.get(`version/${minecraftversion}/json`,{ headers: { "User-Agent": "DeEarthX" } })
|
||||||
.json()) as mcinfoX; //获取Minecraft版本JSON
|
.json()) as mcinfoX; //获取Minecraft版本JSON
|
||||||
const forgepath = path;
|
const forgepath = path;
|
||||||
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`,
|
||||||
)
|
)
|
||||||
).rawBody;
|
).rawBody;
|
||||||
fse.outputFileSync(
|
fse.outputFileSync(
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { LOGGER } from "../utils/logger.js";
|
|||||||
import cp from "child_process";
|
import cp from "child_process";
|
||||||
const got = gotx.extend({
|
const got = gotx.extend({
|
||||||
prefixUrl: "https://bmclapi2.bangbang93.com",
|
prefixUrl: "https://bmclapi2.bangbang93.com",
|
||||||
headers: { "User-Agent": "DeEarthX V2" },
|
headers: { "User-Agent": "DeEarthX" },
|
||||||
});
|
});
|
||||||
|
|
||||||
interface mcinfoX {
|
interface mcinfoX {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ export class CurseForge implements XPlatform {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"x-api-key":
|
"x-api-key":
|
||||||
"$2a$10$ydk0TLDG/Gc6uPMdz7mad.iisj2TaMDytVcIW4gcVP231VKngLBKy",
|
"$2a$10$ydk0TLDG/Gc6uPMdz7mad.iisj2TaMDytVcIW4gcVP231VKngLBKy",
|
||||||
|
"User-Agent": "DeEarthX",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.json()
|
.json()
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import fs from "fs";
|
|||||||
import toml from 'smol-toml'
|
import toml from 'smol-toml'
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import pMap from "p-map";
|
import pMap from "p-map";
|
||||||
|
import { usemirror } from "./utils.js";
|
||||||
import { LOGGER } from "./logger.js";
|
import { LOGGER } from "./logger.js";
|
||||||
import { MultiBar } from "cli-progress";
|
import { MultiBar } from "cli-progress";
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ export async function DeEarthMain(modspath: string, movepath: any) {
|
|||||||
}
|
}
|
||||||
LOGGER.info(`DeEarth V1.0.0`)
|
LOGGER.info(`DeEarth V1.0.0`)
|
||||||
LOGGER.info(`如有无法筛选的mods,请前往 https://dearth.0771010.xyz/ 提交未成功筛选的模组的modid`)
|
LOGGER.info(`如有无法筛选的mods,请前往 https://dearth.0771010.xyz/ 提交未成功筛选的模组的modid`)
|
||||||
LOGGER.info(`Probejs 7.0.0以上版本为非客户端mod,如rubbish中有请自行添加回去`)
|
LOGGER.info(`Probejs 7.0.0以上版本为非客户端mod,如.rubbish中有请自行添加回去`)
|
||||||
const resaddr = fs.readdirSync(modspath)
|
const resaddr = fs.readdirSync(modspath)
|
||||||
LOGGER.info(`获取目录列表,一共${resaddr.length}个jar文件。`)
|
LOGGER.info(`获取目录列表,一共${resaddr.length}个jar文件。`)
|
||||||
const totalBar = multibar.create(resaddr.length, 0, { filename: '总文件数' })
|
const totalBar = multibar.create(resaddr.length, 0, { filename: '总文件数' })
|
||||||
@@ -136,8 +137,14 @@ export async function DeEarth(modpath: string, movepath: string) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export async function DeEarth(modpath: string, movepath: string) {
|
export async function DeEarth(modpath: string, movepath: string) {
|
||||||
|
let mrurl = "https://api.modrinth.com"
|
||||||
|
if (usemirror){
|
||||||
|
mrurl = "https://mod.mcimirror.top/modrinth"
|
||||||
|
}
|
||||||
|
|
||||||
const zipinfo = ZipInfo(modpath)
|
const zipinfo = ZipInfo(modpath)
|
||||||
let modid:string = ""
|
let modid:string = ""
|
||||||
|
if(zipinfo){
|
||||||
if(zipinfo.modinfo.type === "forge"){
|
if(zipinfo.modinfo.type === "forge"){
|
||||||
modid = zipinfo.modinfo.data.mods[0].modId
|
modid = zipinfo.modinfo.data.mods[0].modId
|
||||||
}else if(zipinfo.modinfo.type === "fabric"){
|
}else if(zipinfo.modinfo.type === "fabric"){
|
||||||
@@ -145,7 +152,7 @@ export async function DeEarth(modpath: string, movepath: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try { //Modrinth
|
try { //Modrinth
|
||||||
const body = JSON.parse(await FastGot(`https://api.modrinth.com/v2/project/${modid}`))
|
const body = JSON.parse(await FastGot(`${mrurl}/v2/project/${modid}`))
|
||||||
if(body.client_side == "required" && body.server_side !== "required"){
|
if(body.client_side == "required" && body.server_side !== "required"){
|
||||||
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
|
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
|
||||||
}
|
}
|
||||||
@@ -153,6 +160,8 @@ export async function DeEarth(modpath: string, movepath: string) {
|
|||||||
try {
|
try {
|
||||||
if (JSON.parse(await FastGot(`https://dearth.0771010.xyz/api/modid?modid=${modid}`)).isClient) {
|
if (JSON.parse(await FastGot(`https://dearth.0771010.xyz/api/modid?modid=${modid}`)).isClient) {
|
||||||
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
|
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
|
||||||
|
}else{
|
||||||
|
throw new Error("DeEarthPublic Not Found This Mod")
|
||||||
}
|
}
|
||||||
} catch (error) { //mods.toml或fabric.mod.json判断
|
} catch (error) { //mods.toml或fabric.mod.json判断
|
||||||
try{
|
try{
|
||||||
@@ -187,6 +196,7 @@ export async function DeEarth(modpath: string, movepath: string) {
|
|||||||
}catch(error){
|
}catch(error){
|
||||||
LOGGER.error(`大天才JSON写注释了估计,模组路径:${modpath},过滤失败`)
|
LOGGER.error(`大天才JSON写注释了估计,模组路径:${modpath},过滤失败`)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,6 +207,7 @@ function ZipInfo(modpath: string) {
|
|||||||
mixins: { filename: string, info: string }[]
|
mixins: { filename: string, info: string }[]
|
||||||
modinfo: {type:string,data:any};
|
modinfo: {type:string,data:any};
|
||||||
}
|
}
|
||||||
|
try{
|
||||||
let zipinfo: ZipInfo = { mixins: [], modinfo: {type: "",data: {}} }
|
let zipinfo: ZipInfo = { mixins: [], modinfo: {type: "",data: {}} }
|
||||||
const zip = new AdmZip(modpath).getEntries();
|
const zip = new AdmZip(modpath).getEntries();
|
||||||
for (let i = 0; i < zip.length; i++) {
|
for (let i = 0; i < zip.length; i++) {
|
||||||
@@ -212,6 +223,9 @@ function ZipInfo(modpath: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return zipinfo;
|
return zipinfo;
|
||||||
|
}catch(error){
|
||||||
|
LOGGER.error(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function FastGot(url: string) {
|
async function FastGot(url: string) {
|
||||||
@@ -221,7 +235,7 @@ async function FastGot(url: string) {
|
|||||||
try {
|
try {
|
||||||
if (e[0] !== null) { //防止URL为空
|
if (e[0] !== null) { //防止URL为空
|
||||||
//if(isChinaIpAddress((await got.get("https://4.ipw.cn/")).body)){
|
//if(isChinaIpAddress((await got.get("https://4.ipw.cn/")).body)){
|
||||||
return (await got.get(e[0], { headers: { "User-Agent": "DeEarth" } })).body
|
return (await got.get(e[0], { headers: { "User-Agent": "DeEarthX" } })).body
|
||||||
//}else{
|
//}else{
|
||||||
//return (await got.get(`https://mod.mcimirror.top/modrinth/${new URL(e[0]).pathname}`, { headers: { "User-Agent": "DeEarth" } })).body //MCIM源
|
//return (await got.get(`https://mod.mcimirror.top/modrinth/${new URL(e[0]).pathname}`, { headers: { "User-Agent": "DeEarth" } })).body //MCIM源
|
||||||
//}
|
//}
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ import { URL, fileURLToPath } from "node:url";
|
|||||||
import { LOGGER } from "./logger.js";
|
import { LOGGER } from "./logger.js";
|
||||||
import { exec } from "node:child_process";
|
import { exec } from "node:child_process";
|
||||||
|
|
||||||
|
export interface ForgeInfo{
|
||||||
|
minecraft_verison: string,
|
||||||
|
forge_verison: string
|
||||||
|
}
|
||||||
|
|
||||||
export async function readzipentry(
|
export async function readzipentry(
|
||||||
zipfile: yauzl.ZipFile,
|
zipfile: yauzl.ZipFile,
|
||||||
entry: yauzl.Entry
|
entry: yauzl.Entry
|
||||||
@@ -148,7 +153,11 @@ export async function xfastdownload(
|
|||||||
path !== null &&
|
path !== null &&
|
||||||
!fs.existsSync(e[1])
|
!fs.existsSync(e[1])
|
||||||
) {
|
) {
|
||||||
const res = (await got.get(e[0])).rawBody; //下载文件
|
const res = (await got.get(e[0],{
|
||||||
|
headers: {
|
||||||
|
"user-agent": "DeEarthX"
|
||||||
|
}
|
||||||
|
})).rawBody; //下载文件
|
||||||
await fse.outputFile(e[1], res); //保存文件
|
await fse.outputFile(e[1], res); //保存文件
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user