# Start_Windows - WebServer.ps1 # Run this script with: # Set-ExecutionPolicy Unrestricted -Scope Process; .\Start_Windows -WebServer.ps1 # --- Check for Node.js --- if (-not (Get-Command node -ErrorAction SilentlyContinue)) { Write-Error "Node.js is not installed. Please install Node.js and try again." exit 1 } # --- Define paths --- $venvFolder = "Borealis-Workflow-Automation-Tool" # Virtual environment root. $dataSource = "Data" # Contains server.py and optionally WebUI. $dataDestination = "$venvFolder\Borealis" # Data folder copy destination in the venv. $customUIPath = "$dataSource\WebUI" # Custom UI folder source in the project root. $webUIDestination = "$venvFolder\web-interface" # Destination for the React UI in the venv. # --- Create virtual environment if needed --- if (!(Test-Path "$venvFolder\Scripts\Activate")) { Write-Output "Creating virtual environment in '$venvFolder'..." python -m venv $venvFolder } # --- Copy Data folder (includes server.py) --- if (Test-Path $dataSource) { Write-Output "Copying Data folder into virtual environment..." if (Test-Path $dataDestination) { Remove-Item -Recurse -Force $dataDestination } New-Item -Path $dataDestination -ItemType Directory -Force | Out-Null Copy-Item -Path "$dataSource\*" -Destination $dataDestination -Recurse } else { Write-Output "Warning: Data folder not found, skipping copy." } # --- React UI Deployment --- # Check if the React UI folder exists in the virtual environment root. if (-not (Test-Path $webUIDestination)) { Write-Output "React UI folder '$webUIDestination' not found. Generating default ReactJS app there..." npx create-react-app $webUIDestination } else { Write-Output "React UI folder '$webUIDestination' already exists." } # If a custom UI folder exists at \Data\WebUI, copy its contents over (overwrite defaults). if (Test-Path $customUIPath) { Write-Output "Custom UI folder found at '$customUIPath'. Overwriting default React app with Borealis-related files..." Copy-Item -Path "$customUIPath\*" -Destination $webUIDestination -Recurse -Force } else { Write-Output "No custom UI folder found at '$customUIPath'. Using default ReactJS app." } # --- Activate virtual environment --- Write-Output "Activating virtual environment..." . "$venvFolder\Scripts\Activate" # --- Install Python dependencies --- if (Test-Path "requirements.txt") { Write-Output "Installing Python dependencies..." pip install -q -r requirements.txt } else { Write-Output "No requirements.txt found, skipping Python dependency installation." } # --- Build the React (UI) app in the web-interface folder if needed --- $packageJsonPath = Join-Path $webUIDestination "package.json" $buildFolder = Join-Path $webUIDestination "build" if (-not (Test-Path $buildFolder)) { if (Test-Path $packageJsonPath) { Write-Output "React UI build not found in '$webUIDestination'. Installing dependencies and building the React app..." Push-Location $webUIDestination npm install --no-fund --audit=false # Ensure react-flow-renderer is installed Write-Output "Installing React Flow..." npm install reactflow --no-fund --audit=false npm run build Pop-Location } else { Write-Output "No package.json found in '$webUIDestination'; skipping npm install/build." } } else { Write-Output "React UI build found. Skipping npm install/build." } # --- Change directory to the virtual environment root --- Push-Location $venvFolder Write-Output "Current working directory: $(Get-Location)" $expectedBuildPath = Join-Path (Get-Location) "web-interface\build" Write-Output "Looking for build folder at: $expectedBuildPath" # --- Start the Flask server (server.py is inside Borealis folder) --- Write-Output "Starting the Flask server..." python "Borealis\server.py" # --- Return to original directory and deactivate virtual environment --- Pop-Location deactivate