@@ -20,6 +20,22 @@ param (
2020 [string []] $ArtifactParam
2121)
2222
23+ function IncludePath ([string []] $pathParts ) {
24+ if ($ArtifactParam -eq $null ){
25+ return $true
26+ }
27+ ForEach ($param in $ArtifactParam ){
28+ $parts = $param.Split (' /' , [System.StringSplitOptions ]::RemoveEmptyEntries)
29+ $comp = Compare-Object $parts $pathParts
30+ if ($comp -eq $null -Or $comp -isnot [System.Array ]) {
31+ return $true
32+ }
33+ $indicators = $comp | Foreach-Object { $_.SideIndicator } | Select-Object - unique
34+ return ($indicators ).Count -eq 1
35+ }
36+ return $false
37+ }
38+
2339$ArtifactName = Split-Path - Path $PSScriptRoot - Leaf
2440
2541Write-Verbose - Message (' Generating result for {0} component' -f (Split-Path - Path $PSScriptRoot - Leaf))
@@ -60,10 +76,13 @@ if ($Artifact.Status -eq 'Present') {
6076
6177 $null = $ResultBuilder.AppendLine (' ' )
6278 for ($i = 0 ;$i -lt $Artifact.Websites.Count ;$i ++ ) {
63- $WebSiteBuilder = New-Object System.Text.StringBuilder
6479 $Site = $Artifact.Websites [$i ]
65- $null = $WebSiteBuilder.AppendLine (" # Set up website: $ ( $Site.Name ) " )
66-
80+ $include = IncludePath($Site.Name )
81+ if ($include -ne $true ){
82+ Write-Verbose " ** Skipping site path: $ ( $Site.Name ) "
83+ continue
84+ }
85+
6786 if ($Site.Applications -is [system.array ]){
6887 $mainApp = $Site.Applications.where {$_.Path -eq ' /' }
6988 }
@@ -81,68 +100,88 @@ if ($Artifact.Status -eq 'Present') {
81100 Write-Verbose - Message (' Writing instruction to create site {0}' -f $Site.Name )
82101
83102 # create empty paths for all the site directories
103+ $DirectoryBuilder = New-Object System.Text.StringBuilder
104+ $CopyBuilder = New-Object System.Text.StringBuilder
84105 $newPath = " RUN New-Item -Path 'C:$ ( $mainVirtualDir.PhysicalPath ) ' -Type Directory; `` "
85- $null = $WebSiteBuilder.AppendLine ($newPath )
86-
87- $sourcePaths = $Site.Applications.VirtualDirectories.PhysicalPath
88- ForEach ($sourcePath in $sourcePaths ) {
89- if ($sourcePath -ne $mainVirtualDir.PhysicalPath ) {
90- $newPath = " New-Item -Path 'C:$sourcePath ' -Type Directory -Force; `` "
91- $null = $WebSiteBuilder.AppendLine ($newPath )
92- }
93- }
94-
95- $null = $ResultBuilder.AppendLine ($WebSiteBuilder.ToString ().Trim().TrimEnd(' ``' ))
96- $null = $ResultBuilder.AppendLine (' ' )
97- $WebSiteBuilder = New-Object System.Text.StringBuilder
106+ $null = $DirectoryBuilder.AppendLine ($newPath )
98107
99108 # creating the website creates the default app & vdir underneath it
100- $newSite = " RUN New-Website -Name '$ ( $Site.Name ) ' -PhysicalPath 'C:$ ( $mainVirtualDir.PhysicalPath ) ' -Port $ ( $mainBinding.BindingInformation.split (' :' )[-2 ]) -Force; `` "
101- $null = $WebSiteBuilder.AppendLine ($newSite )
109+ $sourcePath = $mainVirtualDir.PhysicalPath
110+ $newSite = " RUN New-Website -Name '$ ( $Site.Name ) ' -PhysicalPath 'C:$sourcePath ' -Port $ ( $mainBinding.BindingInformation.split (' :' )[-2 ]) -Force; `` "
111+ $AppBuilder = New-Object System.Text.StringBuilder
112+ $null = $AppBuilder.AppendLine ($newSite )
113+ $copy = " COPY {0} {1}" -f (Split-Path $sourcePath - Leaf), ($sourcePath -Replace " \\" , " /" )
114+ $null = $CopyBuilder.AppendLine ($copy )
102115
103116 # now create additional apps and vdirs
104117 ForEach ($application in $Site.Applications ) {
105118 $appVirtualDir = $application.VirtualDirectories.where {$_.Path -eq ' /' }
106119 $appName = $application.Path.Substring (1 ) # remove initial '/'
107120
121+ $include = IncludePath($Site.Name , $appName )
122+ if ($appName.Length -gt 0 -And $include -ne $true ){
123+ Write-Verbose " ** Skipping app path: $ ( $Site.Name ) $ ( $application.Path ) "
124+ continue
125+ }
126+
108127 if ($appName.Length -gt 0 ) {
109128 Write-Verbose - Message (' Creating web app {0}' -f $appName )
110- $newApp = " New-WebApplication -Name '$appName ' -Site '$ ( $Site.Name ) ' -PhysicalPath 'C:$ ( $appVirtualDir.PhysicalPath ) ' -Force; `` "
111- $null = $WebSiteBuilder.AppendLine ($newApp )
129+ $sourcePath = $appVirtualDir.PhysicalPath
130+ $newApp = " New-WebApplication -Name '$appName ' -Site '$ ( $Site.Name ) ' -PhysicalPath 'C:$sourcePath ' -Force; `` "
131+ $null = $AppBuilder.AppendLine ($newApp )
132+ if ($sourcePath -ne $mainVirtualDir.PhysicalPath ) {
133+ $newPath = " New-Item -Path 'C:$sourcePath ' -Type Directory -Force; `` "
134+ $null = $DirectoryBuilder.AppendLine ($newPath )
135+
136+ $copy = " COPY {0} {1}" -f (Split-Path $sourcePath - Leaf), ($sourcePath -Replace " \\" , " /" )
137+ $null = $CopyBuilder.AppendLine ($copy )
138+ }
112139 }
113140
114141 $virtualDirectories = $application.VirtualDirectories.where {$_.Path -ne ' /' }
115142 ForEach ($virtualDir in $virtualDirectories ) {
116143 $dirName = $virtualDir.Path.Substring (1 ) # remove initial '/'
144+
145+ $include = IncludePath($Site.Name , $appName , $dirName )
146+ if ($dirName.Length -gt 0 -And $include -ne $true ){
147+ Write-Verbose " ** Skipping vdir path: $ ( $Site.Name ) $ ( $application.Path ) $ ( $virtualDir.Path ) "
148+ continue
149+ }
150+
117151 Write-Verbose - Message (' Creating virtual directory {0}' -f $dirName )
152+ $sourcePath = $virtualDir.PhysicalPath
118153 $newDir = ' '
119154 if ($appName.Length -gt 0 ) {
120- $newDir = " New-WebVirtualDirectory -Name '$dirName ' -Application '$appName ' -Site '$ ( $Site.Name ) ' -PhysicalPath 'C:$ ( $virtualDir .PhysicalPath ) '; `` "
155+ $newDir = " New-WebVirtualDirectory -Name '$dirName ' -Application '$appName ' -Site '$ ( $Site.Name ) ' -PhysicalPath 'C:$sourcePath '; `` "
121156 }
122157 else {
123- $newDir = " New-WebVirtualDirectory -Name '$dirName ' -Site '$ ( $Site.Name ) ' -PhysicalPath 'C:$ ( $virtualDir.PhysicalPath ) '; `` "
158+ $newDir = " New-WebVirtualDirectory -Name '$dirName ' -Site '$ ( $Site.Name ) ' -PhysicalPath 'C:$sourcePath '; `` "
159+ }
160+ $null = $AppBuilder.AppendLine ($newDir )
161+
162+ if ($sourcePath -ne $mainVirtualDir.PhysicalPath ) {
163+ $newPath = " New-Item -Path 'C:$sourcePath ' -Type Directory -Force; `` "
164+ $null = $DirectoryBuilder.AppendLine ($newPath )
165+
166+ $copy = " COPY {0} {1}" -f (Split-Path $sourcePath - Leaf), ($sourcePath -Replace " \\" , " /" )
167+ $null = $CopyBuilder.AppendLine ($copy )
124168 }
125- $null = $WebSiteBuilder.AppendLine ($newDir )
126169 }
127170 }
128- $null = $ResultBuilder.AppendLine ($WebSiteBuilder.ToString ().Trim().TrimEnd(' ``' ))
171+
172+ $null = $ResultBuilder.AppendLine (" # Set up website: $ ( $Site.Name ) " )
173+
174+ $null = $ResultBuilder.AppendLine ($DirectoryBuilder.ToString ().Trim().TrimEnd(' ``' ))
175+ $null = $ResultBuilder.AppendLine (' ' )
176+
177+ $null = $ResultBuilder.AppendLine ($AppBuilder.ToString ().Trim().TrimEnd(' ``' ))
129178 $null = $ResultBuilder.AppendLine (' ' )
130179
131180 Write-Verbose - Message (' Writing instruction to expose port for site {0}' -f $Site.Name )
132181 $null = $ResultBuilder.AppendLine (" EXPOSE $ ( $mainBinding.BindingInformation.split (' :' )[-2 ]) " )
133182 $null = $ResultBuilder.AppendLine (' ' )
134183
135- $sourcePaths = $Site.Applications.VirtualDirectories.PhysicalPath
136- ForEach ($sourcePath in $sourcePaths ) {
137- $SitePath = $Mount.Path + $sourcePath
138- Write-Verbose - Message (' Copying website files from {0} to {1}' -f $SitePath , $ManifestPath )
139- Copy-Item $SitePath $ManifestPath - Recurse - Force
140-
141- Write-Verbose - Message (' Writing instruction to copy files for {0} site' -f $Site.Name )
142- $copy = " COPY {0} {1}" -f (Split-Path $sourcePath - Leaf), ($sourcePath -Replace " \\" , " /" )
143- $null = $ResultBuilder.AppendLine ($copy )
144- }
145-
184+ $null = $ResultBuilder.AppendLine ($CopyBuilder.ToString ().Trim().TrimEnd(' ``' ))
146185 $null = $ResultBuilder.AppendLine (' ' )
147186 }
148187}
0 commit comments