-
Notifications
You must be signed in to change notification settings - Fork 286
/
Generate-SpdxLicenseList.ps1
64 lines (52 loc) · 1.54 KB
/
Generate-SpdxLicenseList.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
<#
#>
[CmdletBinding(PositionalBinding=$False)]
Param(
[Parameter(Mandatory=$True)]
[string]$Commit,
[Parameter()]
[string]$GithubRepository = "spdx/license-list-data",
[Parameter()]
[string]$LicensesOutFile = "$PSScriptRoot/src/vcpkg/spdx-licenses.inc",
[Parameter()]
[string]$ExceptionsOutFile = "$PSScriptRoot/src/vcpkg/spdx-exceptions.inc"
)
function Transform-JsonFile {
[CmdletBinding()]
Param(
[string]$Uri,
[string]$OutFile,
[string]$OuterName,
[string]$Id
)
$req = Invoke-WebRequest -Uri $Uri
if ($req.StatusCode -ne 200)
{
Write-Error "Failed to GET $Uri"
throw
}
$json = $req.Content | ConvertFrom-Json -Depth 10
Write-Verbose "Writing output to $OutFile"
$fileContent = @(
"// Data downloaded from $Uri",
"// Generated by Generate-SpdxLicenseList.ps1")
$json.$OuterName |
Sort-Object -Property $Id -Culture '' |
ForEach-Object {
$fileContent += "`"$($_.$Id)`","
}
($fileContent -join "`n") + "`n" `
| Out-File -FilePath $OutFile -Encoding 'utf8' -NoNewline
}
$baseUrl = "https://raw.githubusercontent.com/$GithubRepository/$Commit/json"
Write-Verbose "Getting json files from $baseUrl"
Transform-JsonFile `
-Uri "$baseUrl/licenses.json" `
-OutFile $LicensesOutFile `
-OuterName 'licenses' `
-Id 'licenseId'
Transform-JsonFile `
-Uri "$baseUrl/exceptions.json" `
-OutFile $ExceptionsOutFile `
-OuterName 'exceptions' `
-Id 'licenseExceptionId'