#requires -Version 7.0
param([Parameter(Mandatory)][string]$Destination)
$ErrorActionPreference = 'Stop'
$taskRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$Destination = [IO.Path]::GetFullPath($Destination)
New-Item -ItemType Directory -Path $Destination -Force | Out-Null
$seen = [Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
$manifest = @()
foreach ($assetsFile in Get-ChildItem -LiteralPath (Join-Path $taskRoot 'Server'),(Join-Path $taskRoot 'Client'),(Join-Path $taskRoot 'Admin') -Filter project.assets.json -Recurse) {
$assets = Get-Content -LiteralPath $assetsFile.FullName -Raw | ConvertFrom-Json -AsHashtable
foreach ($entry in $assets.libraries.GetEnumerator()) {
if ($entry.Value.type -ne 'package' -or -not $seen.Add($entry.Key)) { continue }
$package = $null
foreach ($folder in $assets.packageFolders.Keys) {
$candidate = Join-Path $folder $entry.Value.path
if (Test-Path -LiteralPath $candidate) { $package = $candidate; break }
}
if (-not $package) { throw "Restored package not found: $($entry.Key)" }
$target = Join-Path $Destination ($entry.Key.Replace('/', '-'))
New-Item -ItemType Directory -Path $target -Force | Out-Null
$metadataPath = Get-ChildItem -LiteralPath $package -Filter '*.nuspec' | Select-Object -First 1
[xml]$metadata = Get-Content -LiteralPath $metadataPath.FullName -Raw
Copy-Item -LiteralPath $metadataPath.FullName -Destination $target
foreach ($file in $entry.Value.files | Where-Object { $_ -match '(?i)(^|/)(licen[sc]e[^/]*|notice[^/]*|third.party[^/]*|copying[^/]*)$' }) {
$licenseFile = Join-Path $package $file
if (Test-Path -LiteralPath $licenseFile -PathType Leaf) {
$output = Join-Path $target $file
New-Item -ItemType Directory -Path (Split-Path $output) -Force | Out-Null
Copy-Item -LiteralPath $licenseFile -Destination $output
}
}
$manifest += [ordered]@{package=$entry.Key; license=[string]$metadata.package.metadata.license.InnerText; licenseUrl=[string]$metadata.package.metadata.licenseUrl; projectUrl=[string]$metadata.package.metadata.projectUrl}
}
}
$manifest | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $Destination 'manifest.json') -Encoding utf8
Write-Output "Retained license metadata for $($manifest.Count) restored packages"
#requires -Version 7.0
param([Parameter(Mandatory)][string]$Destination)
$ErrorActionPreference = 'Stop'
$taskRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$Destination = [IO.Path]::GetFullPath($Destination)
New-Item -ItemType Directory -Path $Destination -Force | Out-Null
$seen = [Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
$manifest = @()
foreach ($assetsFile in Get-ChildItem -LiteralPath (Join-Path $taskRoot 'Server'),(Join-Path $taskRoot 'Client'),(Join-Path $taskRoot 'Admin') -Filter project.assets.json -Recurse) {
$assets = Get-Content -LiteralPath $assetsFile.FullName -Raw | ConvertFrom-Json -AsHashtable
foreach ($entry in $assets.libraries.GetEnumerator()) {
if ($entry.Value.type -ne 'package' -or -not $seen.Add($entry.Key)) { continue }
$package = $null
foreach ($folder in $assets.packageFolders.Keys) {
$candidate = Join-Path $folder $entry.Value.path
if (Test-Path -LiteralPath $candidate) { $package = $candidate; break }
}
if (-not $package) { throw "Restored package not found: $($entry.Key)" }
$target = Join-Path $Destination ($entry.Key.Replace('/', '-'))
New-Item -ItemType Directory -Path $target -Force | Out-Null
$metadataPath = Get-ChildItem -LiteralPath $package -Filter '*.nuspec' | Select-Object -First 1
[xml]$metadata = Get-Content -LiteralPath $metadataPath.FullName -Raw
Copy-Item -LiteralPath $metadataPath.FullName -Destination $target
foreach ($file in $entry.Value.files | Where-Object { $_ -match '(?i)(^|/)(licen[sc]e[^/]*|notice[^/]*|third.party[^/]*|copying[^/]*)$' }) {
$licenseFile = Join-Path $package $file
if (Test-Path -LiteralPath $licenseFile -PathType Leaf) {
$output = Join-Path $target $file
New-Item -ItemType Directory -Path (Split-Path $output) -Force | Out-Null
Copy-Item -LiteralPath $licenseFile -Destination $output
}
}
$manifest += [ordered]@{package=$entry.Key; license=[string]$metadata.package.metadata.license.InnerText; licenseUrl=[string]$metadata.package.metadata.licenseUrl; projectUrl=[string]$metadata.package.metadata.projectUrl}
}
}
$manifest | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $Destination 'manifest.json') -Encoding utf8
Write-Output "Retained license metadata for $($manifest.Count) restored packages"