docs.sheetjs.com/tests/engines/javet.ps1
2026-03-05 00:25:10 -05:00

41 lines
1.9 KiB
PowerShell

#!/usr/bin/env pwsh
# https://docs.sheetjs.com/docs/demos/engines/v8#java
$oldDir = Get-Location
$tempDir = Join-Path -Path $env:TEMP -ChildPath "sheetjs-javet"
if (Test-Path -Path $tempDir) { Remove-Item -Path $tempDir -Recurse -Force }
New-Item -ItemType Directory -Path $tempDir | Out-Null
Set-Location -Path $tempDir
$javetVersion = "4.1.1"
$javetBaseUrl = "https://repo1.maven.org/maven2/com/caoccao/javet"
$osArtifact = "windows"
$archArtifact = "x86_64"
# Javet only provides x64 Windows builds. On ARM64 Windows, x64 Java
# runs via Prism emulation. Ensure we have x64 Java in PATH.
$javaInfo = Get-Command java -ErrorAction SilentlyContinue
if (-not $javaInfo) { throw "Java not found in PATH" }
$javaExe = $javaInfo.Source
$javacInfo = Get-Command javac -ErrorAction SilentlyContinue
if (-not $javacInfo) { throw "javac not found in PATH" }
$javacExe = $javacInfo.Source
Invoke-WebRequest -Uri "$javetBaseUrl/javet/$javetVersion/javet-$javetVersion.jar" -OutFile "javet-$javetVersion.jar"
Invoke-WebRequest -Uri "$javetBaseUrl/javet-v8-$osArtifact-$archArtifact/$javetVersion/javet-v8-$osArtifact-$archArtifact-$javetVersion.jar" -OutFile "javet-v8-$osArtifact-$archArtifact-$javetVersion.jar"
$version = "0.20.3"
Invoke-WebRequest -Uri "https://cdn.sheetjs.com/xlsx-$version/package/dist/xlsx.full.min.js" -OutFile "xlsx.full.min.js"
Invoke-WebRequest -Uri "https://docs.sheetjs.com/pres.xlsx" -OutFile "pres.xlsx"
Invoke-WebRequest -Uri "https://docs.sheetjs.com/v8/SheetJSJavet.java" -OutFile "SheetJSJavet.java"
& $javacExe -cp ".;javet-$javetVersion.jar;javet-v8-$osArtifact-$archArtifact-$javetVersion.jar" SheetJSJavet.java
if ($LASTEXITCODE -ne 0) { throw "Compilation failed" }
& $javaExe -cp ".;javet-$javetVersion.jar;javet-v8-$osArtifact-$archArtifact-$javetVersion.jar" SheetJSJavet pres.xlsx
if ($LASTEXITCODE -ne 0) { throw "Java execution failed" }
Set-Location $oldDir
Remove-Item -Path $tempDir -Recurse -Force