-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathConvert-SampleAnsi.ps1
More file actions
38 lines (30 loc) · 1.53 KB
/
Copy pathConvert-SampleAnsi.ps1
File metadata and controls
38 lines (30 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[CmdletBinding()]
param(
[Parameter()]
[string]$AnsiPath = './assets/ansi-files/DEL-FLAG.ANS',
[Parameter()]
[string]$OutputPath = './dist/examples/DEL-FLAG.ps1'
)
$scriptRoot = Split-Path -Path $MyInvocation.MyCommand.Path -Parent
$repoRoot = [System.IO.Path]::GetFullPath((Join-Path -Path $scriptRoot -ChildPath '..'))
$repoRoot = [System.IO.Path]::GetFullPath((Join-Path -Path $repoRoot -ChildPath '..'))
$ansiFull = Resolve-Path -LiteralPath (Join-Path -Path $repoRoot -ChildPath $AnsiPath)
$outputFull = Join-Path -Path $repoRoot -ChildPath $OutputPath
$node = Get-Command node -ErrorAction SilentlyContinue
if (-not $node) {
throw 'Node.js is required to run Convert-AnsiToColorScript.js. Install Node 18+ and re-run this script.'
}
$outputDirectory = Split-Path -Path $outputFull -Parent
if (-not (Test-Path -LiteralPath $outputDirectory)) {
New-Item -ItemType Directory -Path $outputDirectory -Force | Out-Null
}
$converter = Join-Path -Path $repoRoot -ChildPath 'scripts\Convert-AnsiToColorScript.js'
if (-not (Test-Path -LiteralPath $converter)) {
throw "Converter not found at '$converter'. Run this script from the repository workspace."
}
Write-Host "Converting $ansiFull to $outputFull" -ForegroundColor Cyan
& $node.Source $converter $ansiFull '--output' $outputFull '--encoding' 'utf8'
if ($LASTEXITCODE -ne 0) {
throw "Conversion failed with exit code $LASTEXITCODE."
}
Write-Host '✓ Conversion complete. Preview the generated script with Show-ColorScript or the Test-All harness.' -ForegroundColor Green