-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyour_program.ps1
More file actions
49 lines (38 loc) · 1.53 KB
/
Copy pathyour_program.ps1
File metadata and controls
49 lines (38 loc) · 1.53 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
# This script compiles and runs your .NET program locally.
# Optional: Accepts a -directory parameter to pass to the executable.
param(
[Parameter(ParameterSetName = "directory", HelpMessage="Specifies the root directory to be used by the server")]
[string]
$DirectoryPath
)
$ErrorActionPreference = "Stop" # Exit early if any commands fail
# Get the script's directory
$scriptPath = $MyInvocation.MyCommand.Path
$repoRoot = Split-Path $scriptPath -Parent
# Path to the built executable
$buildPath = Join-Path $repoRoot "bin\Release\net9.0\codecrafters-http-server.exe"
# Go to project root
Write-Host "[INFO] Script directory: $repoRoot `n" -ForegroundColor Cyan
Set-Location $repoRoot
# Build the project
Write-Host "[INFO] Compiling the project... `n" -ForegroundColor White
dotnet build --configuration Release
if ($LASTEXITCODE -ne 0) {
Write-Host "[ERROR] Build failed." -ForegroundColor Red
exit 1
}
Write-Host "[SUCCESS] Build completed.`n" -ForegroundColor Green
# Check if the executable exists
if (Test-Path $buildPath) {
Write-Host "[INFO] Running the executable... `n" -ForegroundColor White
if ($PSCmdlet.ParameterSetName -eq 'directory') {
Write-Host "[INFO] Running with --directory flag: $DirectoryPath" -ForegroundColor Yellow
& "$buildPath" --directory $DirectoryPath
}else{
Write-Host "[INFO] Running without --directory flag" -ForegroundColor Yellow
& "$buildPath"
}
} else {
Write-Host "[ERROR] Executable not found at: $buildPath" -ForegroundColor Red
exit 1
}