36 lines
1.7 KiB
PowerShell
36 lines
1.7 KiB
PowerShell
|
|
param([int]$Port = 5173, [string]$SecretsFile = (Join-Path $PSScriptRoot 'secrets.psd1'))
|
||
|
|
. (Join-Path $PSScriptRoot 'common.ps1')
|
||
|
|
$settings = Read-LocalSettings $SecretsFile
|
||
|
|
$existing = Get-LocalUiProcess
|
||
|
|
if ($existing) { throw "The UI is already running with PID $($existing.ProcessId)." }
|
||
|
|
if (Get-NetTCPConnection -State Listen -LocalPort $Port -ErrorAction SilentlyContinue) { throw "Port $Port is already in use." }
|
||
|
|
$uiPath = Join-Path $repoPath 'yudao-ui-admin-vue3'
|
||
|
|
$vitePath = Join-Path $uiPath 'node_modules/vite/bin/vite.js'
|
||
|
|
if (-not (Test-Path -LiteralPath $vitePath)) { throw 'Run prepare-ui.ps1 first.' }
|
||
|
|
$nodeExe = Resolve-LocalProgram '' 'node.exe'
|
||
|
|
$apiOrigin = "http://127.0.0.1:$($settings.ServerPort)"
|
||
|
|
$uiEnv = @"
|
||
|
|
NODE_ENV=development
|
||
|
|
VITE_DEV=true
|
||
|
|
VITE_PORT=$Port
|
||
|
|
VITE_OPEN=false
|
||
|
|
VITE_BASE_URL=$apiOrigin
|
||
|
|
VITE_UPLOAD_TYPE=server
|
||
|
|
VITE_UPLOAD_URL=$apiOrigin/admin-api/infra/file/upload
|
||
|
|
VITE_API_BASEPATH=/dev-api
|
||
|
|
VITE_API_URL=/admin-api
|
||
|
|
VITE_BASE_PATH=/
|
||
|
|
VITE_DROP_DEBUGGER=false
|
||
|
|
VITE_DROP_CONSOLE=false
|
||
|
|
VITE_SOURCEMAP=false
|
||
|
|
VITE_APP_CAPTCHA_ENABLE=false
|
||
|
|
VITE_APP_DOCALERT_ENABLE=false
|
||
|
|
VITE_APP_BAIDU_CODE=
|
||
|
|
"@
|
||
|
|
[System.IO.File]::WriteAllText((Join-Path $uiPath '.env.desktop'), $uiEnv, (New-Object System.Text.UTF8Encoding($false)))
|
||
|
|
$ui = Start-Process -FilePath $nodeExe -ArgumentList @(('"' + $vitePath + '"'), '--mode', 'desktop', '--host', '127.0.0.1', '--port', [string]$Port, '--strictPort') `
|
||
|
|
-WorkingDirectory $uiPath -WindowStyle Hidden -PassThru `
|
||
|
|
-RedirectStandardOutput (Join-Path $runtimePath 'ui-stdout.log') -RedirectStandardError (Join-Path $runtimePath 'ui-stderr.log')
|
||
|
|
[System.IO.File]::WriteAllText((Join-Path $runtimePath 'ui.pid'), [string]$ui.Id)
|
||
|
|
Write-Output "Started UI PID $($ui.Id): http://127.0.0.1:$Port"
|