1+ # requires -Version 7.0
2+
13[CmdletBinding ()]
24param (
35 [ValidateSet (' Readme' , ' Review' )]
68)
79
810$ErrorActionPreference = ' Stop'
11+ $PSNativeCommandUseErrorActionPreference = $false
12+ Set-StrictMode - Version Latest
913$repoRoot = [IO.Path ]::GetFullPath((Join-Path $PSScriptRoot ' ..' ))
1014if ([string ]::IsNullOrWhiteSpace($OutputDirectory )) {
1115 $OutputDirectory = if ($CaptureSet -eq ' Readme' ) { Join-Path $repoRoot ' docs\images' } else { Join-Path $repoRoot ' dist\ui-review' }
1216}
1317$outputDirectory = [IO.Path ]::GetFullPath($OutputDirectory )
1418$temporaryDirectory = Join-Path (Join-Path $repoRoot ' dist' ) (' .screenshot-build-' + $PID )
19+ $captureDirectory = Join-Path $temporaryDirectory ' captured'
1520$exePath = Join-Path $temporaryDirectory ' IdleTrigger-screenshot.exe'
1621$files = if ($CaptureSet -eq ' Readme' ) {
1722 @ (' panel-en-light.png' , ' panel-en-dark.png' , ' panel-zh-light.png' , ' panel-zh-dark.png' )
@@ -24,6 +29,11 @@ $files = if ($CaptureSet -eq 'Readme') {
2429 }
2530 }
2631}
32+ $previousEnvironment = @ {
33+ CGO_ENABLED = [Environment ]::GetEnvironmentVariable(' CGO_ENABLED' , ' Process' )
34+ GOARCH = [Environment ]::GetEnvironmentVariable(' GOARCH' , ' Process' )
35+ GOCACHE = [Environment ]::GetEnvironmentVariable(' GOCACHE' , ' Process' )
36+ }
2737
2838function Get-PngSize ([string ]$Path ) {
2939 $bytes = [IO.File ]::ReadAllBytes($Path )
@@ -46,14 +56,14 @@ try {
4656 go build - tags devtools - trimpath - ldflags ' -s -w -H windowsgui -X github.com/JeffioZ/idletrigger/internal/version.Value=screenshot' - o $exePath ./ cmd/ idletrigger
4757 if ($LASTEXITCODE -ne 0 ) { throw " go build failed with exit code $LASTEXITCODE " }
4858 $setFlag = if ($CaptureSet -eq ' Readme' ) { ' --readme-set' } else { ' --review-set' }
49- $arguments = @ (' screenshot' , $setFlag , ' --output' , (' "' + $outputDirectory + ' "' ))
59+ $arguments = @ (' screenshot' , $setFlag , ' --output' , (' "' + $captureDirectory + ' "' ))
5060 $process = Start-Process - FilePath $exePath - ArgumentList $arguments - WindowStyle Hidden - Wait - PassThru
5161 if ($process.ExitCode -ne 0 ) { throw " screenshot command failed with exit code $ ( $process.ExitCode ) " }
5262 } finally { Pop-Location }
5363
5464 $sizes = @ {}
5565 foreach ($name in $files ) {
56- $path = Join-Path $outputDirectory $name
66+ $path = Join-Path $captureDirectory $name
5767 if (-not (Test-Path - LiteralPath $path - PathType Leaf)) { throw " Missing screenshot: $path " }
5868 $size = Get-PngSize $path
5969 $sizes [$name ] = $size
7181 }
7282 }
7383 }
84+
85+ New-Item - ItemType Directory - Force - Path $outputDirectory | Out-Null
86+ foreach ($name in $files ) {
87+ Copy-Item - LiteralPath (Join-Path $captureDirectory $name ) - Destination (Join-Path $outputDirectory $name ) - Force
88+ }
7489} finally {
90+ foreach ($name in $previousEnvironment.Keys ) {
91+ [Environment ]::SetEnvironmentVariable($name , $previousEnvironment [$name ], ' Process' )
92+ }
93+
7594 # Windows may briefly retain a handle to a just-exited GUI executable.
7695 # Clean synchronously so the script never leaves a detached cleanup
7796 # process behind.
0 commit comments