param( [string]$ManifestPath = 'docs/design/assets/a01-vnext/source/a01-psd-manifest.json', [string]$OutputPath = 'docs/design/assets/a01-vnext/source/A01-layered-source-v1.psd' ) $ErrorActionPreference = 'Stop' $root = Split-Path -Parent $PSScriptRoot $rootFullPath = [IO.Path]::GetFullPath($root).TrimEnd([IO.Path]::DirectorySeparatorChar) + [IO.Path]::DirectorySeparatorChar function Resolve-WorkspacePath { param( [string]$Path, [bool]$MustExist ) $candidate = if ([IO.Path]::IsPathRooted($Path)) { $Path } else { Join-Path $root $Path } $fullPath = [IO.Path]::GetFullPath($candidate) if (-not $fullPath.StartsWith($rootFullPath, [StringComparison]::OrdinalIgnoreCase)) { throw "Path must remain inside the workspace: $Path" } if ($MustExist -and -not (Test-Path -LiteralPath $fullPath -PathType Leaf)) { throw "Required file does not exist: $fullPath" } return $fullPath } function ConvertTo-JavaScriptString { param([string]$Value) $escaped = $Value.Replace('\', '\\').Replace("'", "\'").Replace("`r", '\r').Replace("`n", '\n') return "'$escaped'" } $resolvedManifest = Resolve-WorkspacePath -Path $ManifestPath -MustExist $true $resolvedOutput = Resolve-WorkspacePath -Path $OutputPath -MustExist $false $outputName = [IO.Path]::GetFileName($resolvedOutput) if ($outputName -notmatch '^A01-layered-source-v[0-9]+\.psd$') { throw "PSD output must use a versioned A01 source name: $outputName" } if (Test-Path -LiteralPath $resolvedOutput) { throw "Refusing to overwrite an existing PSD: $resolvedOutput" } if (-not (Get-Process -Name Photoshop -ErrorAction SilentlyContinue)) { throw 'Adobe Photoshop must already be running.' } $outputDirectory = Split-Path -Parent $resolvedOutput if (-not (Test-Path -LiteralPath $outputDirectory -PathType Container)) { New-Item -ItemType Directory -Path $outputDirectory | Out-Null } $jsxPath = Resolve-WorkspacePath -Path 'scripts/photoshop/a01-build-layered-psd.jsx' -MustExist $true $app = New-Object -ComObject 'Photoshop.Application.150' $bootstrap = @" var JIAPU_A01_ROOT = $(ConvertTo-JavaScriptString $rootFullPath.TrimEnd([IO.Path]::DirectorySeparatorChar)); var JIAPU_A01_MANIFEST = $(ConvertTo-JavaScriptString $resolvedManifest); var JIAPU_A01_PSD = $(ConvertTo-JavaScriptString $resolvedOutput); $.evalFile(new File($(ConvertTo-JavaScriptString $jsxPath))); "@ $app.DoJavaScript($bootstrap, @(), 1) if (-not (Test-Path -LiteralPath $resolvedOutput -PathType Leaf)) { throw "Photoshop did not create the expected PSD: $resolvedOutput" } Write-Output "A01-LAYERED-PSD BUILD PASS: $resolvedOutput"