11# !/usr/bin/env pwsh
22# Cross-platform setup script for SaaS template. Run with: pwsh setup.ps1
3- # This script updates all relevant files for your new solution name and settings.
3+ # On Windows, double-click setup.bat. On Linux/macOS, double-click setup.sh (or run chmod +x setup.ps1 and ./setup.ps1)
44
55# Function to generate random string
66function Get-RandomKey {
@@ -72,19 +72,12 @@ Get-ChildItem -Recurse -Filter "*.csproj" | ForEach-Object {
7272 $content | Set-Content $_.FullName
7373}
7474
75- # Update all .cs files
76- Write-Host " Updating C# files..."
77- Get-ChildItem - Recurse - Filter " *.cs" | ForEach-Object {
78- $content = Get-Content $_.FullName
79- $content = $content -replace " namespace CanBeYours\." , " namespace $solutionName ."
80- $content = $content -replace " using CanBeYours\." , " using $solutionName ."
81- $content | Set-Content $_.FullName
82- }
83-
84- # Update all .razor and .cshtml files
85- Write-Host " Updating Razor and Blazor files..."
86- Get-ChildItem - Recurse - Include * .razor, * .cshtml | ForEach-Object {
75+ # Update all .cs, .razor, and .cshtml files
76+ Write-Host " Updating C#, Razor, and Blazor files..."
77+ Get-ChildItem - Recurse - Include " *.cs" , " *.razor" , " *.cshtml" | ForEach-Object {
8778 $content = Get-Content $_.FullName
79+ $content = $content -replace " namespace CanBeYours\." , " namespace $solutionName ."
80+ $content = $content -replace " using CanBeYours\." , " using $solutionName ."
8881 $content = $content -replace " @using CanBeYours\." , " @using $solutionName ."
8982 $content = $content -replace " @namespace CanBeYours\." , " @namespace $solutionName ."
9083 $content | Set-Content $_.FullName
@@ -93,32 +86,75 @@ Get-ChildItem -Recurse -Include *.razor,*.cshtml | ForEach-Object {
9386# Update appsettings.json files
9487Write-Host " Updating appsettings.json files..."
9588Get-ChildItem - Recurse - Filter " appsettings.json" | ForEach-Object {
96- $json = Get-Content $_.FullName | ConvertFrom-Json - Depth 100
97-
98- # Update application settings
99- $json.Application.Default.Name = $appName
100- $json.Application.Default.Url = $appUrl
101- $json.Swagger.Title = $appName
89+ $jsonContent = Get-Content $_.FullName - Raw
10290
103- # Update admin user settings
104- $json.Identity.AdminUser.Mobile = $adminMobile
105- $json.Identity.AdminUser.Email = $adminEmail
106- $json.Identity.AdminUser.Password = $adminPassword
91+ # Convert string to JSON object (compatible with older PowerShell versions)
92+ $json = $jsonContent | ConvertFrom-Json
10793
108- # Update security keys
109- $json.Security.EncryptionSymmetricKey = $encryptionKey
110- $json.ApiKey = $apiKey
111- $json.JwtAuthentication.Key = $jwtKey
112- $json.JwtAuthentication.Issuer = $appUrl
94+ # Create a template if the JSON is empty
95+ if ($null -eq $json ) {
96+ $json = @ {
97+ Application = @ {
98+ Default = @ {
99+ Name = " "
100+ Url = " "
101+ }
102+ }
103+ Swagger = @ {
104+ Title = " "
105+ }
106+ Identity = @ {
107+ AdminUser = @ {
108+ Mobile = " "
109+ Email = " "
110+ Password = " "
111+ }
112+ }
113+ Security = @ {
114+ EncryptionSymmetricKey = " "
115+ }
116+ ApiKey = " "
117+ JwtAuthentication = @ {
118+ Key = " "
119+ Issuer = " "
120+ }
121+ Hangfire = @ {
122+ MongoStorage = " mongodb://localhost:27017/CanBeYours-Hangfire"
123+ }
124+ Monitoring = @ {
125+ Service = @ {
126+ Name = " CanBeYours-Monitoring"
127+ }
128+ }
129+ CookieAuthentication = @ {
130+ CookieName = " CanBeYours-Auth"
131+ }
132+ Localization = @ {
133+ CookieName = " CanBeYours-Language"
134+ }
135+ MongoDB = @ {
136+ DatabaseName = " CanBeYours-DB"
137+ }
138+ }
139+ }
140+
141+ # Update values using string replacement to preserve the JSON structure
142+ $jsonContent = $jsonContent -replace ' "Name":\s*"[^"]*"' , " `" Name`" : `" $appName `" "
143+ $jsonContent = $jsonContent -replace ' "Url":\s*"[^"]*"' , " `" Url`" : `" $appUrl `" "
144+ $jsonContent = $jsonContent -replace ' "Title":\s*"[^"]*"' , " `" Title`" : `" $appName `" "
145+ $jsonContent = $jsonContent -replace ' "Mobile":\s*"[^"]*"' , " `" Mobile`" : `" $adminMobile `" "
146+ $jsonContent = $jsonContent -replace ' "Email":\s*"[^"]*"' , " `" Email`" : `" $adminEmail `" "
147+ $jsonContent = $jsonContent -replace ' "Password":\s*"[^"]*"' , " `" Password`" : `" $adminPassword `" "
148+ $jsonContent = $jsonContent -replace ' "EncryptionSymmetricKey":\s*"[^"]*"' , " `" EncryptionSymmetricKey`" : `" $encryptionKey `" "
149+ $jsonContent = $jsonContent -replace ' "ApiKey":\s*"[^"]*"' , " `" ApiKey`" : `" $apiKey `" "
150+ $jsonContent = $jsonContent -replace ' "Key":\s*"[^"]*"' , " `" Key`" : `" $jwtKey `" "
151+ $jsonContent = $jsonContent -replace ' "Issuer":\s*"[^"]*"' , " `" Issuer`" : `" $appUrl `" "
113152
114- # Update solution name based settings
115- $json.Hangfire.MongoStorage = $json.Hangfire.MongoStorage -replace " CanBeYours" , $solutionName
116- $json.Monitoring.Service.Name = $json.Monitoring.Service.Name -replace " CanBeYours" , $solutionName
117- $json.CookieAuthentication.CookieName = $json.CookieAuthentication.CookieName -replace " CanBeYours" , $solutionName
118- $json.Localization.CookieName = $json.Localization.CookieName -replace " CanBeYours" , $solutionName
119- $json.MongoDB.DatabaseName = $json.MongoDB.DatabaseName -replace " CanBeYours" , $solutionName
153+ # Replace solution name in various settings
154+ $jsonContent = $jsonContent -replace " CanBeYours-" , " $solutionName -"
120155
121- $json | ConvertTo-Json - Depth 100 | Set-Content $_.FullName
156+ # Save the updated JSON
157+ $jsonContent | Set-Content $_.FullName - NoNewline
122158}
123159
124160Write-Host " `n Setup completed successfully!"
0 commit comments