$ErrorActionPreference = 'Stop'
$npmCmd = if (Get-Command npm.cmd -ErrorAction SilentlyContinue) { 'npm.cmd' } elseif (Get-Command npm -ErrorAction SilentlyContinue) { 'npm' } else { $null }
if (-not $npmCmd) {
  Write-Output '{"app":"helpdesk-ticket-api-typescript","status":"skip","reason":"npm tidak ditemukan"}'
  exit 0
}
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) {
  Write-Output '{"app":"helpdesk-ticket-api-typescript","status":"skip","reason":"npx tidak ditemukan"}'
  exit 0
}
& $npxCmd tsc -p .
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& node .\dist\index.js --smoke-test
