12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <#
- .SYNOPSIS
- Fix duplicate 'this.' references in TypeScript files
-
- .DESCRIPTION
- This script fixes the issue where 'this.PageData' was incorrectly replaced to 'this.this.PageData'
- by replacing all instances of 'this.this.PageData' with 'this.PageData'
- #>
-
- # Configuration parameters
- $baseDir = "D:\front_Vue\ant-design-pro-vue3"
- $entityDir = "src/views/front/develop/Contract/Function/Entity"
- $backupRoot = "$baseDir\backups"
- $logFile = "$baseDir\fix_duplicate_this_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
- "Fix duplicate 'this.' 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
-
- # Fix duplicate 'this.'
- $originalContent = $content
- $content = $content -replace 'this\.this\.PageData\.', 'this.PageData.'
-
- # Only write if changes were made
- if ($content -ne $originalContent) {
- $content | Set-Content $file.FullName -Encoding UTF8
- "Fixed duplicate 'this.' in: $relativePath" | Out-File $logFile -Encoding UTF8 -Append
- } else {
- "No duplicate 'this.' found in: $relativePath" | Out-File $logFile -Encoding UTF8 -Append
- }
- }
- catch {
- "ERROR processing $($file.FullName): $_" | Out-File $logFile -Encoding UTF8 -Append
- }
- }
-
- # Complete processing
- "`nFix completed at $(Get-Date)" | Out-File $logFile -Encoding UTF8 -Append
- "Total files processed: $($files.Count)" | Out-File $logFile -Encoding UTF8 -Append
- "Backup location: $backupDir" | Out-File $logFile -Encoding UTF8 -Append
-
- Write-Host "Fix completed!"
- Write-Host "Files processed: $($files.Count)"
- Write-Host "Backup location: $backupDir"
- Write-Host "Detailed log: $logFile"
|