Pack Controller
This controller creates, imports and edits packs.
const { createPack, importFromFolder, addMods, removeMods, getPackInfo, getPackIndex } = require('@jackcooperdev/cmm/pack');Functions
Section titled “Functions”createPack (fileData, dir)
Section titled “createPack (fileData, dir)”Parameters:
fileData: An object describing the pack. See below.dir: Folder to create the pack in. The pack is created at<dir>/<name>.
| Field | Description |
|---|---|
name |
Pack name, also used as the folder name |
author |
Pack author |
minecraftVersion |
Minecraft version, e.g. 1.20.1. Use release or snapshot for the latest |
loader |
forge, fabric or neoforge |
loaderVersion |
(Optional) Loader version. Leave out, or use latest, release or default, for the recommended version |
mods |
Array of mod entries |
Warning: If
<dir>/<name>already exists it is deleted and recreated.
The function creates the pack and then adds the mods using addMods.
It resolves with the contents of pack.json.
It rejects with:
invalid_loaderifloaderisvanilla. Vanilla packs are not supportedversion not validif the Minecraft version is not supported by the loader- any error from addMods
importFromFolder (zipPath, outPath, nameOverride)
Section titled “importFromFolder (zipPath, outPath, nameOverride)”Parameters:
zipPath: Path to a CurseForge.zipor Modrinth.mrpackfileoutPath: Folder to import the pack into. The pack is created at<outPath>/<name>.nameOverride: (Optional) Pack name. Defaults to five random words, e.g.we-ship-fifteen-fat-there
The function reads the pack’s manifest (manifest.json or modrinth.index.json) and looks up each mod on CurseForge
or Modrinth. The Minecraft version and loader are taken from the manifest.
Files in the archive’s overrides/ folder (configs etc.) are copied into the pack, except logs, crash reports,
.hprof files and files over 100MB.
Mods that cannot be found are logged to the console and left out of the pack.
If a pack with the same name already exists:
- If it was imported from the same file, it is returned unchanged
- Otherwise, it is replaced
It resolves with the contents of pack.json.
It rejects with FILE_NOT_EXIST if the file does not exist, or NOT_VALID_FILE if it is not a .zip / .mrpack
modpack.
addMods (packPath, mods)
Section titled “addMods (packPath, mods)”Parameters:
packPath: Path to the packmods: Array of mod entries
For each mod, the latest file that matches the pack’s Minecraft version and loader is added. Required dependencies are added automatically. Mods that are already in the pack are skipped.
Invalid slugs are logged to the console and skipped.
It resolves true.
It rejects with one of the following if a matching file cannot be found:
mod not found <slug>(CurseForge)mod file not found(CurseForge)mod has no valid version for this mc version / loader(Modrinth)
await addMods('./packs/my-pack', [{ source: 'mr', slug: 'lithium' }]);removeMods (packPath, mods)
Section titled “removeMods (packPath, mods)”Parameters:
packPath: Path to the packmods: Array of mod slugs
Removes mods from the pack. Dependencies are not removed. Slugs that are not in the pack are ignored.
It resolves true.
await removeMods('./packs/my-pack', ['lithium']);getPackInfo (packPath)
Section titled “getPackInfo (packPath)”Returns the contents of the pack’s pack.json, or false if it cannot be read.
getPackIndex (packPath)
Section titled “getPackIndex (packPath)”Returns the contents of the pack’s index.json, or false if it cannot be read.
Appendix
Section titled “Appendix”Mod Entry
Section titled “Mod Entry”{ "source": "mr", "slug": "sodium" }source:cf(CurseForge) ormr(Modrinth)slug: The project slug from the mod’s page URL, e.g.sodiumfrommodrinth.com/mod/sodium
CurseForge lookups only search mods. Resource packs and shaders can be added from Modrinth.
