77 lines
2.6 KiB
PowerShell
Executable File
77 lines
2.6 KiB
PowerShell
Executable File
#!/usr/bin/env pwsh
|
|
# https://docs.sheetjs.com/docs/demos/engines/mujs
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$ARCH = $env:PROCESSOR_ARCHITECTURE
|
|
|
|
switch ($ARCH) {
|
|
"AMD64" { $batFile = "vcvars64.bat" }
|
|
"ARM64" { $batFile = "vcvarsarm64.bat" }
|
|
default { Write-Error "Unsupported architecture: $ARCH"; exit 1 }
|
|
}
|
|
|
|
$oldDir = Get-Location
|
|
$tempDir = Join-Path -Path $env:TEMP -ChildPath "sheetjs-mujs"
|
|
if (Test-Path -Path $tempDir) { Remove-Item -Path $tempDir -Recurse -Force }
|
|
New-Item -ItemType Directory -Path $tempDir | Out-Null
|
|
Set-Location -Path $tempDir
|
|
|
|
# NOTE: This effectuates "Native Tools Command Prompt" for CMake/MSVC
|
|
$vsVersions = @("2022", "2019", "18")
|
|
$vsEditions = @("Community", "Professional", "Enterprise", "BuildTools")
|
|
|
|
foreach ($vsVersion in $vsVersions) {
|
|
foreach ($vsEdition in $vsEditions) {
|
|
$vcbasePath = "${env:ProgramFiles}\Microsoft Visual Studio\$vsVersion\$vsEdition"
|
|
$vcvarsPath = Join-Path $vcbasePath "VC\Auxiliary\Build\$batFile"
|
|
if (Test-Path -Path $vcvarsPath) { break }
|
|
}
|
|
if (Test-Path -Path $vcvarsPath) { break }
|
|
}
|
|
|
|
Push-Location "$vcbasePath"
|
|
cmd.exe /c "`"$vcvarsPath`" && set" | ForEach-Object { if ($_ -match '^([^=]+)=(.*)$') {
|
|
$name = $matches[1]
|
|
$value = $matches[2]
|
|
|
|
if ($name -ne 'PATH') {
|
|
Set-Item -Path "Env:$name" -Value $value
|
|
} else {
|
|
$env:PATH = "$value;$env:PATH"
|
|
}
|
|
} }
|
|
Pop-Location
|
|
|
|
# Download and extract MuJS
|
|
Invoke-WebRequest -Uri "https://mujs.com/downloads/mujs-1.3.8.zip" -OutFile "mujs-1.3.8.zip"
|
|
Expand-Archive -Path "mujs-1.3.8.zip" -DestinationPath "." -Force
|
|
Remove-Item "mujs-1.3.8.zip"
|
|
|
|
# Build MuJS library
|
|
Push-Location (Get-ChildItem -Directory -Filter "mujs-*" | Select-Object -First 1).FullName
|
|
cl /O2 /W3 /I. /c one.c /Fo:mujs.obj
|
|
lib /OUT:libmujs.lib mujs.obj
|
|
Copy-Item libmujs.lib, mujs.h -Destination $tempDir
|
|
Pop-Location
|
|
|
|
# Download SheetJSMu.c
|
|
Invoke-WebRequest -Uri "https://docs.sheetjs.com/mujs/SheetJSMu.c" -OutFile "SheetJSMu.c"
|
|
|
|
# Build SheetJSMu application
|
|
cl /O2 /W3 /Fe:SheetJSMu.exe SheetJSMu.c libmujs.lib
|
|
|
|
# Download SheetJS scripts and test file
|
|
Invoke-WebRequest -Uri "https://cdn.sheetjs.com/xlsx-latest/package/dist/shim.min.js" -OutFile "shim.min.js"
|
|
Invoke-WebRequest -Uri "https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js" -OutFile "xlsx.full.min.js"
|
|
Invoke-WebRequest -Uri "https://sheetjs.com/pres.xlsb" -OutFile "pres.xlsb"
|
|
|
|
# Run the application
|
|
.\SheetJSMu.exe pres.xlsb
|
|
if ($LASTEXITCODE -ne 0) { throw "Execution failed" }
|
|
|
|
# Wait for process to fully exit and file handles to release
|
|
Start-Sleep -Milliseconds 1000
|
|
|
|
Set-Location $oldDir
|
|
Remove-Item -Path $tempDir -Recurse -Force
|