Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions modules/Export-Image.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve-Path has a built-in replacement for this which does work on PS 5.0+ so we likely don't need to define a new function.

Resolve-Path -Relative abspath

$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 = @()
Expand All @@ -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 }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference in error output with PSNativeCommandUseErrorActionPreference versus this error check? Do you still get the error stack trace printed by the Bonsai bootstrapper?

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) {
Expand All @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like PS 5+ does not have -RelativeBasePath and always works relative to the current directory so we would need to push and pop location:

Suggested change
$svgPathRelative = Get-RelativePath $documentationRoot $svgPath
Push-Location $documentationRoot
$svgPathRelative = Resolve-Path $svgPath -Relative
Pop-Location

This could probably even be done outside the loop since we are probably fine running the script from the context of $documentationRoot.


if ($outputFolder) {
$svgPath = Join-Path $outputFolder $svgPathRelative
Expand Down