This bash script attempts to automatically fix common compatibility issues found
in module.json files for Foundry VTT modules. It's particularly useful for
updating older modules to meet the structural requirements of newer Foundry VTT
versions (e.g., V11, V12, V13+).
Foundry VTT's manifest format (module.json) for modules and systems has
evolved. Older modules may use deprecated fields or lack newly required fields,
which can lead to errors or prevent them from loading correctly in the latest
versions of Foundry VTT. This script aims to address several of the most common
structural manifest issues to improve compatibility.
The script iterates through module.json files found in a specified directory
(and its subdirectories) and applies the following changes in place:
- Author Field (
authorvsauthors):- Converts the legacy single
authorstring field to the currentauthorsarray format (e.g.,{"authors": [{"name": "Original Author Name", "email": "", "url": ""}]}). - If the original
authorfield is empty or null, it defaults the name to "Unknown Author". - If both
authorandauthorsfields happen to exist, it removes the legacyauthorfield to prevent conflicts.
- Converts the legacy single
- Module ID (
idfield):- Ensures an
idfield is present at the root of the manifest. - If the
idfield is missing, it uses the name of the module's parent directory as theid(e.g., a module in the directorymy-cool-modulewould get"id": "my-cool-module").
- Ensures an
- Compendium Packs (
packsfield - for V11+):- For each compendium pack defined in the
packsarray:- If a pack definition has an
entityfield (older format) but is missing thetypefield (newer format), the script creates thetypefield using the value fromentityand then deletes the oldentityfield. This is crucial for compatibility with Foundry VTT version 11 and newer.
- If a pack definition has an
- For each compendium pack defined in the
- Legacy Top-Level
nameField:- Removes the deprecated top-level
namefield if it exists. In modern manifests,idis used as the unique machine-readable identifier, andtitleis used for the human-readable display name.
- Removes the deprecated top-level
To run this script successfully, you will need the following command-line tools installed on your system (typically Linux or macOS):
bash: The script is written for the bash shell.jq: A powerful command-line JSON processor. Version 1.4 or newer is generally recommended for some of the fallback logic, though the script aims for broad compatibility.- Typical Installation (Linux):
sudo apt update && sudo apt install jqorsudo dnf install jq - Typical Installation (macOS with Homebrew):
brew install jq
- Typical Installation (Linux):
find: Standard Unix utility for finding files (usually pre-installed).basename: Standard Unix utility for stripping directory information (usually pre-installed).dirname: Standard Unix utility for extracting the directory portion of a path (usually pre-installed).
-
Get the Script:
- Download the
fix.shscript file to your computer. - If you are setting up a Git repository for it, clone the repository.
- Download the
-
Make it Executable: Navigate to the directory where you saved
fix.shusing your terminal and run the following command to make it executable:chmod +x fix.sh
Run the script from your terminal. You can optionally provide a target directory
where the script should search for module.json files. If no directory is
specified, it defaults to scanning the current directory (.) and all its
subdirectories.
Syntax:
./fix.sh./fix.sh [target_directory]