-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathNew-FolderStructure.ps1
More file actions
60 lines (46 loc) · 2.12 KB
/
New-FolderStructure.ps1
File metadata and controls
60 lines (46 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 = ""
)
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) {
Write-Verbose "Folder $path already exists, so not copying files."
} else {
Write-InformationColored "Copying files from $overrideSourceDirectoryPath to $path" -ForegroundColor Green -InformationAction Continue
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
}
}
}