#!/usr/bin/env bash # Phase 1 helper: migrate '@material-ui/*' imports to MUI v5 packages. # Usage: bash $0 --dry (default) | bash $0 --apply set -euo pipefail MODE="dry" [[ "${1-}" == "--apply" ]] && MODE="apply" ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo .)" REPORT_DIR="$ROOT/reports/phase1-$(date +%Y%m%d-%H%M%S)-mui" mkdir -p "$REPORT_DIR" # Find candidates: use reports list if present, otherwise grep. LIST="" LATEST_REPORT="$(ls -d $ROOT/reports/phase1-* 2>/dev/null | sort | tail -n1 || true)" if [[ -n "$LATEST_REPORT" && -f "$LATEST_REPORT/mui_v4_imports.txt" ]]; then LIST="$(awk -F: '{print $1}' "$LATEST_REPORT/mui_v4_imports.txt" | sort -u)" else LIST="$(grep -RIl --include='*.{ts,tsx,js,jsx}' -e '@material-ui/' "$ROOT/src" || true)" fi echo "Files:" > "$REPORT_DIR/changes.log" echo "$LIST" | sed '/^$/d' | tee -a "$REPORT_DIR/changes.log" convert_file() {( f="$1" tmp="$f.__mui_tmp__" cp "$f" "$tmp" # Core/icon packages sed -i 's#@material-ui/core/#@mui/material/#g' "$tmp" sed -i 's#@material-ui/core#@mui/material#g' "$tmp" sed -i 's#@material-ui/icons/#@mui/icons-material/#g' "$tmp" sed -i 's#@material-ui/icons#@mui/icons-material#g' "$tmp" # Styles (best-effort): makeStyles/theme from @mui/styles (legacy). Emit a note. if grep -q "makeStyles\|withStyles" "$tmp"; then echo "NOTE: $f uses makeStyles/withStyles → @mui/styles (legacy) or migrate to sx/Styled API." >> "$REPORT_DIR/notes.txt" fi if [[ "$MODE" == "apply" ]]; then mv "$tmp" "$f" echo "[APPLY] $f" >> "$REPORT_DIR/changes.log" else echo "[DRY] diff $f" git --no-pager diff --no-index "$f" "$tmp" || true rm -f "$tmp" fi )} echo echo "== Processing ==" echo "$LIST" | while read -r f; do [[ -z "$f" ]] && continue [[ -f "$f" ]] || continue convert_file "$f" done echo echo "Report: $REPORT_DIR"