Skip to content

Commit 40ec596

Browse files
feat: setup
1 parent 7419110 commit 40ec596

1 file changed

Lines changed: 130 additions & 0 deletions

File tree

setup.ps1

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/env pwsh
2+
# 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.
4+
5+
# Function to generate random string
6+
function Get-RandomKey {
7+
param (
8+
[int]$length = 32
9+
)
10+
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-='
11+
return -join ((1..$length) | ForEach-Object { $chars[(Get-Random -Maximum $chars.Length)] })
12+
}
13+
14+
# Function to prompt for input with default value
15+
function Get-UserInput {
16+
param (
17+
[string]$prompt,
18+
[string]$default,
19+
[bool]$required = $false
20+
)
21+
22+
Write-Host "`n$prompt"
23+
Write-Host "Current value: $default"
24+
25+
do {
26+
$input = Read-Host "Enter new value (or press Enter to keep current)"
27+
if ([string]::IsNullOrWhiteSpace($input)) {
28+
if ($required) {
29+
Write-Host "This value is required. Please enter a value."
30+
continue
31+
}
32+
return $default
33+
}
34+
return $input
35+
} while ($required)
36+
}
37+
38+
# Welcome message
39+
Write-Host "Welcome to the SaaS Template Setup Script!"
40+
Write-Host "This script will help you configure your new SaaS application."
41+
Write-Host "Press Ctrl+C at any time to cancel the setup.`n"
42+
43+
# Get solution name (required)
44+
$solutionName = Get-UserInput -prompt "Enter your solution name (this will be used for namespaces, assembly names, etc.)" -default "CanBeYours" -required $true
45+
46+
# Get application name
47+
$appName = Get-UserInput -prompt "Enter your application name (this will be displayed in UI and Swagger)" -default "Can Be Yours"
48+
49+
# Get application URL
50+
$appUrl = Get-UserInput -prompt "Enter your application URL (this will be used for JWT issuer and other settings)" -default "https://localhost"
51+
52+
# Get admin user details
53+
$adminMobile = Get-UserInput -prompt "Enter admin user mobile number" -default "+1234567890"
54+
$adminEmail = Get-UserInput -prompt "Enter admin user email" -default "admin@example.com"
55+
$adminPassword = Get-UserInput -prompt "Enter admin user password" -default "Admin123!"
56+
57+
# Generate random keys
58+
$encryptionKey = Get-RandomKey -length 32
59+
$apiKey = Get-RandomKey -length 32
60+
$jwtKey = Get-RandomKey -length 32
61+
62+
# Update solution file
63+
Write-Host "`nUpdating solution file..."
64+
(Get-Content "CanBeYours.sln") -replace "CanBeYours", $solutionName | Set-Content "$solutionName.sln"
65+
Remove-Item "CanBeYours.sln"
66+
67+
# Update all .csproj files
68+
Write-Host "Updating project files..."
69+
Get-ChildItem -Recurse -Filter "*.csproj" | ForEach-Object {
70+
$content = Get-Content $_.FullName
71+
$content = $content -replace "CanBeYours\.", "$solutionName."
72+
$content | Set-Content $_.FullName
73+
}
74+
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 {
87+
$content = Get-Content $_.FullName
88+
$content = $content -replace "@using CanBeYours\.", "@using $solutionName."
89+
$content = $content -replace "@namespace CanBeYours\.", "@namespace $solutionName."
90+
$content | Set-Content $_.FullName
91+
}
92+
93+
# Update appsettings.json files
94+
Write-Host "Updating appsettings.json files..."
95+
Get-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
102+
103+
# Update admin user settings
104+
$json.Identity.AdminUser.Mobile = $adminMobile
105+
$json.Identity.AdminUser.Email = $adminEmail
106+
$json.Identity.AdminUser.Password = $adminPassword
107+
108+
# Update security keys
109+
$json.Security.EncryptionSymmetricKey = $encryptionKey
110+
$json.ApiKey = $apiKey
111+
$json.JwtAuthentication.Key = $jwtKey
112+
$json.JwtAuthentication.Issuer = $appUrl
113+
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
120+
121+
$json | ConvertTo-Json -Depth 100 | Set-Content $_.FullName
122+
}
123+
124+
Write-Host "`nSetup completed successfully!"
125+
Write-Host "Your SaaS application has been configured with the following settings:"
126+
Write-Host "Solution Name: $solutionName"
127+
Write-Host "Application Name: $appName"
128+
Write-Host "Application URL: $appUrl"
129+
Write-Host "Admin Email: $adminEmail"
130+
Write-Host "`nYou can now open the solution in your IDE and start developing!"

0 commit comments

Comments
 (0)