1$ErrorActionPreference = 'Stop'
2$PSNativeCommandUseErrorActionPreference = $true
3
4$CARGO_ABOUT_VERSION="0.8.2"
5$outputFile=$args[0] ? $args[0] : "$(Get-Location)/assets/licenses.md"
6$templateFile="script/licenses/template.md.hbs"
7
8New-Item -Path "$outputFile" -ItemType File -Value "" -Force
9
10@(
11 "# ###### THEME LICENSES ######\n"
12 Get-Content assets/themes/LICENSES
13 "\n# ###### ICON LICENSES ######\n"
14 Get-Content assets/icons/LICENSES
15 "\n# ###### CODE LICENSES ######\n"
16) | Add-Content -Path $outputFile
17
18$needsInstall = $false
19try {
20 $versionOutput = cargo about --version
21 if (-not ($versionOutput -match "cargo-about $CARGO_ABOUT_VERSION")) {
22 $needsInstall = $true
23 } else {
24 Write-Host "cargo-about@$CARGO_ABOUT_VERSION is already installed"
25 }
26} catch {
27 $needsInstall = $true
28}
29
30if ($needsInstall) {
31 Write-Host "Installing cargo-about@$CARGO_ABOUT_VERSION..."
32 cargo install "cargo-about@$CARGO_ABOUT_VERSION"
33}
34
35Write-Host "Generating cargo licenses"
36
37$failFlag = $env:ALLOW_MISSING_LICENSES ? "--fail" : ""
38$args = @('about', 'generate', $failFlag, '-c', 'script/licenses/zed-licenses.toml', $templateFile, '-o', $outputFile) | Where-Object { $_ }
39cargo @args
40
41Write-Host "Applying replacements"
42$replacements = @{
43 '"' = '"'
44 ''' = "'"
45 '=' = '='
46 '`' = '`'
47 '<' = '<'
48 '>' = '>'
49}
50$content = Get-Content $outputFile
51foreach ($find in $replacements.keys) {
52 $content = $content -replace $find, $replacements[$find]
53}
54$content | Set-Content $outputFile
55
56Write-Host "generate-licenses completed. See $outputFile"