45 lines
1.8 KiB
PowerShell
45 lines
1.8 KiB
PowerShell
# Deliberately use $args: unknown switches belong to the underlying command.
|
|
$ErrorActionPreference = 'Stop'
|
|
$Command = if ($args.Count) { $args[0] } else { '' }
|
|
$Forward = @($args | Select-Object -Skip 1)
|
|
try {
|
|
switch ($Command) {
|
|
'migrate' {
|
|
$ComposeArgs = @('run', '--rm', '--no-deps', '-T', '--entrypoint', 'sh', 'app', '-c', "vendor/bin/phinx migrate $($Forward -join ' ')")
|
|
}
|
|
'seed' {
|
|
$ComposeArgs = @('run', '--rm', '--no-deps', '-T', '--entrypoint', 'sh', 'app', '-c', "vendor/bin/phinx seed:run $($Forward -join ' ')")
|
|
}
|
|
'up' { $ComposeArgs = @('up', '-d', '--build') }
|
|
'down' {
|
|
foreach ($Argument in $Forward) {
|
|
if ($Argument -match '^--volumes|^-v$') {
|
|
[Console]::Error.WriteLine('Volume removal is forbidden by this wrapper')
|
|
exit 2
|
|
}
|
|
}
|
|
$ComposeArgs = @('down')
|
|
}
|
|
{ $_ -in 'test', 'lint' } {
|
|
$ComposeArgs = @('run', '--rm', '--no-deps', '-T', '--entrypoint', 'composer', 'app', $Command)
|
|
}
|
|
'assets' { $ComposeArgs = @('run', '--rm', '--no-deps', '-T', 'assets', 'npm', 'run', 'build', '--') }
|
|
{ $_ -in 'watch', 'assets:watch' } {
|
|
$ComposeArgs = @('run', '--rm', '--no-deps', '-T', 'assets', 'npm', 'run', 'watch', '--')
|
|
}
|
|
default {
|
|
[Console]::Error.WriteLine('Usage: dev.ps1 up|down|test|lint|assets|watch|migrate|seed [arguments]')
|
|
exit 2
|
|
}
|
|
}
|
|
Push-Location $PSScriptRoot
|
|
try {
|
|
& docker compose @ComposeArgs @Forward
|
|
$Result = $LASTEXITCODE
|
|
} finally { Pop-Location }
|
|
exit $Result
|
|
} catch {
|
|
[Console]::Error.WriteLine($_.Exception.Message)
|
|
exit 1
|
|
}
|