|
| 1 | +#!/usr/bin/env pwsh |
| 2 | + |
| 3 | +#Requires -Version 7.0 |
| 4 | + |
| 5 | +# Build the project |
| 6 | +Write-Host "Building project..." -ForegroundColor Cyan |
| 7 | +dotnet build Spectre.Docs.Examples |
| 8 | + |
| 9 | +if ($LASTEXITCODE -ne 0) { |
| 10 | + Write-Error "Build failed with exit code $LASTEXITCODE" |
| 11 | + exit $LASTEXITCODE |
| 12 | +} |
| 13 | + |
| 14 | +# Generate all screenshots in parallel |
| 15 | +Write-Host "`nGenerating screenshots in parallel..." -ForegroundColor Cyan |
| 16 | + |
| 17 | +$tapeFiles = Get-ChildItem "Spectre.Docs.Examples\VCR\*.tape" |
| 18 | +$totalFiles = $tapeFiles.Count |
| 19 | +Write-Host "Found $totalFiles tape files to process`n" -ForegroundColor Green |
| 20 | + |
| 21 | +dotnet build B:\VcrSharp\ |
| 22 | + |
| 23 | +$results = $tapeFiles | ForEach-Object -Parallel { |
| 24 | + $file = $_ |
| 25 | + $fileName = $file.Name |
| 26 | + $gifName = $file.BaseName + ".gif" |
| 27 | + |
| 28 | + try { |
| 29 | + Write-Host "[$(Get-Date -Format 'HH:mm:ss')] Processing: $fileName" -ForegroundColor Yellow |
| 30 | + |
| 31 | + |
| 32 | + # Execute VCR command |
| 33 | + dotnet run --no-build --project b:/vcrsharp/src/VcrSharp.Cli -- -o $gifName $file.FullName | Out-Null |
| 34 | + |
| 35 | + if ($LASTEXITCODE -eq 0) { |
| 36 | + Write-Host "[$(Get-Date -Format 'HH:mm:ss')] ✓ Completed: $fileName" -ForegroundColor Green |
| 37 | + return @{ Success = $true; File = $fileName } |
| 38 | + } else { |
| 39 | + Write-Warning "[$(Get-Date -Format 'HH:mm:ss')] ✗ Failed: $fileName (Exit code: $LASTEXITCODE)" |
| 40 | + return @{ Success = $false; File = $fileName; ExitCode = $LASTEXITCODE } |
| 41 | + } |
| 42 | + } |
| 43 | + catch { |
| 44 | + Write-Error "[$(Get-Date -Format 'HH:mm:ss')] ✗ Error processing $fileName : $_" |
| 45 | + return @{ Success = $false; File = $fileName; Error = $_.Exception.Message } |
| 46 | + } |
| 47 | +} -ThrottleLimit 1 |
| 48 | +# THEORETICALLY, this could be increased for more parallelism, but VCRSharp might have issues with concurrent runs. |
| 49 | +# Either we do or ttyd does. It seems an extra line feed gets added to the output (svg and gif) when run in parallel |
| 50 | +# and I don't even know how to begin debugging that. |
| 51 | + |
| 52 | + |
| 53 | +# Report results |
| 54 | +Write-Host "`n========================================" -ForegroundColor Cyan |
| 55 | +Write-Host "Screenshot Generation Summary" -ForegroundColor Cyan |
| 56 | +Write-Host "========================================" -ForegroundColor Cyan |
| 57 | + |
| 58 | +$successful = ($results | Where-Object { $_.Success }).Count |
| 59 | +$failed = ($results | Where-Object { -not $_.Success }).Count |
| 60 | + |
| 61 | +Write-Host "Total: $totalFiles | Success: $successful | Failed: $failed" -ForegroundColor $(if ($failed -eq 0) { 'Green' } else { 'Yellow' }) |
| 62 | + |
| 63 | +if ($failed -gt 0) { |
| 64 | + Write-Host "`nFailed files:" -ForegroundColor Red |
| 65 | + $results | Where-Object { -not $_.Success } | ForEach-Object { |
| 66 | + Write-Host " - $($_.File)" -ForegroundColor Red |
| 67 | + if ($_.Error) { |
| 68 | + Write-Host " Error: $($_.Error)" -ForegroundColor Gray |
| 69 | + } |
| 70 | + if ($_.ExitCode) { |
| 71 | + Write-Host " Exit code: $($_.ExitCode)" -ForegroundColor Gray |
| 72 | + } |
| 73 | + } |
| 74 | + exit 1 |
| 75 | +} |
| 76 | + |
| 77 | +Write-Host "`n✓ All screenshots generated successfully!" -ForegroundColor Green |
0 commit comments