run-node-demo.ps1 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. param(
  2. [string]$SampleDir,
  3. [string]$OutDir,
  4. [string]$LibreOfficePath = "C:\Program Files\LibreOffice\program\soffice.exe"
  5. )
  6. $ErrorActionPreference = "Stop"
  7. $OutputEncoding = [System.Text.Encoding]::UTF8
  8. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  9. [Console]::InputEncoding = [System.Text.Encoding]::UTF8
  10. $TestFilesName = "$([char]0x6D4B)$([char]0x8BD5)$([char]0x6587)$([char]0x4EF6)"
  11. $CompareName = "$([char]0x5BF9)$([char]0x6BD4)$([char]0x7ED3)$([char]0x679C)"
  12. if ([string]::IsNullOrWhiteSpace($SampleDir)) { $SampleDir = Join-Path $PSScriptRoot $TestFilesName }
  13. if ([string]::IsNullOrWhiteSpace($OutDir)) { $OutDir = Join-Path $PSScriptRoot (Join-Path $CompareName "node") }
  14. function Write-Log {
  15. param([string]$Message)
  16. Write-Host ("[{0:yyyy-MM-dd HH:mm:ss}] {1}" -f (Get-Date), $Message)
  17. }
  18. if (Test-Path $OutDir) { Remove-Item $OutDir -Recurse -Force }
  19. New-Item -ItemType Directory -Force $OutDir | Out-Null
  20. $LogFile = Join-Path $OutDir "run.log"
  21. Start-Transcript -Path $LogFile | Out-Null
  22. try {
  23. $ProjectDir = Join-Path $PSScriptRoot "doc2markdown-node"
  24. Write-Log "Node demo started"
  25. Write-Log "SampleDir=$SampleDir"
  26. Write-Log "OutDir=$OutDir"
  27. Write-Log "ProjectDir=$ProjectDir"
  28. if (!(Test-Path $SampleDir)) { throw "SampleDir not found: $SampleDir" }
  29. if (!(Test-Path $ProjectDir)) { throw "ProjectDir not found: $ProjectDir" }
  30. if (Test-Path $LibreOfficePath) {
  31. $env:LIBREOFFICE_PATH = $LibreOfficePath
  32. Write-Log "LIBREOFFICE_PATH=$env:LIBREOFFICE_PATH"
  33. } else {
  34. Write-Log "LibreOffice not found at default path: $LibreOfficePath"
  35. }
  36. Push-Location $ProjectDir
  37. try {
  38. if (!(Test-Path "node_modules")) {
  39. Write-Log "node_modules not found, running npm install"
  40. npm install
  41. }
  42. Write-Log ("Running npm smoke: {0}" -f $SampleDir)
  43. npm run smoke -- "$SampleDir" --out-dir "$OutDir"
  44. Write-Log "npm exit code: $LASTEXITCODE"
  45. } finally {
  46. Pop-Location
  47. }
  48. Write-Log "Node demo finished"
  49. } catch {
  50. Write-Log ("Failed: {0}" -f $_.Exception.Message)
  51. throw
  52. } finally {
  53. Stop-Transcript | Out-Null
  54. }