switch to php composer
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$Command,
|
||||
[string[]]$Arguments = @()
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$root = (Resolve-Path (Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Path) '..')).Path
|
||||
|
||||
$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 continuare."
|
||||
}
|
||||
|
||||
$dockerRoot = $root -replace '\\', '/'
|
||||
if ($dockerRoot -match '^([A-Za-z]):') {
|
||||
$dockerRoot = "/$($Matches[1].ToLower())$($dockerRoot.Substring(2))"
|
||||
}
|
||||
|
||||
Write-Host "Docker trovato. Verifico 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 -v "$($dockerRoot):/app" -w /app composer:2 composer $Command @Arguments
|
||||
}
|
||||
else {
|
||||
composer $Command @Arguments
|
||||
}
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Composer ha restituito il codice di uscita $LASTEXITCODE."
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
Reference in New Issue
Block a user