-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-deprecated.ps1
97 lines (83 loc) · 3.43 KB
/
generate-deprecated.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
$ErrorActionPreference="Stop"
$outputDir = mkdir "_gen" -force
$tasksToPatch = @("NuGetRestore", "NuGetInstaller", "NuGetAuthenticate", "NuGetPackager", "NuGet", "NuGetPublisher")
$taskKinds = @("deprecated")
$filesToPatch = @()
foreach ($task in $tasksToPatch)
{
$filesToPatch += Get-ChildItem "_download/$task.*.zip"
}
foreach ($task in $filesToPatch)
{
foreach ($kind in $taskKinds)
{
if (Test-Path "_tmp")
{
Remove-Item "_tmp" -force -Recurse
}
$taskDir = "_tmp"
if (Test-Path -path "_gen\$($task.Name -replace '([^.]+).*-',"`$1-$kind.*")" -PathType Leaf)
{
continue
}
# Expand-Archive -Path $task -DestinationPath _tmp
& "C:\Program Files\7-Zip\7z.exe" x $task -o_tmp task*.json *.resjson -r -bd
if ($LASTEXITCODE -ne 0)
{
Remove-item $task
Write-Error "Failed to extract $task"
continue
}
$taskManifestFiles = @("task.loc.json", "task.json")
$manifest = @{}
foreach ($taskManifestFile in $taskManifestFiles)
{
$manifestPath = "$taskDir/$taskManifestFile"
if (Test-Path -Path $manifestPath -PathType Leaf)
{
$manifest = (Get-Content $manifestPath -raw) | ConvertFrom-Json
$manifest.name = "$($manifest.name)-deprecated"
if ($taskManifestFile -eq "task.json")
{
$manifest.friendlyName = "$($manifest.friendlyName) (Deprecated)"
if (Test-Path -Path "$taskDir\Strings" -PathType Container)
{
$resourceFiles = Get-ChildItem "$taskDir\Strings\resources.resjson\resources.resjson" -recurse -ErrorAction "Continue"
foreach ($resourceFile in $resourceFiles)
{
$resources = (Get-Content $resourceFile -raw) | ConvertFrom-Json -AsHashtable
if ($resources["loc.friendlyName"])
{
$resources["loc.friendlyName"] = $manifest.friendlyName
}
$resources | ConvertTo-Json -depth 100 | Out-File $resourceFile -Encoding utf8NoBOM
}
}
}
$manifest.id = Get-UUIDv5 $manifest.id $manifest.name
$manifest.author = "Jesse Houwing"
$manifest.PSObject.Properties.Remove('removalDate')
if (-not $manifest.deprecated)
{
$manifest | Add-Member -MemberType NoteProperty -Name "deprecated" -Value $true
}
$manifest | ConvertTo-Json -depth 100 | Out-File $manifestPath -Encoding utf8NoBOM
}
}
$taskName = $manifest.name
$taskid = $manifest.id
$taskversion = "$($manifest.version.Major).$($manifest.version.Minor).$($manifest.version.Patch)"
$taskZip = "$taskName.$taskid-$taskversion.zip"
Copy-Item $task "_gen\$taskzip"
Push-Location _tmp
& "C:\Program Files\7-Zip\7z.exe" u "$outputDir\$taskzip" "*" -r -bd
if ($LASTEXITCODE -ne 0)
{
Remove-Item "$outputDir\$taskzip"
Write-Error "Failed to compress $task"
continue
}
write-output "Created: $taskzip"
Pop-Location
}
}