Last active
November 7, 2022 14:03
-
-
Save RanolP/a066622a46bc01f61473b1e5e4acfe05 to your computer and use it in GitHub Desktop.
Prism 런처의 기기묘묘한 .index 폴더와 mmc-pack.json을 잘 탐구해서 Curseforge 모드팩을 만들어보자
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { promises as fs } from 'node:fs'; | |
import { join } from 'node:path'; | |
const MODPACK_VERSION = ''; | |
const MODPACK_AUTHOR = ''; | |
const MODPACK_NAME = ''; | |
const mmcPack = JSON.parse( | |
await fs.readFile('mmc-pack.json', { encoding: 'utf8' }) | |
); | |
const minecraftVersion = mmcPack.components.find(c => c.uid == 'net.minecraft').version; | |
const forgeVersion = mmcPack.components.find(c => c.uid == 'net.minecraftforge').version; | |
const manifest = { | |
minecraft: { | |
version: minecraftVersion, | |
modLoaders: [ | |
{ | |
id: `forge-${forgeVersion}`, | |
primary: true | |
} | |
], | |
}, | |
manifestType: "minecraftModpack", | |
overrides: "overrides", | |
manifestVersion: 1, | |
version: MODPACK_VERSION, | |
author: MODPACK_AUTHOR, | |
name: MODPACK_NAME, | |
files: [], | |
}; | |
const ProjectIdRegex = /project-id\s+=\s+([0-9]+)\n/; | |
const FileIdRegex = /file-id = ([0-9]+)\n/; | |
const modsIndexDir = '.minecraft/mods/.index'; | |
for (const filename of await fs.readdir(modsIndexDir)) { | |
const filepath = join(modsIndexDir, filename); | |
const data = await fs.readFile(filepath, { encoding: 'utf8' }); | |
const [projectID, fileID] = [ProjectIdRegex, FileIdRegex].map(r => r.exec(data)[1]); | |
manifest.files.push({ | |
projectID, | |
fileID, | |
required: true, | |
}); | |
} | |
const modInfo = []; | |
for (const { projectID } of manifest.files) { | |
const resp = await fetch(`https://api.curse.tools/v1/cf/mods/${projectID}`); | |
const json = await resp.json(); | |
const data = json.data; | |
console.log(`Fetched ${data.name}`); | |
modInfo.push(`<li><a href="${data.links.websiteUrl}">${data.name}(${data.authors[0].name})</a></li>`); | |
} | |
try { | |
await fs.stat('dist'); | |
} catch { | |
await fs.mkdir('dist'); | |
} | |
await fs.writeFile('dist/manifest.json', JSON.stringify(manifest)); | |
await fs.writeFile('dist/modlist.html', `<ul>${modInfo.join('')}</ul>`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
위와 같이
prism2curse.mjs
를 넣었을 때your-project
폴더에서 터미널 열고 Node.js v18로 실행하면dist/
폴더에manifest.json
파일이랑modlist.html
파일을 만들어준다.