@@ -7,10 +7,10 @@ Saves package properties in source of a given service directory to JSON files.
77JSON files are named in the form <package name>.json or <artifact name>.json if
88an artifact name property is available in the package properties.
99
10- Can optionally add a dev version property which can be used logic for daily
10+ Can optionally add a dev version property which can be used logic for daily
1111builds.
1212
13- In cases of collisions where track 2 packages (IsNewSdk = true) have the same
13+ In cases of collisions where track 2 packages (IsNewSdk = true) have the same
1414filename as track 1 packages (e.g. same artifact name or package name), the
1515track 2 package properties will be written.
1616
@@ -21,30 +21,31 @@ Service directory in which to search for packages.
2121A file path leading to a file generated from Generate-PR-Diff.json. This parameter takes precedence over serviceDirectory, do not provide both.
2222
2323. PARAMETER outDirectory
24- Output location (generally a package artifact directory in DevOps) for JSON
24+ Output location (generally a package artifact directory in DevOps) for JSON
2525files
2626
2727. PARAMETER addDevVersion
28- Reads the version out of the source and adds a DevVersion property to the
29- package properties JSON file. If the package properties JSON file already
28+ Reads the version out of the source and adds a DevVersion property to the
29+ package properties JSON file. If the package properties JSON file already
3030exists, read the Version property from the existing package properties JSON file
3131and set that as the Version property for the new output. This has the effect of
32- "adding" a DevVersion property to the file which could be different from the
32+ "adding" a DevVersion property to the file which could be different from the
3333Verison property in that file.
3434#>
3535
3636[CmdletBinding ()]
3737Param (
3838 [string ] $serviceDirectory ,
39- [Parameter (Mandatory = $True )]
39+ [Parameter (Mandatory = $True )]
4040 [string ] $outDirectory ,
4141 [string ] $prDiff ,
4242 [switch ] $addDevVersion
4343)
4444
4545. (Join-Path $PSScriptRoot common.ps1)
4646
47- function SetOutput ($outputPath , $incomingPackageSpec ) {
47+ function SetOutput ($outputPath , $incomingPackageSpec )
48+ {
4849
4950 # If there is an exsiting package info json file read that and set that as output object which gets properties updated here.
5051 if (Test-Path $outputPath )
@@ -56,7 +57,7 @@ function SetOutput($outputPath, $incomingPackageSpec) {
5657 {
5758 $outputObject = $incomingPackageSpec
5859 }
59-
60+
6061
6162 if ($addDevVersion )
6263 {
@@ -75,16 +76,19 @@ function SetOutput($outputPath, $incomingPackageSpec) {
7576 - Value (ConvertTo-Json - InputObject $outputObject - Depth 100 )
7677}
7778
78- function GetRelativePath ($path ) {
79+ function GetRelativePath ($path )
80+ {
7981 # If the path is empty return an empty string
80- if (! $path ) {
82+ if (! $path )
83+ {
8184 return ' '
8285 }
8386
8487 # If the path is already relative return the path. Calling `GetRelativePath`
8588 # on a relative path converts the relative path to an absolute path based on
8689 # the current working directory which can result in unexpected outputs.
87- if (! [IO.Path ]::IsPathRooted($path )) {
90+ if (! [IO.Path ]::IsPathRooted($path ))
91+ {
8892 return $path
8993 }
9094
@@ -98,22 +102,26 @@ $exportedPaths = @{}
98102
99103$allPackageProperties = @ ()
100104
101- if ($prDiff ) {
105+ if ($prDiff )
106+ {
102107 Write-Host " Getting package properties for PR diff file: $prDiff "
103108 $allPackageProperties = Get-PrPkgProperties $prDiff
104109
105- if (! $allPackageProperties ) {
110+ if (! $allPackageProperties )
111+ {
106112 Write-Host " No packages found matching PR diff file $prDiff "
107113 Write-Host " Setting NoPackagesChanged variable to true"
108114 Write-Host " ##vso[task.setvariable variable=NoPackagesChanged]true"
109115 exit 0
110116 }
111117}
112- else {
118+ else
119+ {
113120 Write-Host " Getting package properties for service directory: $serviceDirectory "
114121 $allPackageProperties = Get-AllPkgProperties $serviceDirectory
115122
116- if (! $allPackageProperties ) {
123+ if (! $allPackageProperties )
124+ {
117125 Write-Error " Package properties are not available for service directory $serviceDirectory "
118126 exit 1
119127 }
@@ -124,21 +132,26 @@ if (-not (Test-Path -Path $outDirectory))
124132 New-Item - ItemType Directory - Force - Path $outDirectory | Out-Null
125133}
126134
127- foreach ($pkg in $allPackageProperties )
135+ foreach ($pkg in $allPackageProperties )
128136{
129- if ($pkg.Name ) {
137+ if ($pkg.Name )
138+ {
139+ Write-Host " "
130140 Write-Host " Package Name: $ ( $pkg.Name ) "
131141 Write-Host " Package Version: $ ( $pkg.Version ) "
132142 Write-Host " Package SDK Type: $ ( $pkg.SdkType ) "
133143 Write-Host " Artifact Name: $ ( $pkg.ArtifactName ) "
134144 Write-Host " Release date: $ ( $pkg.ReleaseStatus ) "
135145 $configFilePrefix = $pkg.Name
146+
136147 if ($pkg.ArtifactName )
137148 {
138149 $configFilePrefix = $pkg.ArtifactName
139150 }
151+
140152 $outputPath = Join-Path - Path $outDirectory " $configFilePrefix .json"
141153 Write-Host " Output path of json file: $outputPath "
154+
142155 $outDir = Split-Path $outputPath - parent
143156 if (-not (Test-Path - path $outDir ))
144157 {
@@ -148,14 +161,17 @@ foreach($pkg in $allPackageProperties)
148161
149162 # If package properties for a track 2 (IsNewSdk = true) package has
150163 # already been written, skip writing to that same path.
151- if ($exportedPaths.ContainsKey ($outputPath ) -and $exportedPaths [$outputPath ].IsNewSdk -eq $true ) {
164+ if ($exportedPaths.ContainsKey ($outputPath ) -and $exportedPaths [$outputPath ].IsNewSdk -eq $true )
165+ {
152166 Write-Host " Track 2 package info with file name $ ( $outputPath ) already exported. Skipping export."
153167 continue
154168 }
155- $exportedPaths [$outputPath ] = $pkg
156169
170+ $exportedPaths [$outputPath ] = $pkg
157171 SetOutput $outputPath $pkg
158172 }
159173}
160174
161- Get-ChildItem - Path $outDirectory
175+ $fileNames = (Get-ChildItem - Path $outDirectory ).Name
176+ Write-Host " `n Files written to $outDirectory `:"
177+ Write-Host " $ ( $fileNames -join " `n " ) "
0 commit comments