<# .SYNOPSIS Frontend dependency fix script - Resolve frontend build dependency issues .DESCRIPTION Clean cache, fix dependency version conflicts, reinstall dependencies and build #> $ErrorActionPreference = "Stop" function Write-ColorOutput { param( [string]$Message, [string]$Color = "White" ) $originalColor = $Host.UI.RawUI.ForegroundColor $Host.UI.RawUI.ForegroundColor = $Color Write-Host $Message $Host.UI.RawUI.ForegroundColor = $originalColor } function Fix-FrontendDependencies { param( [string]$ProjectPath, [string]$ProjectName ) Write-ColorOutput "`n=== Processing $ProjectName ===" "Cyan" if (-not (Test-Path $ProjectPath)) { Write-ColorOutput "ERROR: Project path not found: $ProjectPath" "Red" return $false } try { Set-Location $ProjectPath Write-ColorOutput "1. Cleaning npm cache..." "Yellow" npm cache clean --force Write-ColorOutput "2. Deleting node_modules and package-lock.json..." "Yellow" if (Test-Path "node_modules") { Remove-Item -Recurse -Force "node_modules" } if (Test-Path "package-lock.json") { Remove-Item "package-lock.json" } Write-ColorOutput "3. Installing dependencies with domestic mirror..." "Yellow" npm install --registry=https://registry.npmmirror.com Write-ColorOutput "4. Fixing audit issues..." "Yellow" npm audit fix --force Write-ColorOutput "5. Executing build..." "Yellow" npm run build Write-ColorOutput "SUCCESS: $ProjectName build completed!" "Green" return $true } catch { Write-ColorOutput "ERROR: $ProjectName failed: $_" "Red" return $false } } Write-ColorOutput "==============================================" "Green" Write-ColorOutput " Frontend Dependency Fix Script" "Green" Write-ColorOutput "==============================================" "Green" $basePath = (Get-Item $PSScriptRoot).Parent.FullName $frontendPath = Join-Path $basePath "frontend" $projects = @( @{ Name = "platform_web"; Path = Join-Path $frontendPath "platform_web" }, @{ Name = "merchant_web"; Path = Join-Path $frontendPath "merchant_web" }, @{ Name = "official_website"; Path = Join-Path $frontendPath "official_website" } ) $successCount = 0 $totalCount = $projects.Count foreach ($project in $projects) { if (Fix-FrontendDependencies -ProjectPath $project.Path -ProjectName $project.Name) { $successCount++ } } Write-ColorOutput "`n==============================================" "Cyan" Write-ColorOutput " Build completed: $successCount/$totalCount" "Cyan" Write-ColorOutput "==============================================" "Cyan" if ($successCount -eq $totalCount) { Write-ColorOutput "SUCCESS: All frontend projects built successfully!" "Green" exit 0 } else { Write-ColorOutput "ERROR: Some projects failed, please check logs" "Red" exit 1 }