Skip to content

Commit b8f06a0

Browse files
chore: fix setup
1 parent b5458cf commit b8f06a0

3 files changed

Lines changed: 150 additions & 0 deletions

File tree

setup/setup.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
powershell -ExecutionPolicy Bypass -File "%~dp0setup.ps1"
3+
pause

setup/setup.ps1

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/usr/bin/env pwsh
2+
# Cross-platform setup script for SaaS template. Run with: pwsh setup.ps1
3+
# On Windows, double-click setup.bat. On Linux/macOS, double-click setup.sh (or run chmod +x setup.ps1 and ./setup.ps1)
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+
$input = $default
29+
}
30+
if ($required -and [string]::IsNullOrWhiteSpace($input)) {
31+
Write-Host "This value is required. Please enter a value."
32+
continue
33+
}
34+
break
35+
} while ($true)
36+
37+
return $input
38+
}
39+
40+
# Welcome message
41+
Write-Host "Welcome to CodeBlock Dev Kit - SaaS Template Setup!"
42+
Write-Host "This script will help you configure your new SaaS application powered by CodeBlock Dev Kit."
43+
Write-Host "Press Ctrl+C at any time to cancel the setup.`n"
44+
45+
# Get the root directory (one level up from setup folder)
46+
$rootDir = Split-Path -Parent $PSScriptRoot
47+
48+
# Read default values from appsettings.json
49+
$defaultSettingsPath = Join-Path $rootDir "src/2-Clients/AdminPanel/appsettings.json"
50+
$defaultSettings = Get-Content $defaultSettingsPath -Raw | ConvertFrom-Json
51+
52+
# Get solution name (required)
53+
$solutionName = Get-UserInput -prompt "Enter your solution name (this will be used for namespaces, assembly names, database name, etc.)" -default $defaultSettings.MongoDB.DatabaseName -required $true
54+
55+
# Get application name
56+
$appName = Get-UserInput -prompt "Enter your application name (this will be displayed in UI)" -default $defaultSettings.Application.Default.Name
57+
58+
# Get application URL
59+
$appUrl = Get-UserInput -prompt "Enter your application URL" -default $defaultSettings.Application.Default.Url
60+
61+
# Get admin user details
62+
$adminMobile = Get-UserInput -prompt "Enter admin user mobile number" -default $defaultSettings.Identity.AdminUser.Mobile
63+
$adminEmail = Get-UserInput -prompt "Enter admin user email" -default $defaultSettings.Identity.AdminUser.Email
64+
$adminPassword = Get-UserInput -prompt "Enter admin user password" -default $defaultSettings.Identity.AdminUser.Password
65+
66+
# Generate random keys
67+
$encryptionKey = Get-RandomKey -length 32
68+
$apiKey = Get-RandomKey -length 32
69+
$jwtKey = Get-RandomKey -length 32
70+
71+
# Change to root directory for all file operations
72+
Push-Location $rootDir
73+
74+
try {
75+
# Update all appsettings.json files
76+
Write-Host "Updating appsettings.json files..."
77+
Get-ChildItem -Recurse -Filter "appsettings.json" | ForEach-Object {
78+
$content = Get-Content $_.FullName -Raw
79+
80+
# Update values using string replacement to preserve JSON structure
81+
$content = $content -replace '"Name":\s*"[^"]*"', "`"Name`": `"$appName`""
82+
$content = $content -replace '"Url":\s*"[^"]*"', "`"Url`": `"$appUrl`""
83+
$content = $content -replace '"Title":\s*"[^"]*"', "`"Title`": `"$appName`""
84+
$content = $content -replace '"Issuer":\s*"[^"]*"', "`"Issuer`": `"$appUrl`""
85+
$content = $content -replace '"Mobile":\s*"[^"]*"', "`"Mobile`": `"$adminMobile`""
86+
$content = $content -replace '"Email":\s*"[^"]*"', "`"Email`": `"$adminEmail`""
87+
$content = $content -replace '"Password":\s*"[^"]*"', "`"Password`": `"$adminPassword`""
88+
$content = $content -replace '"EncryptionSymmetricKey":\s*"[^"]*"', "`"EncryptionSymmetricKey`": `"$encryptionKey`""
89+
$content = $content -replace '"ApiKey":\s*"[^"]*"', "`"ApiKey`": `"$apiKey`""
90+
$content = $content -replace '"Key":\s*"[^"]*"', "`"Key`": `"$jwtKey`""
91+
$content = $content -replace '"DatabaseName":\s*"[^"]*"', "`"DatabaseName`": `"$solutionName`""
92+
$content = $content -replace '"Name":\s*"CanBeYours\.[^"]*"', "`"Name`": `"$solutionName.$1`""
93+
$content = $content -replace '"CookieName":\s*"CanBeYours\.[^"]*"', "`"CookieName`": `"$solutionName.$1`""
94+
95+
Set-Content $_.FullName $content
96+
}
97+
98+
# Update solution file
99+
Write-Host "Updating solution file..."
100+
Get-ChildItem -Filter "*.sln" | ForEach-Object {
101+
$oldName = $_.Name
102+
$newName = $_.Name -replace "CanBeYours", $solutionName
103+
$content = Get-Content $_.FullName
104+
$content = $content -replace "CanBeYours", $solutionName
105+
Set-Content $_.FullName $content
106+
107+
# Rename the solution file if name changed
108+
if ($oldName -ne $newName) {
109+
Write-Host "Renaming solution file from $oldName to $newName"
110+
Rename-Item -Path $_.FullName -NewName $newName -Force
111+
}
112+
}
113+
114+
# Update all project files
115+
Write-Host "Updating project files..."
116+
Get-ChildItem -Recurse -Filter "*.csproj" | ForEach-Object {
117+
$content = Get-Content $_.FullName
118+
$content = $content -replace "<AssemblyName>CanBeYours\.", "<AssemblyName>$solutionName."
119+
$content = $content -replace "<RootNamespace>CanBeYours\.", "<RootNamespace>$solutionName."
120+
Set-Content $_.FullName $content
121+
}
122+
123+
# Update all source files
124+
Write-Host "Updating source files..."
125+
Get-ChildItem -Recurse -Include "*.cs","*.razor","*.cshtml" | ForEach-Object {
126+
$content = Get-Content $_.FullName
127+
$content = $content -replace "namespace CanBeYours\.", "namespace $solutionName."
128+
$content = $content -replace "using CanBeYours\.", "using $solutionName."
129+
$content = $content -replace "@namespace CanBeYours\.", "@namespace $solutionName."
130+
$content = $content -replace "@using CanBeYours\.", "@using $solutionName."
131+
Set-Content $_.FullName $content
132+
}
133+
}
134+
finally {
135+
# Return to original directory
136+
Pop-Location
137+
}
138+
139+
Write-Host "`nSetup completed successfully!"
140+
Write-Host "Your CodeBlock Dev Kit SaaS application has been configured with the following settings:"
141+
Write-Host "Solution Name: $solutionName"
142+
Write-Host "Application Name: $appName"
143+
Write-Host "Application URL: $appUrl"
144+
Write-Host "Admin Email: $adminEmail"
145+
Write-Host "`nYou can now build and run your application."

setup/setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
pwsh -File "$(dirname "$0")/setup.ps1"

0 commit comments

Comments
 (0)