$ErrorActionPreference = 'Stop' $projectRoot = Split-Path -Parent $PSScriptRoot $releaseRoot = [System.IO.Path]::GetFullPath((Join-Path $projectRoot 'release\TaskPilot')) $expectedPrefix = [System.IO.Path]::GetFullPath((Join-Path $projectRoot 'release')).TrimEnd('\') + '\' if (-not $releaseRoot.StartsWith($expectedPrefix, [System.StringComparison]::OrdinalIgnoreCase)) { throw "Refusing to build outside release directory: $releaseRoot" } function Assert-ExitCode { param([string]$Step) if ($LASTEXITCODE -ne 0) { throw "$Step failed with exit code $LASTEXITCODE" } } Push-Location $projectRoot try { # 前端依赖同级 stash-ui(file:../../stash-ui):发布包要求先有组件库产物 $stashUiDist = [System.IO.Path]::GetFullPath((Join-Path $projectRoot '..\stash-ui\dist\stash-ui.js')) if (-not (Test-Path -LiteralPath $stashUiDist)) { throw "Missing @stash/ui build output: $stashUiDist. Run 'npm --prefix ..\stash-ui install' and 'npm --prefix ..\stash-ui run build' first." } pnpm --dir frontend build Assert-ExitCode 'Frontend build' cargo build --release --bin task-pilot-backend --manifest-path backend\Cargo.toml Assert-ExitCode 'Rust release build' if (Test-Path -LiteralPath $releaseRoot) { Remove-Item -LiteralPath $releaseRoot -Recurse -Force } [void](New-Item -ItemType Directory -Path $releaseRoot -Force) [void](New-Item -ItemType Directory -Path (Join-Path $releaseRoot 'web') -Force) [void](New-Item -ItemType Directory -Path (Join-Path $releaseRoot 'data') -Force) [void](New-Item -ItemType Directory -Path (Join-Path $releaseRoot 'logs') -Force) Copy-Item -LiteralPath 'backend\target\release\task-pilot-backend.exe' -Destination $releaseRoot Copy-Item -LiteralPath 'scripts\start.ps1' -Destination $releaseRoot Copy-Item -Path 'frontend\dist\*' -Destination (Join-Path $releaseRoot 'web') -Recurse Copy-Item -LiteralPath 'docs\RELEASE.md' -Destination (Join-Path $releaseRoot 'README.md') Write-Host "Release package: $releaseRoot" } finally { Pop-Location }