|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [string]$StagingRoot, |
| 4 | + [string[]]$IncludePaths, |
| 5 | + [switch]$Apply |
| 6 | +) |
| 7 | + |
| 8 | +Set-StrictMode -Version Latest |
| 9 | +$ErrorActionPreference = "Stop" |
| 10 | + |
| 11 | +. (Join-Path $PSScriptRoot "WebsiteRepoDeploymentCommon.ps1") |
| 12 | + |
| 13 | +$repoRoot = Get-CodexRepoRoot |
| 14 | +$paths = Get-WebsiteDeploymentPaths -StagingRoot $StagingRoot |
| 15 | +$normalizedIncludePaths = Normalize-IncludePaths -IncludePaths $IncludePaths |
| 16 | +if ($normalizedIncludePaths.Count -eq 0) { |
| 17 | + $normalizedIncludePaths = Get-DefaultWebsiteIncludePaths |
| 18 | +} |
| 19 | + |
| 20 | +$missing = New-Object System.Collections.Generic.List[string] |
| 21 | +foreach ($entry in $normalizedIncludePaths) { |
| 22 | + $fullPath = [System.IO.Path]::GetFullPath((Join-Path $repoRoot $entry)) |
| 23 | + if (-not (Test-PathWithinRoot -Path $fullPath -RootPath $repoRoot)) { |
| 24 | + throw "Include path escapes repo root: $entry" |
| 25 | + } |
| 26 | + if (-not (Test-Path -LiteralPath $fullPath)) { |
| 27 | + $missing.Add($entry) |
| 28 | + } |
| 29 | +} |
| 30 | +if ($missing.Count -gt 0) { |
| 31 | + throw "Prep validation failed. Missing include path(s): $($missing -join ', ')" |
| 32 | +} |
| 33 | + |
| 34 | +$plan = New-WebsiteDeploymentPlan -IncludePaths $normalizedIncludePaths -RepoRoot $repoRoot |
| 35 | + |
| 36 | +if (-not $Apply.IsPresent) { |
| 37 | + Write-Host "Preview mode only. No files were created." |
| 38 | + Write-Host "Run with -Apply to create staging folders and deployment plan." |
| 39 | + Write-Host "Staging root: $($paths.stagingRoot)" |
| 40 | + Write-Host "Planned include paths: $($normalizedIncludePaths -join ', ')" |
| 41 | + exit 0 |
| 42 | +} |
| 43 | + |
| 44 | +Ensure-Directory -Path $paths.stagingRoot |
| 45 | +Ensure-Directory -Path $paths.siteRoot |
| 46 | +Ensure-Directory -Path $paths.metaRoot |
| 47 | +Write-JsonFile -Value $plan -Path $paths.planPath |
| 48 | + |
| 49 | +Write-Host "Prepared website deployment staging." |
| 50 | +Write-Host "Staging root: $($paths.stagingRoot)" |
| 51 | +Write-Host "Plan file: $($paths.planPath)" |
| 52 | +Write-Host "Include paths: $($normalizedIncludePaths -join ', ')" |
0 commit comments