|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | +Move metadata JSON and package-level overview markdown files for deprecated packages to the legacy folder. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | +Move onboarding information to the "legacy" moniker for whose support is "deprecated" in the Metadata CSV. |
| 7 | +Only one version of a package can be documented in the "legacy" moniker. If multiple versions are available, |
| 8 | +the "latest" version will be used and the "preview" version will be deleted. |
| 9 | +
|
| 10 | +.PARAMETER DocRepoLocation |
| 11 | +The location of the target docs repository. |
| 12 | +#> |
| 13 | + |
| 14 | +param( |
| 15 | + [Parameter(Mandatory = $true)] |
| 16 | + [string] $DocRepoLocation |
| 17 | +) |
| 18 | + |
| 19 | +. (Join-Path $PSScriptRoot common.ps1) |
| 20 | + |
| 21 | +Set-StrictMode -Version 3 |
| 22 | + |
| 23 | +function getPackageMetadata($moniker) { |
| 24 | + $jsonFiles = Get-ChildItem -Path (Join-Path $DocRepoLocation "metadata/$moniker") -Filter *.json |
| 25 | + $metadata = @{} |
| 26 | + |
| 27 | + foreach ($jsonFile in $jsonFiles) { |
| 28 | + $packageMetadata = Get-Content $jsonFile -Raw | ConvertFrom-Json -AsHashtable |
| 29 | + $packageIdentity = $packageMetadata.Name |
| 30 | + if (Test-Path "Function:$GetPackageIdentity") { |
| 31 | + $packageIdentity = &$GetPackageIdentity $packageMetadata |
| 32 | + } |
| 33 | + |
| 34 | + $metadata[$packageIdentity] = @{ File = $jsonFile; Metadata = $packageMetadata } |
| 35 | + } |
| 36 | + |
| 37 | + return $metadata |
| 38 | +} |
| 39 | + |
| 40 | +function getPackageInfoFromLookup($packageIdentity, $version, $lookupTable) { |
| 41 | + if ($lookupTable.ContainsKey($packageIdentity)) { |
| 42 | + if ($lookupTable[$packageIdentity]['Metadata'].Version -eq $version) { |
| 43 | + # Only return if the version matches |
| 44 | + return $lookupTable[$packageIdentity] |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + return $null |
| 49 | +} |
| 50 | + |
| 51 | +function moveToLegacy($packageInfo) { |
| 52 | + $docsMsMetadata = &$GetDocsMsMetadataForPackageFn -PackageInfo $packageInfo['Metadata'] |
| 53 | + |
| 54 | + Write-Host "Move to legacy: $($packageInfo['Metadata'].Name)" |
| 55 | + $packageInfoPath = $packageInfo['File'] |
| 56 | + Move-Item "$($packageInfoPath.Directory)/$($packageInfoPath.BaseName).*" "$DocRepoLocation/metadata/legacy/" -Force |
| 57 | + |
| 58 | + $readmePath = "$DocRepoLocation/$($docsMsMetadata.PreviewReadMeLocation)/$($docsMsMetadata.DocsMsReadMeName)-readme.md" |
| 59 | + if (Test-Path $readmePath) { |
| 60 | + Move-Item ` |
| 61 | + $readmePath ` |
| 62 | + "$DocRepoLocation/$($docsMsMetadata.LegacyReadMeLocation)/" ` |
| 63 | + -Force |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +function deletePackageInfo($packageInfo) { |
| 68 | + $docsMsMetadata = &$GetDocsMsMetadataForPackageFn -PackageInfo $packageInfo['Metadata'] |
| 69 | + |
| 70 | + Write-Host "Delete superseded package: $($packageInfo['Metadata'].Name)" |
| 71 | + $packageInfoPath = $packageInfo['File'] |
| 72 | + Remove-Item "$($packageInfoPath.Directory)/$($packageInfoPath.BaseName).*" -Force |
| 73 | + |
| 74 | + $readmePath = "$DocRepoLocation/$($docsMsMetadata.PreviewReadMeLocation)/$($docsMsMetadata.DocsMsReadMeName)-readme.md" |
| 75 | + if (Test-Path $readmePath) { |
| 76 | + Remove-Item $readmePath -Force |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +$metadataLookup = @{ |
| 81 | + 'latest' = getPackageMetadata 'latest' |
| 82 | + 'preview' = getPackageMetadata 'preview' |
| 83 | +} |
| 84 | +$deprecatedPackages = (Get-CSVMetadata).Where({ $_.Support -eq 'deprecated' }) |
| 85 | + |
| 86 | +foreach ($package in $deprecatedPackages) { |
| 87 | + $packageIdentity = $package.Package |
| 88 | + if (Test-Path "Function:$GetPackageIdentityFromCsvMetadata") { |
| 89 | + $packageIdentity = &$GetPackageIdentityFromCsvMetadata $package |
| 90 | + } |
| 91 | + |
| 92 | + $packageInfoPreview = $packageInfoLatest = $null |
| 93 | + if ($package.VersionPreview) { |
| 94 | + $packageInfoPreview = getPackageInfoFromLookup ` |
| 95 | + -packageIdentity $packageIdentity ` |
| 96 | + -version $package.VersionPreview ` |
| 97 | + -lookupTable $metadataLookup['preview'] |
| 98 | + } |
| 99 | + |
| 100 | + if ($package.VersionGA) { |
| 101 | + $packageInfoLatest = getPackageInfoFromLookup ` |
| 102 | + -packageIdentity $packageIdentity ` |
| 103 | + -version $package.VersionGA ` |
| 104 | + -lookupTable $metadataLookup['latest'] |
| 105 | + } |
| 106 | + |
| 107 | + if (!$packageInfoPreview -and !$packageInfoLatest) { |
| 108 | + # Nothing to move or delete |
| 109 | + continue |
| 110 | + } |
| 111 | + |
| 112 | + if ($packageInfoPreview -and $packageInfoLatest) { |
| 113 | + # Delete metadata JSON and package-level overview markdown files for |
| 114 | + # the preview version instead of moving both. This mitigates situations |
| 115 | + # where the "latest" verison doesn't have a package-level overview |
| 116 | + # markdown file and the "preview" version does. |
| 117 | + deletePackageInfo $packageInfoPreview |
| 118 | + moveToLegacy $packageInfoLatest |
| 119 | + } else { |
| 120 | + moveToLegacy ($packageInfoPreview ?? $packageInfoLatest) |
| 121 | + } |
| 122 | +} |
0 commit comments