-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
49 lines (42 loc) · 1.99 KB
/
Copy pathbuild.ps1
File metadata and controls
49 lines (42 loc) · 1.99 KB
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
$ErrorActionPreference = "Stop"
$projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$addonRoot = Join-Path $projectRoot "addon"
$versionPath = Join-Path $projectRoot "VERSION"
$manifestTemplatePath = Join-Path $addonRoot "manifest.ini.template"
$version = (Get-Content -LiteralPath $versionPath -Raw).Trim()
if ($version -notmatch '^\d+\.\d+\.\d+$') {
throw "VERSION must contain a semantic version such as 0.2.0; found '$version'"
}
$outputPath = Join-Path $projectRoot "HamCalls-$version.nvda-addon"
$temporaryZip = Join-Path $projectRoot "HamCalls-$version.zip"
$stagingRoot = Join-Path ([System.IO.Path]::GetTempPath()) "HamCalls-$version-$([guid]::NewGuid())"
$stagedAddonRoot = Join-Path $stagingRoot "addon"
$generatedCache = Join-Path $addonRoot "globalPlugins\HamCalls\__pycache__"
if (Test-Path -LiteralPath $generatedCache) {
Remove-Item -LiteralPath $generatedCache -Recurse -Force
}
try {
New-Item -ItemType Directory -Path $stagedAddonRoot | Out-Null
Copy-Item -Path (Join-Path $addonRoot "*") -Destination $stagedAddonRoot -Recurse
Remove-Item -LiteralPath (Join-Path $stagedAddonRoot "manifest.ini.template")
$manifest = (Get-Content -LiteralPath $manifestTemplatePath -Raw).Replace("{{version}}", $version)
if ($manifest -match '{{[^}]+}}') {
throw "The generated manifest contains an unresolved template value"
}
$manifestOutputPath = Join-Path $stagedAddonRoot "manifest.ini"
$utf8WithoutBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($manifestOutputPath, $manifest, $utf8WithoutBom)
if (Test-Path -LiteralPath $temporaryZip) {
Remove-Item -LiteralPath $temporaryZip
}
if (Test-Path -LiteralPath $outputPath) {
Remove-Item -LiteralPath $outputPath
}
Compress-Archive -Path (Join-Path $stagedAddonRoot "*") -DestinationPath $temporaryZip
Move-Item -LiteralPath $temporaryZip -Destination $outputPath
Write-Output $outputPath
} finally {
if (Test-Path -LiteralPath $stagingRoot) {
Remove-Item -LiteralPath $stagingRoot -Recurse -Force
}
}