-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
181 lines (152 loc) Β· 5.37 KB
/
setup.ps1
File metadata and controls
181 lines (152 loc) Β· 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Full Stack Setup Script for Cybersecurity SaaS Platform
Write-Host "π Setting up Cybersecurity SaaS Platform..." -ForegroundColor Cyan
function Write-Status {
param($Message)
Write-Host "[INFO] $Message" -ForegroundColor Blue
}
function Write-Success {
param($Message)
Write-Host "[SUCCESS] $Message" -ForegroundColor Green
}
function Write-Warning {
param($Message)
Write-Host "[WARNING] $Message" -ForegroundColor Yellow
}
function Write-Error {
param($Message)
Write-Host "[ERROR] $Message" -ForegroundColor Red
}
# Check if Node.js is installed
try {
$nodeVersion = node --version
Write-Success "Node.js version check passed: $nodeVersion"
} catch {
Write-Error "Node.js is not installed. Please install Node.js 16 or higher."
exit 1
}
# Backend setup
Write-Status "Setting up backend..."
if (Test-Path "backend") {
Set-Location backend
} else {
Write-Error "Backend directory not found!"
exit 1
}
# Install backend dependencies
Write-Status "Installing backend dependencies..."
npm install
if ($LASTEXITCODE -eq 0) {
Write-Success "Backend dependencies installed successfully"
} else {
Write-Error "Failed to install backend dependencies"
exit 1
}
# Check if .env file exists
if (!(Test-Path ".env")) {
Write-Warning ".env file not found in backend directory"
if (Test-Path ".env.example") {
Write-Status "Copying .env.example to .env..."
Copy-Item ".env.example" ".env"
Write-Warning "Please configure your .env file with proper values"
} else {
Write-Error "No .env.example file found"
}
} else {
Write-Success "Backend .env file found"
}
# Go back to root directory
Set-Location ..
# Frontend setup
Write-Status "Setting up frontend..."
# Install frontend dependencies
Write-Status "Installing frontend dependencies..."
npm install
if ($LASTEXITCODE -eq 0) {
Write-Success "Frontend dependencies installed successfully"
} else {
Write-Error "Failed to install frontend dependencies"
exit 1
}
# Check if .env.local file exists
if (!(Test-Path ".env.local")) {
Write-Warning ".env.local file not found in frontend directory"
Write-Status "Creating default .env.local file..."
$envContent = @"
# Frontend Environment Variables
NEXT_PUBLIC_API_URL=http://localhost:5000/api
NEXT_PUBLIC_WS_URL=http://localhost:5000
NEXT_PUBLIC_APP_NAME=Cybersecurity SaaS Platform
NEXT_PUBLIC_APP_VERSION=1.0.0
# Blockchain Configuration (Public)
NEXT_PUBLIC_BLOCKCHAIN_NETWORK=polygon-mumbai
NEXT_PUBLIC_CHAINSHIELD_CONTRACT_ADDRESS=0x01B0CB02107Cd66Df4DB390Dce2EeD391D3B57F3
# Feature Flags
NEXT_PUBLIC_ENABLE_BLOCKCHAIN=true
NEXT_PUBLIC_ENABLE_WALLET_CONNECT=true
NEXT_PUBLIC_ENABLE_REAL_TIME=true
"@
$envContent | Out-File -FilePath ".env.local" -Encoding UTF8
Write-Success "Default .env.local file created"
} else {
Write-Success "Frontend .env.local file found"
}
# Create startup scripts
Write-Status "Creating startup scripts..."
# Backend start script
$backendScript = @"
@echo off
echo π Starting Cybersecurity SaaS Backend...
cd backend
npm run dev
"@
$backendScript | Out-File -FilePath "start-backend.bat" -Encoding ASCII
# Frontend start script
$frontendScript = @"
@echo off
echo π Starting Cybersecurity SaaS Frontend...
echo π URL: http://localhost:3000
npm run dev
"@
$frontendScript | Out-File -FilePath "start-frontend.bat" -Encoding ASCII
# PowerShell full stack script
$fullStackScript = @"
# Full Stack Startup Script
Write-Host "π Starting Full Stack Cybersecurity SaaS Platform..." -ForegroundColor Cyan
# Start backend in new window
Write-Host "π§ Starting backend server..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd backend; npm run dev"
# Wait a moment for backend to start
Start-Sleep -Seconds 3
# Start frontend in new window
Write-Host "π¨ Starting frontend server..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-NoExit", "-Command", "npm run dev"
Write-Host ""
Write-Host "β
Full stack is starting up..." -ForegroundColor Green
Write-Host "π Backend: http://localhost:5000" -ForegroundColor Blue
Write-Host "π¨ Frontend: http://localhost:3000" -ForegroundColor Blue
Write-Host "π API Docs: http://localhost:5000/api/health" -ForegroundColor Blue
Write-Host ""
Write-Host "Close the PowerShell windows to stop the services" -ForegroundColor Yellow
"@
$fullStackScript | Out-File -FilePath "start-fullstack.ps1" -Encoding UTF8
Write-Success "Startup scripts created"
# Summary
Write-Host ""
Write-Success "π Setup completed successfully!"
Write-Host ""
Write-Host "π Next steps:" -ForegroundColor Cyan
Write-Host " 1. Configure your backend\.env file with proper database credentials"
Write-Host " 2. Run .\start-backend.bat to start the backend"
Write-Host " 3. Run .\start-frontend.bat to start the frontend"
Write-Host " 4. Or run .\start-fullstack.ps1 to start both"
Write-Host ""
Write-Host "π Endpoints:" -ForegroundColor Cyan
Write-Host " β’ Frontend: http://localhost:3000"
Write-Host " β’ Backend API: http://localhost:5000/api"
Write-Host " β’ Health Check: http://localhost:5000/api/health"
Write-Host " β’ System Status: http://localhost:5000/api/status"
Write-Host ""
Write-Host "π§ Optional: Seed the database with sample data:" -ForegroundColor Cyan
Write-Host " cd backend && npm run seed"
Write-Host ""
Write-Success "Happy coding! π"