diff --git a/modules/Export-Image.ps1 b/modules/Export-Image.ps1 index 0bfc50f..75f4136 100644 --- a/modules/Export-Image.ps1 +++ b/modules/Export-Image.ps1 @@ -6,9 +6,15 @@ [string]$documentationRoot="" # Only relevant when outputFolder is set ) -Set-StrictMode -Version 3.0 +Set-StrictMode -Version 2.0 $ErrorActionPreference = 'Stop' -$PSNativeCommandUseErrorActionPreference = $true + +function Get-RelativePath([string]$basePath, [string]$targetPath) { + $baseUri = New-Object System.Uri(($basePath.TrimEnd('\', '/') + '\')) + $targetUri = New-Object System.Uri($targetPath) + $relUri = $baseUri.MakeRelativeUri($targetUri) + return [System.Uri]::UnescapeDataString($relUri.ToString()) -replace '/', [IO.Path]::DirectorySeparatorChar +} function Export-Svg([string[]]$libPath, [string]$svgPath, [string]$workflowFile) { $bootstrapperArgs = @() @@ -20,13 +26,17 @@ function Export-Svg([string[]]$libPath, [string]$svgPath, [string]$workflowFile) $bootstrapperArgs += "$svgPath" $bootstrapperArgs += "$workflowFile" - if (!$IsWindows) { + $isWindowsPlatform = if ($null -eq (Get-Variable 'IsWindows' -ErrorAction SilentlyContinue)) { $true } else { $IsWindows } + if (!$isWindowsPlatform) { $bootstrapperArgs = @($bootstrapperPath) + $bootstrapperArgs $bootstrapperPath = 'mono' } Write-Verbose "$($bootstrapperPath) $($bootstrapperArgs)" &$bootstrapperPath $bootstrapperArgs + if ($LASTEXITCODE -ne 0) { + throw "Export failed for '$workflowFile' with exit code $LASTEXITCODE." + } } if (-not $documentationRoot) { @@ -35,10 +45,9 @@ if (-not $documentationRoot) { Import-Module (Join-Path $PSScriptRoot "Export-Tools.psm1") -Verbose:$false -$sessionPath = $ExecutionContext.SessionState.Path foreach ($workflowFile in Get-ChildItem -File -Recurse (Join-Path $workflowPath "*.bonsai")) { $svgPath = Join-Path $workflowFile.DirectoryName "$($workflowFile.BaseName).svg" - $svgPathRelative = [IO.Path]::GetRelativePath($documentationRoot, $svgPath) + $svgPathRelative = Get-RelativePath $documentationRoot $svgPath if ($outputFolder) { $svgPath = Join-Path $outputFolder $svgPathRelative