feat:首次提交(无法使用)

This commit is contained in:
Tianpao
2025-07-02 19:52:56 +08:00
parent fc20a736c4
commit 839d208029
15 changed files with 772 additions and 35 deletions

3
.gitignore vendored
View File

@@ -132,3 +132,6 @@ ndist
.yarn/install-state.gz
.pnp.*
# test files
*.zip
*.mrpack

320
package-lock.json generated
View File

@@ -9,16 +9,25 @@
"version": "2.0.0",
"license": "ISC",
"dependencies": {
"adm-zip": "^0.5.16",
"chalk": "^5.4.1",
"cli-progress": "^3.12.0",
"fs-extra": "^11.3.0",
"got": "^14.4.7",
"inquirer": "^12.6.3",
"minizlib": "^3.0.2",
"p-map": "^7.0.3",
"p-retry": "^6.2.1"
"p-retry": "^6.2.1",
"toml": "^3.0.0",
"yauzl": "^3.2.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^28.0.6",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.1",
"@types/adm-zip": "^0.5.7",
"@types/cli-progress": "^3.11.6",
"@types/fs-extra": "^11.0.4",
"@types/yauzl": "^2.10.3",
"nexe": "^5.0.0-beta.4",
"rollup": "^4.44.1",
"typescript": "^5.8.3"
@@ -445,6 +454,143 @@
"node": ">= 8"
}
},
"node_modules/@rollup/plugin-commonjs": {
"version": "28.0.6",
"resolved": "https://registry.npmmirror.com/@rollup/plugin-commonjs/-/plugin-commonjs-28.0.6.tgz",
"integrity": "sha512-XSQB1K7FUU5QP+3lOQmVCE3I0FcbbNvmNT4VJSj93iUjayaARrTQeoRdiYQoftAJBLrR9t2agwAd3ekaTgHNlw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@rollup/pluginutils": "^5.0.1",
"commondir": "^1.0.1",
"estree-walker": "^2.0.2",
"fdir": "^6.2.0",
"is-reference": "1.2.1",
"magic-string": "^0.30.3",
"picomatch": "^4.0.2"
},
"engines": {
"node": ">=16.0.0 || 14 >= 14.17"
},
"peerDependencies": {
"rollup": "^2.68.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
}
},
"node_modules/@rollup/plugin-commonjs/node_modules/fdir": {
"version": "6.4.6",
"resolved": "https://registry.npmmirror.com/fdir/-/fdir-6.4.6.tgz",
"integrity": "sha512-hiFoqpyZcfNm1yc4u8oWCf9A2c4D3QjCrks3zmoVKVxpQRzmPNar1hUJcBG2RQHvEVGDN+Jm81ZheVLAQMK6+w==",
"dev": true,
"license": "MIT",
"peerDependencies": {
"picomatch": "^3 || ^4"
},
"peerDependenciesMeta": {
"picomatch": {
"optional": true
}
}
},
"node_modules/@rollup/plugin-commonjs/node_modules/picomatch": {
"version": "4.0.2",
"resolved": "https://registry.npmmirror.com/picomatch/-/picomatch-4.0.2.tgz",
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/@rollup/plugin-json": {
"version": "6.1.0",
"resolved": "https://registry.npmmirror.com/@rollup/plugin-json/-/plugin-json-6.1.0.tgz",
"integrity": "sha512-EGI2te5ENk1coGeADSIwZ7G2Q8CJS2sF120T7jLw4xFw9n7wIOXHo+kIYRAoVpJAN+kmqZSoO3Fp4JtoNF4ReA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@rollup/pluginutils": "^5.1.0"
},
"engines": {
"node": ">=14.0.0"
},
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
}
},
"node_modules/@rollup/plugin-node-resolve": {
"version": "16.0.1",
"resolved": "https://registry.npmmirror.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-16.0.1.tgz",
"integrity": "sha512-tk5YCxJWIG81umIvNkSod2qK5KyQW19qcBF/B78n1bjtOON6gzKoVeSzAE8yHCZEDmqkHKkxplExA8KzdJLJpA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@rollup/pluginutils": "^5.0.1",
"@types/resolve": "1.20.2",
"deepmerge": "^4.2.2",
"is-module": "^1.0.0",
"resolve": "^1.22.1"
},
"engines": {
"node": ">=14.0.0"
},
"peerDependencies": {
"rollup": "^2.78.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
}
},
"node_modules/@rollup/pluginutils": {
"version": "5.2.0",
"resolved": "https://registry.npmmirror.com/@rollup/pluginutils/-/pluginutils-5.2.0.tgz",
"integrity": "sha512-qWJ2ZTbmumwiLFomfzTyt5Kng4hwPi9rwCYN4SHb6eaRU1KNO4ccxINHr/VhH4GgPlt1XfSTLX2LBTme8ne4Zw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/estree": "^1.0.0",
"estree-walker": "^2.0.2",
"picomatch": "^4.0.2"
},
"engines": {
"node": ">=14.0.0"
},
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
}
},
"node_modules/@rollup/pluginutils/node_modules/picomatch": {
"version": "4.0.2",
"resolved": "https://registry.npmmirror.com/picomatch/-/picomatch-4.0.2.tgz",
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/@rollup/rollup-android-arm-eabi": {
"version": "4.44.1",
"resolved": "https://registry.npmmirror.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.44.1.tgz",
@@ -755,6 +901,26 @@
"node": ">=14.16"
}
},
"node_modules/@types/adm-zip": {
"version": "0.5.7",
"resolved": "https://registry.npmmirror.com/@types/adm-zip/-/adm-zip-0.5.7.tgz",
"integrity": "sha512-DNEs/QvmyRLurdQPChqq0Md4zGvPwHerAJYWk9l2jCbD1VPpnzRJorOdiq4zsw09NFbYnhfsoEhWtxIzXpn2yw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/cli-progress": {
"version": "3.11.6",
"resolved": "https://registry.npmmirror.com/@types/cli-progress/-/cli-progress-3.11.6.tgz",
"integrity": "sha512-cE3+jb9WRlu+uOSAugewNpITJDt1VF8dHOopPO4IABFc3SXYL5WE/+PTz/FCdZRRfIujiWW3n3aMbv1eIGVRWA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/emscripten": {
"version": "1.40.1",
"resolved": "https://registry.npmmirror.com/@types/emscripten/-/emscripten-1.40.1.tgz",
@@ -791,6 +957,17 @@
"dev": true,
"license": "MIT"
},
"node_modules/@types/fs-extra": {
"version": "11.0.4",
"resolved": "https://registry.npmmirror.com/@types/fs-extra/-/fs-extra-11.0.4.tgz",
"integrity": "sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/jsonfile": "*",
"@types/node": "*"
}
},
"node_modules/@types/http-cache-semantics": {
"version": "4.0.4",
"resolved": "https://registry.npmmirror.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz",
@@ -804,6 +981,16 @@
"dev": true,
"license": "MIT"
},
"node_modules/@types/jsonfile": {
"version": "6.1.4",
"resolved": "https://registry.npmmirror.com/@types/jsonfile/-/jsonfile-6.1.4.tgz",
"integrity": "sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/node": {
"version": "24.0.8",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-24.0.8.tgz",
@@ -814,6 +1001,13 @@
"undici-types": "~7.8.0"
}
},
"node_modules/@types/resolve": {
"version": "1.20.2",
"resolved": "https://registry.npmmirror.com/@types/resolve/-/resolve-1.20.2.tgz",
"integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/retry": {
"version": "0.12.2",
"resolved": "https://registry.npmmirror.com/@types/retry/-/retry-0.12.2.tgz",
@@ -881,6 +1075,16 @@
"node": ">= 8"
}
},
"node_modules/@types/yauzl": {
"version": "2.10.3",
"resolved": "https://registry.npmmirror.com/@types/yauzl/-/yauzl-2.10.3.tgz",
"integrity": "sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@webassemblyjs/ast": {
"version": "1.14.1",
"resolved": "https://registry.npmmirror.com/@webassemblyjs/ast/-/ast-1.14.1.tgz",
@@ -1147,6 +1351,15 @@
"node": ">=0.4.0"
}
},
"node_modules/adm-zip": {
"version": "0.5.16",
"resolved": "https://registry.npmmirror.com/adm-zip/-/adm-zip-0.5.16.tgz",
"integrity": "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ==",
"license": "MIT",
"engines": {
"node": ">=12.0"
}
},
"node_modules/ajv": {
"version": "8.17.1",
"resolved": "https://registry.npmmirror.com/ajv/-/ajv-8.17.1.tgz",
@@ -1540,7 +1753,6 @@
"version": "0.2.13",
"resolved": "https://registry.npmmirror.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
"integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": "*"
@@ -1825,6 +2037,13 @@
"dev": true,
"license": "MIT"
},
"node_modules/commondir": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/commondir/-/commondir-1.0.1.tgz",
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==",
"dev": true,
"license": "MIT"
},
"node_modules/compress-commons": {
"version": "4.1.2",
"resolved": "https://registry.npmmirror.com/compress-commons/-/compress-commons-4.1.2.tgz",
@@ -2198,6 +2417,17 @@
"node": ">=0.10.0"
}
},
"node_modules/decompress-unzip/node_modules/yauzl": {
"version": "2.10.0",
"resolved": "https://registry.npmmirror.com/yauzl/-/yauzl-2.10.0.tgz",
"integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==",
"dev": true,
"license": "MIT",
"dependencies": {
"buffer-crc32": "~0.2.3",
"fd-slicer": "~1.1.0"
}
},
"node_modules/decompress/node_modules/make-dir": {
"version": "1.3.0",
"resolved": "https://registry.npmmirror.com/make-dir/-/make-dir-1.3.0.tgz",
@@ -2231,6 +2461,16 @@
"node": ">=0.10.0"
}
},
"node_modules/deepmerge": {
"version": "4.3.1",
"resolved": "https://registry.npmmirror.com/deepmerge/-/deepmerge-4.3.1.tgz",
"integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/defaults": {
"version": "1.0.4",
"resolved": "https://registry.npmmirror.com/defaults/-/defaults-1.0.4.tgz",
@@ -2699,6 +2939,13 @@
"node": ">=4.0"
}
},
"node_modules/estree-walker": {
"version": "2.0.2",
"resolved": "https://registry.npmmirror.com/estree-walker/-/estree-walker-2.0.2.tgz",
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"dev": true,
"license": "MIT"
},
"node_modules/events": {
"version": "3.3.0",
"resolved": "https://registry.npmmirror.com/events/-/events-3.3.0.tgz",
@@ -3510,6 +3757,13 @@
"node": ">=0.10.0"
}
},
"node_modules/is-module": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/is-module/-/is-module-1.0.0.tgz",
"integrity": "sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==",
"dev": true,
"license": "MIT"
},
"node_modules/is-natural-number": {
"version": "4.0.1",
"resolved": "https://registry.npmmirror.com/is-natural-number/-/is-natural-number-4.0.1.tgz",
@@ -3572,6 +3826,16 @@
"node": ">=0.10.0"
}
},
"node_modules/is-reference": {
"version": "1.2.1",
"resolved": "https://registry.npmmirror.com/is-reference/-/is-reference-1.2.1.tgz",
"integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/estree": "*"
}
},
"node_modules/is-retry-allowed": {
"version": "1.2.0",
"resolved": "https://registry.npmmirror.com/is-retry-allowed/-/is-retry-allowed-1.2.0.tgz",
@@ -3891,6 +4155,16 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/magic-string": {
"version": "0.30.17",
"resolved": "https://registry.npmmirror.com/magic-string/-/magic-string-0.30.17.tgz",
"integrity": "sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@jridgewell/sourcemap-codec": "^1.5.0"
}
},
"node_modules/make-dir": {
"version": "2.1.0",
"resolved": "https://registry.npmmirror.com/make-dir/-/make-dir-2.1.0.tgz",
@@ -4034,27 +4308,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/minipass": {
"version": "7.1.2",
"resolved": "https://registry.npmmirror.com/minipass/-/minipass-7.1.2.tgz",
"integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==",
"license": "ISC",
"engines": {
"node": ">=16 || 14 >=14.17"
}
},
"node_modules/minizlib": {
"version": "3.0.2",
"resolved": "https://registry.npmmirror.com/minizlib/-/minizlib-3.0.2.tgz",
"integrity": "sha512-oG62iEk+CYt5Xj2YqI5Xi9xWUeZhDI8jjQmC5oThVH5JGCTgIjr7ciJDzC7MBzYd//WvR1OTmP5Q38Q8ShQtVA==",
"license": "MIT",
"dependencies": {
"minipass": "^7.1.2"
},
"engines": {
"node": ">= 18"
}
},
"node_modules/mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmmirror.com/mkdirp/-/mkdirp-1.0.4.tgz",
@@ -4551,7 +4804,6 @@
"version": "1.2.0",
"resolved": "https://registry.npmmirror.com/pend/-/pend-1.2.0.tgz",
"integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==",
"dev": true,
"license": "MIT"
},
"node_modules/picocolors": {
@@ -5523,6 +5775,12 @@
"node": ">=8.0"
}
},
"node_modules/toml": {
"version": "3.0.0",
"resolved": "https://registry.npmmirror.com/toml/-/toml-3.0.0.tgz",
"integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==",
"license": "MIT"
},
"node_modules/trim-repeated": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/trim-repeated/-/trim-repeated-1.0.0.tgz",
@@ -6104,14 +6362,16 @@
}
},
"node_modules/yauzl": {
"version": "2.10.0",
"resolved": "https://registry.npmmirror.com/yauzl/-/yauzl-2.10.0.tgz",
"integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==",
"dev": true,
"version": "3.2.0",
"resolved": "https://registry.npmmirror.com/yauzl/-/yauzl-3.2.0.tgz",
"integrity": "sha512-Ow9nuGZE+qp1u4JIPvg+uCiUr7xGQWdff7JQSk5VGYTAZMDe2q8lxJ10ygv10qmSj031Ty/6FNJpLO4o1Sgc+w==",
"license": "MIT",
"dependencies": {
"buffer-crc32": "~0.2.3",
"fd-slicer": "~1.1.0"
"pend": "~1.2.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/yoctocolors-cjs": {

View File

@@ -8,23 +8,32 @@
"main": "main.js",
"scripts": {
"tsbuild": "tsc",
"rollup":"rollup",
"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",
"upx": ".\\.dist_modules\\upx.exe .\\ndist\\main.exe",
"build": "npm run tsbuild&&npm run rollup&&npm run nexe&&npm run upx",
"test": "tsc&&node dist/main.js"
},
"dependencies": {
"adm-zip": "^0.5.16",
"chalk": "^5.4.1",
"cli-progress": "^3.12.0",
"fs-extra": "^11.3.0",
"got": "^14.4.7",
"inquirer": "^12.6.3",
"minizlib": "^3.0.2",
"p-map": "^7.0.3",
"p-retry": "^6.2.1"
"p-retry": "^6.2.1",
"toml": "^3.0.0",
"yauzl": "^3.2.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^28.0.6",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.1",
"@types/adm-zip": "^0.5.7",
"@types/cli-progress": "^3.11.6",
"@types/fs-extra": "^11.0.4",
"@types/yauzl": "^2.10.3",
"nexe": "^5.0.0-beta.4",
"rollup": "^4.44.1",
"typescript": "^5.8.3"

View File

@@ -1,9 +1,17 @@
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',
output: {
file: 'bundle.js',
file: 'ndist/bundle.js',
format: 'es'
}
},
plugins:[
resolve({preferBuiltins: false}),
commonjs(),
json()
]
};

59
src/main.ts Normal file
View File

@@ -0,0 +1,59 @@
import inquirer from "inquirer";
import yauzl from "yauzl";
import process from "node:process";
import { join, basename } from "node:path";
import { platform, what_platform } from "./platform/index.js";
import { readzipentry } from "./utils/utils.js";
interface Answers {
modpack_path: string | undefined;
}
const unzip_path = "./instance";
const argv = process.argv.slice(2)[0];
if (!argv) {
const answer: Answers = await inquirer.prompt([
{ type: "input", name: "modpack_path", message: "请输入整合包路径" },
]);
if (answer.modpack_path) {
await main(answer.modpack_path);
}
} else {
await main(argv);
}
async function main(modpack_path: string) {
const zipname = basename(modpack_path)
.replace(".zip", "")
.replace(".mrpack", "");
let dud_files: Array<string> = [];
let pack_info: object;
//unzip
yauzl.open(modpack_path, { lazyEntries: true }, (err, zipfile) => {
zipfile.readEntry(); //首次读取
zipfile.on("entry", async (entry) => {
if (/\/$/.test(entry.fileName)) {
} else if (entry.fileName.includes("overrides/")) {
/*zipfile.openReadStream(entry,(err,stream)=>{ //读取overrides文件夹下的所有文件和文件夹
})*/
//console.log(entry.fileName)
} else {
const name: string = entry.fileName;
dud_files.push(name);
if (name && name.endsWith(".json")) {
pack_info = JSON.parse(
(await readzipentry(zipfile, entry)).toString()
);
}
console.log(name);
}
zipfile.readEntry();
});
zipfile.on("end", () => {
//zip
platform(what_platform(dud_files));
//console.log(dud_files)
zipfile.close();
});
});
}

0
src/ml_install/fabric.ts Normal file
View File

0
src/ml_install/forge.ts Normal file
View File

View File

View File

@@ -0,0 +1,28 @@
import { fastdownload } from "../utils/utils.js";
import { modpack_info, XPlatform } from "./index.js";
export interface CurseForgeManifest {
minecraft: {
version: string;
modLoaders: Array<{ id: string }>;
};
}
export class CurseForge implements XPlatform {
async getinfo(manifest: object): Promise<modpack_info> {
let result: modpack_info = Object.create({});
const local_manifest = manifest as CurseForgeManifest;
if (result && local_manifest)
result.minecraft = local_manifest.minecraft.version;
const loader_all = local_manifest.minecraft.modLoaders[0].id.match(
/(.*)-/
) as RegExpMatchArray;
result.loader = loader_all[1];
result.loader_version = loader_all[0];
return result;
}
async downloadfile(urls: [string, string]): Promise<void> {
await fastdownload(urls);
}
}

42
src/platform/index.ts Normal file
View File

@@ -0,0 +1,42 @@
import { CurseForge } from "./curseforge.js";
import { MCBBS } from "./mcbbs.js";
import { Modrinth } from "./modrinth.js";
export interface XPlatform {
getinfo(manifest: object): Promise<modpack_info>;
downloadfile(
urls: [string, string] | [string, string, string]
): Promise<void>;
}
export interface modpack_info {
minecraft: string;
loader: string;
loader_version: string;
}
export function platform(plat: string | undefined): XPlatform {
let platform: XPlatform = Object.create({});
switch (plat) {
case "curseforge":
platform = new CurseForge();
break;
case "modrinth":
platform = new Modrinth();
case "mcbbs":
platform = new MCBBS();
}
return platform;
}
export function what_platform(dud_files: Array<string>) {
if (dud_files.includes("mcbbs.packmeta")) {
return "mcbbs";
} else if (dud_files.includes("manifest.json")) {
return "curseforge";
} else if (dud_files.includes("modrinth.index.json")) {
return "modrinth";
} else {
return undefined;
}
}

21
src/platform/mcbbs.ts Normal file
View File

@@ -0,0 +1,21 @@
import { CurseForgeManifest } from "./curseforge.js";
import { modpack_info, XPlatform } from "./index.js";
interface MCBBSManifest extends CurseForgeManifest {}
export class MCBBS implements XPlatform {
async getinfo(manifest: object): Promise<modpack_info> {
const result: modpack_info = Object.create({});
const local_manifest = manifest as MCBBSManifest;
if (result && local_manifest)
result.minecraft = local_manifest.minecraft.version;
const loader_all = local_manifest.minecraft.modLoaders[0].id.match(
/(.*)-/
) as RegExpMatchArray;
result.loader = loader_all[1];
result.loader_version = loader_all[0];
return result;
}
async downloadfile(urls: [string, string]): Promise<void> {}
}

33
src/platform/modrinth.ts Normal file
View File

@@ -0,0 +1,33 @@
import { mr_fastdownload } from "../utils/utils.js";
import { modpack_info, XPlatform } from "./index.js";
interface ModrinthManifest {
dependencies: {
minecraft: string;
forge: string;
neoforge: string;
"fabric-loader": string;
[key: string]: string;
};
}
export class Modrinth implements XPlatform {
async getinfo(manifest: object): Promise<modpack_info> {
let result: modpack_info = Object.create({});
const local_manifest = manifest as ModrinthManifest;
const depkey = Object.keys(local_manifest.dependencies);
const loader = ["forge", "neoforge", "fabric-loader"];
result.minecraft = local_manifest.dependencies.minecraft;
for (let i = 0; i < depkey.length; i++) {
const key = depkey[i];
if (key !== "minecraft" && loader.includes(key)) {
result.loader = key;
result.loader_version = local_manifest.dependencies[key];
}
}
return result;
}
async downloadfile(urls: [string, string, string]): Promise<void> {
await mr_fastdownload(urls);
}
}

145
src/utils/DeEarth.ts Normal file
View File

@@ -0,0 +1,145 @@
/* Power by.Tianpao
* 本工具可能会判断失误,但也能为您节省不少时间!
* DeEarth V2 From StarNet.X
* Writing in 03.29.2025(latest)
* ©2024-2025
*/
import AdmZip from "adm-zip";
import got from "got";
import fs from "fs";
import toml from 'toml';
import path from 'path';
import pMap from "p-map";
import { LOGGER } from "./logger.js";
import { MultiBar } from "cli-progress";
export async function DeEarthMain(modspath: string, movepath: any) {
if(!fs.existsSync(movepath)){
fs.mkdirSync(movepath)
}
LOGGER.info(`DeEarth V1.0.0`)
const resaddr = fs.readdirSync(modspath)
LOGGER.info(`获取目录列表,一共${resaddr.length}个jar文件。`)
const totalBar = multibar.create(resaddr.length, 0, { filename: '总文件数' })
for (let i = 0; i < resaddr.length; i++) {
const e = `${modspath}/${resaddr[i]}`
if (e.endsWith(".jar") && fs.statSync(e).isFile()) { //判断是否以.jar结尾并且是文件
//console.log(e)
await DeEarth(e, movepath) //使用DeEarth进行审查mod并移动
totalBar.increment()
}
}
multibar.stop()
}
export async function DeEarth(modpath: string, movepath: string) {
const zip = new AdmZip(modpath).getEntries();
//for (let i = 0; i < zip.length; i++) {
//const e = zip[i]
try { //Modrinth
for (let i = 0; i < zip.length; i++) {
const e = zip[i]
if (e.entryName == "META-INF/mods.toml") { //Forge,NeoForge
const modid = toml.parse(e.getData().toString('utf-8')).mods[0].modId
//const body = await got.get(`https://api.modrinth.com/v2/project/${modid}`, { headers: { "User-Agent": "DeEarth" } }).json()
const body = JSON.parse(await FastGot(`https://api.modrinth.com/v2/project/${modid}`))
if (body.client_side == "required" && body.server_side == "unsupported") {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
} else if (e.entryName == "fabric.mod.json") { //Fabric
const modid = JSON.parse(e.getData().toString('utf-8')).id
//const body = await got.get(`https://api.modrinth.com/v2/project/${modid}`, { headers: { "User-Agent": "DeEarth" } }).json()
const body = JSON.parse(await FastGot(`https://api.modrinth.com/v2/project/${modid}`))
if (body.client_side == "required" && body.server_side == "unsupported") {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
}
}
} catch (error) { //mods.toml或fabric.mod.json判断
for (let i = 0; i < zip.length; i++) {
const e = zip[i]
try {
if (e.entryName == "META-INF/mods.toml") { //Forge,Neoforge
const tr = toml.parse(e.getData().toString('utf-8'))
const mcside = tr.dependencies[tr.mods[0].modId].find((mod: { modId: string; }) => mod.modId === "minecraft").side
if (mcside == "CLIENT"){ //从Minecraft判断
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
const forgeside = tr.dependencies[tr.mods[0].modId].find((mod: { modId: string; }) => mod.modId === "forge").side
if (forgeside == "CLIENT") { //从Forge判断
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
} else if (e.entryName == "fabric.mod.json") { //Fabric
const fmj = JSON.parse(e.getData().toString('utf-8')).environment
if (fmj == "client") {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
}
} catch (erro) {//从Mixin判断 但是可能为不准确
for (let i = 0; i < zip.length; i++) {
const e = zip[i]
try {
if (!e.entryName.includes("/") && e.entryName.endsWith(".json") && !e.entryName.endsWith("refmap.json") && !e.entryName.endsWith("mod.json")) {
LOGGER.info(e.entryName)
const resx = JSON.parse(e.getData().toString('utf-8'))
if (e.entryName.includes("common.mixins.json")) { //第一步从common mixins文件判断判断失败后再使用modid.mixins.json进行判断
if (resx.mixins == null || Object.keys(resx.mixins).length == 0 && Object.keys(resx.client).length !== 0) {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
} else {
if (resx.mixins == null || Object.keys(resx.mixins).length == 0 && Object.keys(resx.client).length !== 0) {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
}
}
} catch (err:any) {//避免有傻逼JSON写注释虽然GSON可以这样 但是这样一点也不人道)
if (err.errno !== -4058) {
LOGGER.error(`大天才JSON写注释了估计模组路径:${modpath},过滤失败`)
}
}
}
}
}
}
//}
}
async function FastGot(url: string) {
let e = []
e.push([url])
const fastgot = await pMap(e, async (e: any[]) => {
try {
if (e[0] !== null) { //防止URL为空
//if(isChinaIpAddress((await got.get("https://4.ipw.cn/")).body)){
return (await got.get(e[0], { headers: { "User-Agent": "DeEarth" } })).body
//}else{
//return (await got.get(`https://mod.mcimirror.top/modrinth/${new URL(e[0]).pathname}`, { headers: { "User-Agent": "DeEarth" } })).body //MCIM源
//}
}
} catch (error: any) {
if (error.message !== "Response code 404 (Not Found)") {
LOGGER.error({ err: error })
} else {
throw new Error(error)
}
}
}, {
concurrency: 48
})
if (fastgot[0] !== undefined) {
return fastgot[0]
}else{
return "null"
}
}
const multibar = new MultiBar({
format: ' {bar} | {filename} | {value}/{total}',
noTTYOutput: true,
notTTYSchedule: 10*1000,
})
function isChinaIpAddress(ipAddress: string) {
const chinaRegex = /^((?:(?:1(?:0|1|2[0-7]|[3-9][0-9])|2(?:[0-4][0-9]|5[0-5])|[3-9][0-9]{2})\.){3}(?:(?:1(?:0|1|2[0-7]|[3-9][0-9])|2(?:[0-4][0-9]|5[0-5])|[3-9][0-9]{2})))$/;
return chinaRegex.test(ipAddress);
}

44
src/utils/logger.ts Normal file
View File

@@ -0,0 +1,44 @@
import chalk from "chalk";
export const LOGGER = {
info(text: string) {
info(text);
},
warn(text: string) {
warn(text);
},
error(text: string | object) {
error(text);
},
};
function info(text: string) {
console.log(
`[${chalk.blue(
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
)}](${process.pid})[${chalk.green("INFO")}]:${chalk.cyan(text)}`
);
}
function warn(text: string) {
console.log(
`[${chalk.blue(
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
)}](${process.pid})[${chalk.yellowBright("WARN")}]:${chalk.yellowBright(
text
)}`
);
}
function error(error: object | string) {
if (typeof error === "object") {
console.log(
`[${chalk.blue(
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
)}](${process.pid})[${chalk.red("ERROR")}:${error.toString()}`
);
} else {
console.log(
`[${chalk.blue(
new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
)}](${process.pid})[${chalk.red("ERROR")}:${error}`
);
}
}

85
src/utils/utils.ts Normal file
View File

@@ -0,0 +1,85 @@
import pMap from "p-map";
import pRetry from "p-retry";
import fse from "fs-extra"
import yauzl from "yauzl";
import got from "got";
import { MultiBar } from "cli-progress";
import { LOGGER } from "./logger.js";
export async function readzipentry(zipfile: yauzl.ZipFile, entry: yauzl.Entry):Promise<string|Buffer> {
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());
});
});
});
}
export async function fastdownload(data:[string,string]){
const multibar = new MultiBar({
format: ' {bar} | {filename} | {value}/{total}',
noTTYOutput: true,
notTTYSchedule: 10*1000,
})
const totalBar = multibar.create(data.length, 0, {filename: '总文件数'})
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 bar = multibar.create(size, 0, {filename: e[1]})
try{
await pRetry(async()=>{
if(!fse.existsSync(e[1])){
await got.get(e[0],{
responseType:"buffer",
}).on('downloadProgress',(progress)=>{
bar.update(progress.transferred)
}).then((res)=>{
fse.outputFileSync(e[1],res.rawBody)
})
}
},{retries:3})
}catch(e){
LOGGER.error({err:e})
}finally{
bar.stop()
totalBar.increment()
multibar.remove(bar)
}
},{concurrency:16})
}
export async function mr_fastdownload(data:[string,string,string]){
const multibar = new MultiBar({
format: ' {bar} | {filename} | {value}/{total}',
noTTYOutput: true,
notTTYSchedule: 10*1000,
});
const totalBar = multibar.create(data.length, 0, { filename: '总文件数' });
return await pMap(data, async (e) => {
const bar = multibar.create(Number(e[2]), 0, { filename: e[1] });
try {
await pRetry(async () => {
if (!fse.existsSync(e[1])) {
await got.get(e[0], {
responseType: "buffer",
}).on('downloadProgress', (progress) => {
bar.update(progress.transferred);
}).then((res) => {
fse.outputFileSync(e[1], res.rawBody);
});
}
}, { retries: 3 });
}
catch (e) {
LOGGER.error({ err: e });
}
finally {
bar.stop();
totalBar.increment();
multibar.remove(bar);
}
}, { concurrency: 16 });
}