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