basic_signup_allowlist/rename_module.sh
2025-09-16 09:32:40 +00:00

102 lines
4.2 KiB
Bash
Executable File

#!/bin/bash
# Script to rename BasicSignupWhitelist module to BasicSignupAllowlist
# This includes renaming files, module names, function names, and all references
# Works recursively through all subdirectories
echo "Starting module rename from Whitelist to Allowlist..."
echo ""
# Counter for renamed files
renamed_count=0
# 1. Find and rename ALL files containing "whitelist" recursively
echo "Finding and renaming files recursively..."
echo "----------------------------------------"
# Use find to locate all files with whitelist in the name
# Process deepest files first to avoid path issues
while IFS= read -r -d '' file; do
dir=$(dirname "$file")
filename=$(basename "$file")
newname="${filename//whitelist/allowlist}"
newname="${newname//Whitelist/Allowlist}"
if [ "$filename" != "$newname" ]; then
mv "$file" "$dir/$newname"
echo " ✓ Renamed: $file$dir/$newname"
((renamed_count++))
fi
done < <(find . -type f \( -name "*whitelist*" -o -name "*Whitelist*" \) \( -name "*.ex" -o -name "*.exs" \) -print0 | sort -zr)
if [ $renamed_count -eq 0 ]; then
echo " No files needed renaming"
fi
echo ""
# 2. Replace all occurrences of BasicSignupWhitelist with BasicSignupAllowlist
echo "Updating module names in all .ex and .exs files..."
echo "---------------------------------------------------"
find . -type f \( -name "*.ex" -o -name "*.exs" \) ! -path "./_build/*" ! -path "./deps/*" -exec sed -i 's/BasicSignupWhitelist/BasicSignupAllowlist/g' {} +
echo " ✓ Updated module names from BasicSignupWhitelist to BasicSignupAllowlist"
# 3. Replace function names (mail_whitelisted -> mail_allowlisted)
echo ""
echo "Updating function names..."
echo "--------------------------"
find . -type f \( -name "*.ex" -o -name "*.exs" \) ! -path "./_build/*" ! -path "./deps/*" -exec sed -i 's/mail_whitelisted/mail_allowlisted/g' {} +
echo " ✓ Updated function names from mail_whitelisted to mail_allowlisted"
# 4. Replace case-sensitive variations of whitelist/allowlist
echo ""
echo "Updating all whitelist references (case-sensitive)..."
echo "-----------------------------------------------------"
find . -type f \( -name "*.ex" -o -name "*.exs" \) ! -path "./_build/*" ! -path "./deps/*" -exec sed -i 's/whitelist/allowlist/g' {} +
find . -type f \( -name "*.ex" -o -name "*.exs" \) ! -path "./_build/*" ! -path "./deps/*" -exec sed -i 's/Whitelist/Allowlist/g' {} +
find . -type f \( -name "*.ex" -o -name "*.exs" \) ! -path "./_build/*" ! -path "./deps/*" -exec sed -i 's/WHITELIST/ALLOWLIST/g' {} +
echo " ✓ Updated all case variations of whitelist to allowlist"
# 5. Update references in config files (mix.exs, README.md, etc.)
echo ""
echo "Updating references in configuration and documentation files..."
echo "--------------------------------------------------------------"
for file in mix.exs README.md CLAUDE.md .formatter.exs; do
if [ -f "$file" ]; then
sed -i 's/whitelist/allowlist/g' "$file"
sed -i 's/Whitelist/Allowlist/g' "$file"
sed -i 's/WHITELIST/ALLOWLIST/g' "$file"
echo " ✓ Updated references in $file"
fi
done
# 6. Clean up old build artifacts
echo ""
echo "Cleaning up old build artifacts..."
echo "----------------------------------"
if [ -d "_build" ]; then
# Find and remove directories with whitelist in the name
find _build -type d -name "*whitelist*" -exec rm -rf {} + 2>/dev/null
echo " ✓ Removed old build directories containing 'whitelist'"
echo " Note: Run 'mix clean' and 'mix compile' to rebuild completely"
else
echo " No _build directory found"
fi
# 7. Show summary of changes
echo ""
echo "============================================"
echo "Module rename complete!"
echo "============================================"
echo ""
echo "Summary:"
echo " - Renamed $renamed_count file(s)"
echo " - Updated all module and function references"
echo " - Cleaned build artifacts"
echo ""
echo "Recommended next steps:"
echo " 1. Run 'mix clean' to clean all build artifacts"
echo " 2. Run 'mix deps.get' if you have dependencies"
echo " 3. Run 'mix compile --force' to recompile with new module names"
echo " 4. Run 'mix test' to ensure all tests still pass"
echo " 5. Commit these changes to version control"