$ErrorActionPreference = 'Stop'
$npmCmd = if (Get-Command npm.cmd -ErrorAction SilentlyContinue) { 'npm.cmd' } elseif (Get-Command npm -ErrorAction SilentlyContinue) { 'npm' } else { $null }
if (-not $npmCmd) { throw 'npm tidak ditemukan.' }
if (-not (Test-Path .\node_modules\typescript)) {
  & $npmCmd install --no-fund --no-audit
  if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
$npxCmd = if (Get-Command npx.cmd -ErrorAction SilentlyContinue) { 'npx.cmd' } elseif (Get-Command npx -ErrorAction SilentlyContinue) { 'npx' } else { $null }
if (-not $npxCmd) { throw 'npx tidak ditemukan.' }
& $npxCmd tsc -p .
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
$cmd = 'cd "' + $PSScriptRoot + '"; node .\dist\index.js'
Start-Process powershell -ArgumentList '-NoExit','-ExecutionPolicy','Bypass','-Command', $cmd | Out-Null
Start-Sleep -Seconds 2
Start-Process 'http://localhost:3100/'
Write-Output 'Helpdesk Ticket Dashboard dibuka di browser: http://localhost:3100/'
