|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- # 改进版实体文件更新脚本
- # 解决原脚本未完全替换PageData引用和导入的问题
-
- # 1. 配置参数
- $directory = "src/views/front/develop/Contract/Function/Entity"
- $backupDir = "backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
- $logFile = "update_entities_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
-
- # 2. 创建备份目录和日志文件
- New-Item -ItemType Directory -Path $backupDir -Force | Out-Null
- "Script started at $(Get-Date)" | Out-File -FilePath $logFile -Encoding UTF8
-
- # 3. 获取所有.ts文件(排除demo目录)
- $files = Get-ChildItem -Path $directory -Filter "*.ts" -Recurse |
- Where-Object { $_.FullName -notmatch "\\demo\\" }
-
- # 4. 处理每个文件
- foreach ($file in $files) {
- try {
- # 记录处理开始
- "Processing file: $($file.FullName)" | Out-File -FilePath $logFile -Encoding UTF8 -Append
-
- # 备份原始文件
- $backupPath = Join-Path $backupDir $file.Name
- Copy-Item -Path $file.FullName -Destination $backupPath
-
- # 读取文件内容
- $content = Get-Content -Path $file.FullName -Raw -Encoding UTF8
-
- # 1. 删除PageData导入
- $content = $content -replace '(?m)^import\s*{\s*PageData\s*}\s*from\s*[''"].*page-data[''"];?\s*$', ''
-
- # 2. 替换所有PageData引用为this.PageData
- $content = $content -replace '(?<!this\.)PageData\.', 'this.PageData.'
-
- # 3. 替换FileData为fileData (如果存在)
- $content = $content -replace 'FileData', 'fileData'
-
- # 写入修改后的内容
- $content | Set-Content -Path $file.FullName -Encoding UTF8
-
- # 记录处理完成
- "File processed successfully: $($file.FullName)" | Out-File -FilePath $logFile -Encoding UTF8 -Append
- }
- catch {
- # 记录错误
- "Error processing file $($file.FullName): $_" | Out-File -FilePath $logFile -Encoding UTF8 -Append
- }
- }
-
- # 5. 完成处理
- "Script completed at $(Get-Date)" | Out-File -FilePath $logFile -Encoding UTF8 -Append
- "All files processed. Backup saved to: $backupDir" | Out-File -FilePath $logFile -Encoding UTF8 -Append
-
- Write-Host "所有文件处理完成。备份保存在: $backupDir"
- Write-Host "详细日志请查看: $logFile"
|