<# .SYNOPSIS Creates a new engine project from _Template/. .DESCRIPTION Copies _Template/ to /OpenNest.Engine./ and replaces the __NAME__ placeholder in file names and contents. The new engine builds against OpenNest via Directory.Build.props, which must sit in or a parent folder. With -IncludeBuildFiles, Directory.Build.props/.targets and the shared Engine.Testing source kit are copied into , so the engine can live outside this repo, e.g. in an Engines/ folder inside an OpenNest checkout (the props detect that layout on their own). .EXAMPLE ./New-Engine.ps1 -Name Nova ./New-Engine.ps1 -Name Nova -Destination C:/bench/run1/OpenNest/Engines -IncludeBuildFiles #> param( [Parameter(Mandatory)] [ValidatePattern('^[A-Z][A-Za-z0-9]*$')] [string]$Name, [string]$Destination = $PSScriptRoot, [switch]$IncludeBuildFiles ) $ErrorActionPreference = 'Stop' $template = Join-Path $PSScriptRoot '_Template' $target = Join-Path $Destination "OpenNest.Engine.$Name" if (Test-Path $target) { throw "'$target' already exists." } New-Item -ItemType Directory -Force $Destination | Out-Null # A built template contains binary/obj files. Copy only source files, never rewrite binaries. $template = (Resolve-Path $template).Path Get-ChildItem $template -Recurse -File | Where-Object { $_.FullName.Substring($template.Length) -notmatch '[\\/](bin|obj)[\\/]' } | ForEach-Object { $relative = $_.FullName.Substring($template.Length + 1).Replace('__NAME__', $Name) $output = Join-Path $target $relative New-Item -ItemType Directory -Force (Split-Path $output -Parent) | Out-Null $text = [IO.File]::ReadAllText($_.FullName) [IO.File]::WriteAllText($output, $text.Replace('__NAME__', $Name)) } if ($IncludeBuildFiles) { foreach ($file in 'Directory.Build.props', 'Directory.Build.targets') { Copy-Item (Join-Path $PSScriptRoot $file) $Destination -Force } # The acceptance tests reference the shared, read-only kit beside the engine. $kitTarget = Join-Path $Destination 'Engine.Testing' New-Item -ItemType Directory -Force $kitTarget | Out-Null Get-ChildItem (Join-Path $PSScriptRoot 'Engine.Testing') -File | Where-Object { $_.Extension -in '.cs', '.csproj' } | Copy-Item -Destination $kitTarget -Force } Write-Host "Created $target"