diff --git a/.gitignore b/.gitignore index ccd7feb..360f457 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ src/Client/output/ # Production deployment wwwroot/ +.publish/ .treemon.pid .treemon.config diff --git a/src/Server/Server.fsproj b/src/Server/Server.fsproj index bd1a59c..8851d36 100644 --- a/src/Server/Server.fsproj +++ b/src/Server/Server.fsproj @@ -2,6 +2,7 @@ Exe + Treemon net9.0 LatestMajor diff --git a/treemon.ps1 b/treemon.ps1 index fdb8753..6e7c756 100644 --- a/treemon.ps1 +++ b/treemon.ps1 @@ -15,6 +15,7 @@ $PidFile = Join-Path $ScriptDir ".treemon.pid" $ConfigFile = Join-Path $ScriptDir ".treemon.config" $LogDir = Join-Path $ScriptDir "logs" $LogFile = Join-Path $LogDir "treemon-prod.log" +$PublishDir = Join-Path $ScriptDir ".publish" $WwwRoot = Join-Path $ScriptDir "wwwroot" $DefaultPort = 5000 if ($env:TREEMON_PORT) { @@ -149,11 +150,16 @@ function Start-ProductionServer([string[]]$Roots) { Save-Config $Roots + Write-Host "Publishing server..." -ForegroundColor Cyan + dotnet publish -c Release -o $PublishDir src/Server/Server.fsproj + if ($LASTEXITCODE -ne 0) { throw "dotnet publish failed" } + + $serverExe = Join-Path $PublishDir "Treemon.exe" $rootArgs = ($Roots | ForEach-Object { "`"$($_.TrimEnd('\', '/'))`"" }) -join " " Write-Host "Starting production server on port $DefaultPort..." -ForegroundColor Cyan - $process = Start-Process -FilePath "dotnet" ` - -ArgumentList "run -c Release --project `"$(Join-Path $ScriptDir "src/Server")`" -- $rootArgs --port $DefaultPort" ` + $process = Start-Process -FilePath $serverExe ` + -ArgumentList "$rootArgs --port $DefaultPort" ` -WorkingDirectory $ScriptDir ` -RedirectStandardOutput $LogFile ` -RedirectStandardError (Join-Path $LogDir "treemon-prod-stderr.log") `