2020-11-11 21:38:56 +00:00
|
|
|
[CmdletBinding(SupportsShouldProcess)]param(
|
2021-03-23 05:06:49 +00:00
|
|
|
[ArgumentCompleter({Invoke-Command -ScriptBlock $_DockerComposeDirsCompleter -ArgumentList $args})]
|
2020-11-11 21:38:56 +00:00
|
|
|
[string[]]$ProjectPath=@($PWD),
|
|
|
|
[switch]$Force,
|
|
|
|
[string[]]$AdditionalFiles
|
|
|
|
|
|
|
|
)
|
2020-10-31 21:10:32 +00:00
|
|
|
|
2021-04-04 18:42:29 +00:00
|
|
|
$local:EditCandidates = @('docker-compose.###','.base.docker-compose.###','secrets.env')
|
2021-01-14 22:24:29 +00:00
|
|
|
$local:EditBonus = @('Dockerfile', '.env', '*.env')
|
2020-10-31 21:10:32 +00:00
|
|
|
$local:editFiles = @()
|
2021-01-14 22:24:29 +00:00
|
|
|
foreach( $local:ext in @('.yml', '.yaml') ) {
|
|
|
|
$local:rawEditCandidates = $EditCandidates | ForEach-Object { $_ -replace '\.###',$ext }
|
|
|
|
foreach( $local:fileName in $rawEditCandidates ) {
|
|
|
|
foreach( $local:path in $ProjectPath ) {
|
|
|
|
$local:testPath = Join-Path $path $fileName
|
|
|
|
if( $Force -or $(Test-Path $testPath) ) {
|
2021-04-04 18:42:29 +00:00
|
|
|
$editFiles += $testPath | Get-Path
|
2021-09-10 05:20:12 +00:00
|
|
|
$editFiles += Get-ChildItem $(Join-Path $path '*') -Include $EditBonus -Depth 1 -ErrorAction SilentlyContinue |
|
2021-01-19 00:04:39 +00:00
|
|
|
Select-Object -ExpandProperty FullName
|
2021-01-14 22:24:29 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-31 21:10:32 +00:00
|
|
|
}
|
2021-01-19 00:04:39 +00:00
|
|
|
if( $editFiles ) {
|
|
|
|
break
|
|
|
|
}
|
2020-10-31 21:10:32 +00:00
|
|
|
}
|
|
|
|
|
2021-01-24 02:46:48 +00:00
|
|
|
$AdditionalFiles = $AdditionalFiles | Where-Object { $_ } | ForEach-Object {
|
2021-01-24 02:25:39 +00:00
|
|
|
$_ -replace
|
|
|
|
'^#lsi$','#/*linuxserver.yml' -replace
|
|
|
|
'^#tr?$','#/*traefik.yml' -replace
|
|
|
|
'^#/',"$env:SZ_DOCKER_SYSTEM_PATH"
|
|
|
|
} |
|
|
|
|
Get-ChildItem -Force |
|
|
|
|
Select-Object -ExpandProperty FullName
|
|
|
|
|
2021-01-19 00:04:39 +00:00
|
|
|
$local:FinalEditList = $editFiles | Where-Object {$_} | Sort-Object {
|
|
|
|
$local:n = [System.IO.Path]::GetFileName($_)
|
2021-04-04 18:42:29 +00:00
|
|
|
$local:sorder = "$(
|
|
|
|
if( $n[0] -eq '.' ) { "2" }
|
|
|
|
elseif( $n -match 'docker-compose\.y' ) { "1" }
|
|
|
|
else { "9" }
|
|
|
|
)$n"
|
|
|
|
Write-Verbose "sorder($n)=$sorder"
|
|
|
|
$local:sorder = Join-Path $([System.IO.Path]::GetDirectoryName($_)) $sorder
|
|
|
|
$sorder
|
2021-01-19 00:04:39 +00:00
|
|
|
}
|
2021-02-04 00:43:12 +00:00
|
|
|
$FinalEditList = (@() + $FinalEditList + @() + $AdditionalFiles) | Select-Object -Unique
|
2021-04-04 18:42:29 +00:00
|
|
|
Write-Verbose "`$FinalEditList = `n$($FinalEditList | Out-String)"
|
2021-01-19 00:04:39 +00:00
|
|
|
|
|
|
|
Edit-TextFile $FinalEditList
|
2020-10-31 21:10:32 +00:00
|
|
|
|
2021-01-24 03:07:36 +00:00
|
|
|
dcc -ProjectPath $ProjectPath -TestOnly
|