|
| 1 | +# ---------------------------------------------------------------------------------- |
| 2 | +# Copyright Microsoft Corporation |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | +# ---------------------------------------------------------------------------------- |
| 13 | + |
| 14 | +# Move the UX metadata files under modules to the artifacts folder and compress them into a zip file. |
| 15 | + |
| 16 | +$RootPath = "$PSScriptRoot/.." |
| 17 | +$RepoArtifacts = 'artifacts' |
| 18 | +$UXMetadataFolder = "$RootPath/$RepoArtifacts/UX" |
| 19 | +If (-Not (Test-Path -Path $UXMetadataFolder)) |
| 20 | +{ |
| 21 | + New-Item -ItemType Directory -Path $UXMetadataFolder |
| 22 | +} |
| 23 | +Else |
| 24 | +{ |
| 25 | + Get-ChildItem $UXMetadataFolder | Remove-Item -Force -Recurse |
| 26 | +} |
| 27 | + |
| 28 | +$Modules = Get-ChildItem -Path "$RootPath/src" -Directory | ForEach-Object { $_.BaseName } |
| 29 | +ForEach ($ModuleName In $Modules) |
| 30 | +{ |
| 31 | + $SourceFolder = "$RootPath/src/$ModuleName" |
| 32 | + $MetadataFileArray = Get-ChildItem -Path $SourceFolder -Recurse -Filter UX | Get-ChildItem -Recurse -Filter *.json | ForEach-Object { $_.FullName } |
| 33 | + If ($MetadataFileArray.Length -Eq 0) |
| 34 | + { |
| 35 | + Continue |
| 36 | + } |
| 37 | + |
| 38 | + ForEach ($MetadataFile In $MetadataFileArray) |
| 39 | + { |
| 40 | + $ResourceType = [System.IO.Path]::GetFileName([System.IO.Path]::GetDirectoryName($MetadataFile)) |
| 41 | + $ResourceTypeFolder = "$UXMetadataFolder/$ResourceType" |
| 42 | + If (-Not (Test-Path -Path $ResourceTypeFolder)) |
| 43 | + { |
| 44 | + New-Item -ItemType Directory -Path $ResourceTypeFolder |
| 45 | + } |
| 46 | + $FileName = [System.IO.Path]::GetFileName($MetadataFile) |
| 47 | + $TargetPath = "$ResourceTypeFolder/$FileName" |
| 48 | + If (-Not (Test-Path -Path $TargetPath)) |
| 49 | + { |
| 50 | + Copy-Item -Path $MetadataFile -Destination $TargetPath |
| 51 | + } |
| 52 | + Else |
| 53 | + { |
| 54 | + #Merge the json files for the same resource type in hybrid module |
| 55 | + $Metadata1 = Get-Content -Path $TargetPath | ConvertFrom-Json |
| 56 | + $Metadata2 = Get-Content -Path $MetadataFile | ConvertFrom-Json |
| 57 | + $Metadata1.commands += $Metadata2.commands |
| 58 | + |
| 59 | + ConvertTo-Json -Depth 10 -InputObject $Metadata1 | Out-File -FilePath $TargetPath |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +$ArchivePath = "$RootPath/$RepoArtifacts/UX.zip" |
| 65 | +If (Test-Path -Path $ArchivePath) |
| 66 | +{ |
| 67 | + Remove-Item -Path $ArchivePath -Force |
| 68 | +} |
| 69 | +Compress-Archive -Path $UXMetadataFolder/* -DestinationPath $ArchivePath |
0 commit comments