139 lines
4.0 KiB
PowerShell
139 lines
4.0 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Export GraphQL schemas, pack subgraphs and compose the gateway (PowerShell).
|
|
.DESCRIPTION
|
|
- Searches for FictionArchive.Service.* folders one directory above this script.
|
|
- Reads skip-projects.txt next to the script.
|
|
- Builds each service (Release).
|
|
- Runs `dotnet run --no-build --no-launch-profile -- schema export` in each service to avoid running the web host.
|
|
- Packs subgraphs.
|
|
- Composes the gateway from FictionArchive.API.
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param()
|
|
|
|
function Write-ErrExit {
|
|
param($Message, $Code = 1)
|
|
Write-Error $Message
|
|
exit $Code
|
|
}
|
|
|
|
# Resolve directories
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
|
$ServicesDir = Resolve-Path -Path (Join-Path $ScriptDir '..') -ErrorAction Stop
|
|
$ApiDir = Join-Path $ServicesDir 'FictionArchive.API'
|
|
|
|
Write-Host "Script dir: $ScriptDir"
|
|
Write-Host "Services dir: $ServicesDir"
|
|
|
|
# Load skip list
|
|
$SkipFile = Join-Path $ScriptDir 'gateway_skip.txt'
|
|
$SkipList = @()
|
|
|
|
Write-Host "----------------------------------------"
|
|
Write-Host " Loading skip list..."
|
|
Write-Host "----------------------------------------"
|
|
|
|
if (Test-Path $SkipFile) {
|
|
$SkipList = Get-Content $SkipFile |
|
|
ForEach-Object { $_.Trim() } |
|
|
Where-Object { $_ -and -not $_.StartsWith('#') }
|
|
|
|
Write-Host "Skipping: $($SkipList -join ', ')"
|
|
} else {
|
|
Write-Warning "skip-projects.txt not found — no services will be skipped."
|
|
}
|
|
|
|
# Find service directories
|
|
Write-Host
|
|
Write-Host "----------------------------------------"
|
|
Write-Host " Finding GraphQL services..."
|
|
Write-Host "----------------------------------------"
|
|
|
|
$servicePattern = 'FictionArchive.Service.*'
|
|
$serviceDirs = Get-ChildItem -Path $ServicesDir -Directory -Filter 'FictionArchive.Service.*'
|
|
|
|
if (-not $serviceDirs) {
|
|
Write-ErrExit "No service folders found matching FictionArchive.Service.* under $ServicesDir"
|
|
}
|
|
|
|
$selectedServices = @()
|
|
|
|
foreach ($d in $serviceDirs) {
|
|
if ($SkipList -contains $d.Name) {
|
|
Write-Host "Skipping: $($d.Name)"
|
|
continue
|
|
}
|
|
|
|
Write-Host "Found: $($d.Name)"
|
|
$selectedServices += $d.FullName
|
|
}
|
|
|
|
if (-not $selectedServices) {
|
|
Write-ErrExit "All services skipped — nothing to do."
|
|
}
|
|
|
|
# Export schemas and pack subgraphs
|
|
Write-Host
|
|
Write-Host "----------------------------------------"
|
|
Write-Host " Exporting schemas & packing subgraphs..."
|
|
Write-Host "----------------------------------------"
|
|
|
|
foreach ($svcPath in $selectedServices) {
|
|
$svcName = Split-Path -Leaf $svcPath
|
|
Write-Host "`nProcessing: $svcName"
|
|
|
|
Push-Location $svcPath
|
|
try {
|
|
# Build Release
|
|
Write-Host "Building $svcName..."
|
|
dotnet build -c Release
|
|
if ($LASTEXITCODE -ne 0) { Write-ErrExit "dotnet build failed for $svcName" }
|
|
|
|
# Schema export using dotnet run (no server)
|
|
Write-Host "Running schema export..."
|
|
dotnet run --no-build --no-launch-profile -- schema export --output schema.graphql
|
|
if ($LASTEXITCODE -ne 0) { Write-ErrExit "Schema export failed for $svcName" }
|
|
|
|
# Pack subgraph
|
|
Write-Host "Running fusion subgraph pack..."
|
|
fusion subgraph pack
|
|
if ($LASTEXITCODE -ne 0) { Write-ErrExit "fusion subgraph pack failed for $svcName" }
|
|
|
|
Write-Host "Completed: $svcName"
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|
|
}
|
|
|
|
# Compose gateway
|
|
Write-Host
|
|
Write-Host "----------------------------------------"
|
|
Write-Host " Running fusion compose..."
|
|
Write-Host "----------------------------------------"
|
|
|
|
if (-not (Test-Path $ApiDir)) {
|
|
Write-ErrExit "API directory not found: $ApiDir"
|
|
}
|
|
|
|
Push-Location $ApiDir
|
|
try {
|
|
if (Test-Path "gateway.fgp") { Remove-Item "gateway.fgp" -Force }
|
|
|
|
foreach ($svcPath in $selectedServices) {
|
|
$svcName = Split-Path -Leaf $svcPath
|
|
Write-Host "Composing: $svcName"
|
|
fusion compose -p gateway.fgp -s ("..\" + $svcName)
|
|
if ($LASTEXITCODE -ne 0) { Write-ErrExit "fusion compose failed for $svcName" }
|
|
}
|
|
|
|
Write-Host "`nFusion build complete!"
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|
|
|
|
exit 0
|