19 lines
1.4 KiB
PowerShell
19 lines
1.4 KiB
PowerShell
[CmdletBinding()]
|
|
param([int]$Port = 0, [switch]$NoBrowser, [string]$DataRoot = '', [string]$NodePath = '')
|
|
$ErrorActionPreference = 'Stop'
|
|
[Console]::OutputEncoding = [Text.UTF8Encoding]::new($false)
|
|
$appRoot = [IO.Path]::GetFullPath((Split-Path -Parent $PSScriptRoot))
|
|
if ($Port -eq 0) { $Port = if ($env:AGENT_WORKBENCH_PORT) { [int]$env:AGENT_WORKBENCH_PORT } else { 4318 } }
|
|
if (-not $DataRoot) { $DataRoot = if ($env:AGENT_WORKBENCH_DATA_DIR) { $env:AGENT_WORKBENCH_DATA_DIR } else { Join-Path $env:LOCALAPPDATA 'AgentWorkbench' } }
|
|
$DataRoot = [IO.Path]::GetFullPath($DataRoot)
|
|
if (-not $NodePath) { $NodePath = Join-Path $appRoot 'runtime\node.exe' }
|
|
if (-not (Test-Path -LiteralPath $NodePath)) { $NodePath = (Get-Command node.exe -ErrorAction Stop).Source }
|
|
$launcher = Join-Path $appRoot 'dist-server\host-launcher.mjs'
|
|
if (-not (Test-Path -LiteralPath $launcher)) { throw 'Build the source first, or use the complete portable package.' }
|
|
$output = & $NodePath $launcher start --app-root $appRoot --data-root $DataRoot --node $NodePath --port ([string]$Port)
|
|
if ($LASTEXITCODE -ne 0) { throw 'The host could not be verified. See the original diagnostic above.' }
|
|
$result = $output | ConvertFrom-Json
|
|
Write-Output ('Agent Workbench is ready: ' + $result.url)
|
|
Write-Output ('Data: ' + $DataRoot)
|
|
Write-Output ('Verified host PID: ' + $result.identity.pid + ' · Instance: ' + $result.identity.instanceId)
|
|
if (-not $NoBrowser) { Start-Process -FilePath $result.url } |