@@ -124,6 +124,19 @@ Write-Host "Press Ctrl+C at any time to cancel the setup.`n"
124124# Get the root directory (one level up from setup folder)
125125$rootDir = Split-Path - Parent $PSScriptRoot
126126
127+ # Check if setup has already been run
128+ $solutionFile = Get-ChildItem - Path $rootDir - Filter " *.sln" | Select-Object - First 1
129+ if ($solutionFile -and $solutionFile.Name -ne " CanBeYours.sln" ) {
130+ Write-Host " Setup has already been run on this template!" - ForegroundColor Red
131+ Write-Host " `n The solution file has been renamed from 'CanBeYours.sln' to '$ ( $solutionFile.Name ) '." - ForegroundColor Yellow
132+ Write-Host " This indicates that the setup process has already been executed on this template." - ForegroundColor Yellow
133+ Write-Host " `n To run setup again, you must use a fresh copy of the CodeBlock Dev Kit template." - ForegroundColor Cyan
134+ Write-Host " Please download a new copy from: https://github.com/CodeBlock-Dev/CodeBlock.DevKit.Template" - ForegroundColor Cyan
135+ Write-Host " `n Press any key to exit..." - ForegroundColor Gray
136+ $null = $Host.UI.RawUI.ReadKey (" NoEcho,IncludeKeyDown" )
137+ exit 1
138+ }
139+
127140# Read default values from appsettings.json
128141$defaultSettingsPath = Join-Path $rootDir " src/2-Clients/AdminPanel/appsettings.json"
129142$defaultSettings = Get-Content $defaultSettingsPath - Raw | ConvertFrom-Json
@@ -223,24 +236,37 @@ try {
223236 # Handle InternalsVisibleTo attributes in AssemblyInfo.cs
224237 $content = $content -replace ' InternalsVisibleTo\("CanBeYours\.([^"]*)"\)' , " InternalsVisibleTo(`" $solutionName .`$ 1`" )"
225238
239+ # Handle specific patterns in _ViewImports.cshtml files
240+ $content = $content -replace " ^CanBeYours\.([A-Za-z]+)\.Pages$" , " $solutionName .`$ 1.Pages"
241+
226242 Set-Content $_.FullName $content
227243 }
228244
229245 # Update .nuke configuration files and other JSON files
230246 Write-Host " `n Updating configuration files..." - ForegroundColor Blue
231- Get-ChildItem - Recurse - Include " *.nuke" , " parameters.json" | ForEach-Object {
232- $content = Get-Content $_.FullName
233- $content = $content -replace ' "Solution":\s*"CanBeYours\.sln"' , " `" Solution`" : `" $solutionName .sln`" "
234- Set-Content $_.FullName $content
247+ Get-ChildItem - Recurse - Include " *.nuke" , " parameters.json" | Where-Object { $_.PSIsContainer -eq $false } | ForEach-Object {
248+ try {
249+ $content = Get-Content $_.FullName - ErrorAction Stop
250+ $content = $content -replace ' "Solution":\s*"CanBeYours\.sln"' , " `" Solution`" : `" $solutionName .sln`" "
251+ Set-Content $_.FullName $content - ErrorAction Stop
252+ }
253+ catch {
254+ Write-Host " Warning: Could not update $ ( $_.FullName ) - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
255+ }
235256 }
236257
237258 # Update generated files (test results, logs, etc.)
238259 Write-Host " `n Updating generated files..." - ForegroundColor Blue
239- Get-ChildItem - Recurse - Include " *.trx" , " *.log" , " *.cache" , " *.deps.json" , " *.runtimeconfig.json" , " *.staticwebassets.*.json" , " *.resources.dll" , " *.pdb" , " *.dll" , " *.exe" | Where-Object { $_.FullName -like " *CanBeYours*" } | ForEach-Object {
240- $content = Get-Content $_.FullName - Raw - ErrorAction SilentlyContinue
241- if ($content ) {
242- $content = $content -replace " CanBeYours\." , " $solutionName ."
243- Set-Content $_.FullName $content - NoNewline
260+ Get-ChildItem - Recurse - Include " *.trx" , " *.log" , " *.cache" , " *.deps.json" , " *.runtimeconfig.json" , " *.staticwebassets.*.json" , " *.resources.dll" , " *.pdb" , " *.dll" , " *.exe" | Where-Object { $_.PSIsContainer -eq $false -and $_.FullName -like " *CanBeYours*" } | ForEach-Object {
261+ try {
262+ $content = Get-Content $_.FullName - Raw - ErrorAction Stop
263+ if ($content ) {
264+ $content = $content -replace " CanBeYours\." , " $solutionName ."
265+ Set-Content $_.FullName $content - NoNewline - ErrorAction Stop
266+ }
267+ }
268+ catch {
269+ Write-Host " Warning: Could not update $ ( $_.FullName ) - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
244270 }
245271 }
246272}
0 commit comments