Private/Deploy-Accelerator-Helpers/New-FolderStructure.ps1
function New-FolderStructure { [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter(Mandatory = $true)] [string] $targetDirectory, [Parameter(Mandatory = $true)] [string] $url, [Parameter(Mandatory = $false)] [string] $release = "latest", [Parameter(Mandatory = $false)] [string] $releaseArtifactName = "", [Parameter(Mandatory = $true)] [string] $targetFolder, [Parameter(Mandatory = $false)] [string] $sourceFolder, [Parameter(Mandatory = $false)] [string] $overrideSourceDirectoryPath = "", [Parameter(Mandatory = $false)] [switch] $replaceFiles ) if ($PSCmdlet.ShouldProcess("ALZ-Terraform module configuration", "modify")) { Write-Verbose "Downloading modules to $targetDirectory" if(!($release.StartsWith("v")) -and ($release -ne "latest")) { $release = "v$release" } $releaseTag = "" $path = "" if($overrideSourceDirectoryPath -ne "") { $releaseTag = "local" $path = Join-Path $targetDirectory $targetFolder $releaseTag if((Test-Path $path) -and !$replaceFiles) { Write-Verbose "Folder $path already exists, so not copying files." } else { Write-InformationColored "Copying files from $overrideSourceDirectoryPath to $path" -ForegroundColor Green -InformationAction Continue if(!(Test-Path $path)) { New-Item -Path $path -ItemType "Directory" } Copy-Item -Path "$overrideSourceDirectoryPath/$sourceFolder/*" -Destination "$path" -Recurse -Force | Out-String | Write-Verbose } } else { $releaseTag = Get-GithubRelease -githubRepoUrl $url -targetDirectory $targetDirectory -moduleSourceFolder $sourceFolder -moduleTargetFolder $targetFolder -release $release -releaseArtifactName $releaseArtifactName $path = Join-Path $targetDirectory $targetFolder $releaseTag } Write-Verbose "Version $releaseTag is located in $path" return @{ path = $path releaseTag = $releaseTag } } } |