<# .SYNOPSIS Batch replace PageData references in all TypeScript files .DESCRIPTION 1. Automatically backup original files 2. Remove all PageData import statements 3. Replace all PageData references with this.PageData 4. Generate detailed execution log #> # Configuration parameters $baseDir = "D:\front_Vue\ant-design-pro-vue3" $entityDir = "src/views/front/develop/Contract/Function/Entity" $backupRoot = "$baseDir\backups" $logFile = "$baseDir\batch_replace_log_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt" # Create backup directory and log file $backupDir = "$backupRoot\$(Get-Date -Format 'yyyyMMdd_HHmmss')" New-Item -ItemType Directory -Path $backupDir -Force | Out-Null "Batch replace started at $(Get-Date)" | Out-File $logFile -Encoding UTF8 # Get all .ts files (excluding demo directory) $files = Get-ChildItem -Path "$baseDir\$entityDir" -Filter "*.ts" -Recurse | Where-Object { $_.FullName -notmatch "\\demo\\" } # Process each file foreach ($file in $files) { try { $relativePath = $file.FullName.Substring($baseDir.Length + 1) "Processing: $relativePath" | Out-File $logFile -Encoding UTF8 -Append # Backup file (maintaining original directory structure) $backupPath = $file.FullName.Replace($baseDir, $backupDir) $backupDirPath = Split-Path $backupPath -Parent if (-not (Test-Path $backupDirPath)) { New-Item -ItemType Directory -Path $backupDirPath -Force | Out-Null } Copy-Item $file.FullName $backupPath # Read and modify content $content = Get-Content $file.FullName -Raw -Encoding UTF8 # 1. Remove PageData import $content = $content -replace '(?m)^import\s*{\s*PageData\s*}\s*from\s*[''"].*page-data[''"];?\s*$', '' # 2. Replace all PageData references $content = $content -replace '(?