39 lines
1.4 KiB
PowerShell
39 lines
1.4 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$root = Join-Path $root '..'
|
|
|
|
$useDockerComposer = $false
|
|
$dockerRoot = $null
|
|
|
|
if (-not (Get-Command composer -ErrorAction SilentlyContinue)) {
|
|
Write-Host "Composer non trovato localmente. Verifico se Docker è disponibile..."
|
|
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
|
|
throw "Composer non trovato e Docker mancante! Installa Composer o Docker prima di generare il pacchetto."
|
|
}
|
|
|
|
$dockerRoot = $root -replace '\\', '/'
|
|
if ($dockerRoot -match '^([A-Za-z]):') {
|
|
$dockerRoot = "/$($Matches[1].ToLower())$($dockerRoot.Substring(2))"
|
|
}
|
|
|
|
Write-Host "Docker trovato. Root: '$dockerRoot' Test di Composer tramite container..."
|
|
docker run --rm -v "$($dockerRoot):/app" -w /app composer:2 composer --version 2>&1
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Docker presente, ma Composer non riesce ad avviarsi tramite container. Installa Composer localmente o verifica Docker."
|
|
}
|
|
|
|
$useDockerComposer = $true
|
|
}
|
|
|
|
Push-Location $root
|
|
try {
|
|
if ($useDockerComposer) {
|
|
docker run --rm -p 8000:8000 -v "$($dockerRoot):/app" -w /app --name php-serve php:8.5.8-cli php -S 0.0.0.0:8000 -t public public/index.php
|
|
}
|
|
else {
|
|
php -S 0.0.0.0:8000 -t public public/index.php
|
|
}
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
} |