-
Notifications
You must be signed in to change notification settings - Fork 8
Export-Image.ps1 compatibility with PowerShell 5.1 #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 } | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NeuroThom why was it necessary to redefine this part of the implementation? It wasn't clear from the PR description. |
||||||||||
| if (!$isWindowsPlatform) { | ||||||||||
| $bootstrapperArgs = @($bootstrapperPath) + $bootstrapperArgs | ||||||||||
| $bootstrapperPath = 'mono' | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Write-Verbose "$($bootstrapperPath) $($bootstrapperArgs)" | ||||||||||
| &$bootstrapperPath $bootstrapperArgs | ||||||||||
| if ($LASTEXITCODE -ne 0) { | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference in error output with A good way to check would be to get a workflow which fails to export and check the output of one version versus the other. |
||||||||||
| 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 | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like PS 5+ does not have
Suggested change
This could probably even be done outside the loop since we are probably fine running the script from the context of |
||||||||||
|
|
||||||||||
| if ($outputFolder) { | ||||||||||
| $svgPath = Join-Path $outputFolder $svgPathRelative | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolve-Pathhas a built-in replacement for this which does work on PS 5.0+ so we likely don't need to define a new function.