devops/tools/format_json.sh
#!/bin/bash
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/format_script_tools.sh"

# Initialize variables with default exclusion pattern
EXCLUDE_PATTERN="$(
  printf '%s\|' \
    '/charts/' \
    'packages/mettagrid/python/src/mettagrid/renderer/assets/' \
    'packages/mettagrid/nim/mettascope/data/fidget/'
)"
# strip trailing \|
EXCLUDE_PATTERN="${EXCLUDE_PATTERN%\\|}"

EXCLUDE_HELP_TEXT="  Default: excludes paths known to contain autogenerated json files
  Use --exclude none to format all files"

# Note that this script assumes that a .prettierrc is present with appropriate settings for
# regular json files and vscode's flavor of jsonc

# Parse command line arguments
parse_format_args "$@"

# Ensure required tools are available
ensure_pnpm
ensure_prettier

# Format JSON files
format_files "json"

# Also format .code-workspace files
if [ -f "metta.code-workspace" ]; then
  echo "Formatting metta.code-workspace..."
  pnpm exec prettier --write metta.code-workspace
fi

echo "All JSON files (except excluded ones) have been formatted with Prettier."
