@@ -118,6 +118,7 @@ $SAMPLE_APP_VERSION = $packageJson.version
118118$SAMPLE_APP_FOLDER = " ${BINARY_NAME} -sample-app-${SAMPLE_APP_VERSION} -${SAMPLE_PACKAGE_OS} -${SAMPLE_PACKAGE_ARCH} "
119119
120120# Server ports
121+ $FRONTEND_PORT = 9090
121122$BACKEND_PORT = 8090
122123
123124# Directories
@@ -133,6 +134,9 @@ $REPOSITORY_DB_DIR = Join-Path $REPOSITORY_DIR "database"
133134$SERVER_SCRIPTS_DIR = Join-Path $BACKEND_BASE_DIR " scripts"
134135$SERVER_DB_SCRIPTS_DIR = Join-Path $BACKEND_BASE_DIR " dbscripts"
135136$SECURITY_DIR = " repository/resources/security"
137+ $FRONTEND_BASE_DIR = " frontend"
138+ $GATE_APP_DIR = " apps/gate"
139+ $FRONTEND_GATE_APP_DIR = Join-Path $FRONTEND_BASE_DIR $GATE_APP_DIR
136140$SAMPLE_BASE_DIR = " samples"
137141$SAMPLE_APP_DIR = Join-Path $SAMPLE_BASE_DIR " apps/oauth"
138142$SAMPLE_APP_SERVER_DIR = Join-Path $SAMPLE_APP_DIR " server"
@@ -274,6 +278,32 @@ function Build-Backend {
274278 Write-Host " ================================================================"
275279}
276280
281+ function Build-Frontend {
282+ Write-Host " ================================================================"
283+ Write-Host " Building Next.js frontend apps..."
284+
285+ # Check if pnpm is installed, if not install it
286+ if (-not (Get-Command pnpm - ErrorAction SilentlyContinue)) {
287+ Write-Host " pnpm not found, installing..."
288+ & npm install - g pnpm
289+ }
290+
291+ # Navigate to frontend directory and install dependencies
292+ Push-Location $FRONTEND_BASE_DIR
293+ try {
294+ Write-Host " Installing frontend dependencies..."
295+ & pnpm install
296+
297+ Write-Host " Building gate app..."
298+ & pnpm -- filter gate build
299+ }
300+ finally {
301+ Pop-Location
302+ }
303+
304+ Write-Host " ================================================================"
305+ }
306+
277307function Initialize-Databases {
278308 param (
279309 [bool ]$override = $false
@@ -362,13 +392,37 @@ function Prepare-Backend-For-Packaging {
362392 Write-Host " ================================================================"
363393}
364394
365- function Package-Backend {
395+ function Prepare-Frontend-For-Packaging {
396+ Write-Host " ================================================================"
397+ Write-Host " Copying frontend artifacts..."
398+
399+ $package_folder = Join-Path $DIST_DIR $PRODUCT_FOLDER
400+ $gate_app_folder = Join-Path $package_folder $GATE_APP_DIR
401+ New-Item - Path $gate_app_folder - ItemType Directory - Force | Out-Null
402+
403+ # Copy Next.js standalone output with all files including hidden ones
404+ $standalone_path = Join-Path $FRONTEND_GATE_APP_DIR " dist\.next\standalone"
405+ if (Test-Path $standalone_path ) {
406+ Write-Host " Copying gate app build output..."
407+ # Copy all files including hidden ones from standalone directory
408+ Get-ChildItem - Path $standalone_path - Force | ForEach-Object {
409+ Copy-Item - Path $_.FullName - Destination $gate_app_folder - Recurse - Force
410+ }
411+ }
412+ else {
413+ Write-Host " Warning: Frontend build output not found at $standalone_path "
414+ }
415+ Write-Host " ================================================================"
416+ }
417+
418+ function Package {
366419 Write-Host " ================================================================"
367- Write-Host " Packaging backend artifacts..."
420+ Write-Host " Packaging backend & frontend artifacts..."
368421
369422 $package_folder = Join-Path $DIST_DIR $PRODUCT_FOLDER
370423 New-Item - Path $package_folder - ItemType Directory - Force | Out-Null
371424
425+ Prepare- Frontend- For- Packaging
372426 Prepare- Backend- For- Packaging
373427
374428 # Copy the appropriate startup script based on the target OS
@@ -953,6 +1007,9 @@ function Run-Server {
9531007 Write-Host " === Ensuring server certificates exist ==="
9541008 Ensure- Certificates - cert_dir (Join-Path $BACKEND_DIR $SECURITY_DIR )
9551009
1010+ Write-Host " === Ensuring portal certificates exist ==="
1011+ Ensure- Certificates - cert_dir $FRONTEND_GATE_APP_DIR
1012+
9561013 Write-Host " === Ensuring sample app certificates exist ==="
9571014 Ensure- Certificates - cert_dir $SAMPLE_APP_DIR
9581015
@@ -969,21 +1026,35 @@ function Run-Server {
9691026 }
9701027 }
9711028
1029+ Kill- Port $FRONTEND_PORT
9721030 Kill- Port $BACKEND_PORT
9731031
974- Write-Host " === Starting backend ==="
1032+ Write-Host " === Starting frontend on https://localhost:$FRONTEND_PORT ==="
1033+ $env: FRONTEND_PORT = $FRONTEND_PORT
1034+
1035+ Push-Location $FRONTEND_BASE_DIR
1036+ try {
1037+ $frontendProcess = Start-Process - FilePath " pnpm" - ArgumentList " --filter" , " gate" , " start" - PassThru - NoNewWindow
1038+ }
1039+ finally {
1040+ Pop-Location
1041+ }
1042+
1043+ Write-Host " === Starting backend on https://localhost:$BACKEND_PORT ==="
9751044 $env: BACKEND_PORT = $BACKEND_PORT
9761045
9771046 Push-Location $BACKEND_DIR
9781047 try {
979- Start-Process - FilePath " go" - ArgumentList " run" , " ." - PassThru
1048+ $backendProcess = Start-Process - FilePath " go" - ArgumentList " run" , " ." - PassThru - NoNewWindow
9801049 }
9811050 finally {
9821051 Pop-Location
9831052 }
9841053
9851054 Write-Host " "
986- Write-Host " ⚡ Thunder Backend : https://localhost:$BACKEND_PORT "
1055+ Write-Host " 🚀 Servers running:"
1056+ Write-Host " 👉 Frontend: https://localhost:$FRONTEND_PORT "
1057+ Write-Host " 👉 Backend : https://localhost:$BACKEND_PORT "
9871058 Write-Host " Press Ctrl+C to stop."
9881059
9891060 # Wait for user to press Ctrl+C
@@ -994,6 +1065,12 @@ function Run-Server {
9941065 }
9951066 catch [System.Management.Automation.PipelineStoppedException ] {
9961067 Write-Host " Stopping servers..."
1068+ if ($frontendProcess -and -not $frontendProcess.HasExited ) {
1069+ Stop-Process - Id $frontendProcess.Id - Force - ErrorAction SilentlyContinue
1070+ }
1071+ if ($backendProcess -and -not $backendProcess.HasExited ) {
1072+ Stop-Process - Id $backendProcess.Id - Force - ErrorAction SilentlyContinue
1073+ }
9971074 }
9981075}
9991076
@@ -1007,7 +1084,10 @@ switch ($Command) {
10071084 }
10081085 " build_backend" {
10091086 Build-Backend
1010- Package- Backend
1087+ Package
1088+ }
1089+ " build_frontend" {
1090+ Build-Frontend
10111091 }
10121092 " build_samples" {
10131093 Build-Sample - App
@@ -1018,7 +1098,8 @@ switch ($Command) {
10181098 }
10191099 " build" {
10201100 Build-Backend
1021- Package- Backend
1101+ Build-Frontend
1102+ Package
10221103 Build-Sample - App
10231104 Package- Sample- App
10241105 }
@@ -1039,12 +1120,13 @@ switch ($Command) {
10391120 Run- Server
10401121 }
10411122 default {
1042- Write-Host " Usage: ./build.ps1 {clean|build|test|run} [OS] [ARCH]"
1123+ Write-Host " Usage: ./build.ps1 {clean|build|build_backend|build_frontend| test|run} [OS] [ARCH]"
10431124 Write-Host " "
10441125 Write-Host " clean - Clean build artifacts"
10451126 Write-Host " clean_all - Clean all build artifacts including distributions"
1046- Write-Host " build - Build the Thunder server and sample applications"
1047- Write-Host " build_backend - Build the Thunder backend server"
1127+ Write-Host " build - Build the complete Thunder application (backend + frontend + samples)"
1128+ Write-Host " build_backend - Build only the Thunder backend server"
1129+ Write-Host " build_frontend - Build only the Next.js frontend applications"
10481130 Write-Host " build_samples - Build the sample applications"
10491131 Write-Host " test_unit - Run unit tests with coverage"
10501132 Write-Host " test_integration - Run integration tests"
0 commit comments