54 lines
2.2 KiB
PowerShell
54 lines
2.2 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)
|
|
}
|
|
{ $_ -in 'import', 'worker-once' } {
|
|
$ComposeArgs = @('run', '--rm', '-T', '--entrypoint', 'php', 'app', 'bin/meshvault', $Command)
|
|
}
|
|
'worker' {
|
|
# Interactive so Ctrl+C reaches the worker's graceful-stop handler.
|
|
$ComposeArgs = @('run', '--rm', '--entrypoint', 'php', 'app', 'bin/meshvault', 'worker')
|
|
}
|
|
'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|import|worker|worker-once [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
|
|
}
|