-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathzipplugin.ps1
45 lines (36 loc) · 1.61 KB
/
zipplugin.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
param (
[Parameter(Mandatory=$true, Position=0)]
[string]$projectdir,
[Parameter(Mandatory=$true, Position=1)]
[string]$builddir,
[Parameter(Mandatory=$true, Position=2)]
[string]$outputPath,
[Parameter(Mandatory=$false, Position=4)]
[string]$buildId
)
Write-Host "projectdir=${projectdir}"
Write-Host "builddir=${builddir}"
Write-Host "outputPath=${outputPath}"
Write-Host "buildId=${buildId}"
New-Item -ItemType Directory -Force -Path $outputPath
Copy-Item -Path $projectdir\Manifest.json $builddir
$local:ManifestFile = (Join-Path $builddir "Manifest.json")
if ($buildId) {
Write-Host "Replacing version marker in manifest file"
$local:VersionMarker = ".9999"
$local:BuildNumber = ($buildId % 65535) # max value for version part on Windows is 65534
(Get-Content $local:ManifestFile -Raw).replace($local:VersionMarker, ".${local:BuildNumber}") | Set-Content -Encoding UTF8 $local:ManifestFile
}
$local:manifestProperties = (Get-Content $local:ManifestFile -Raw) | ConvertFrom-Json
$local:zipfileName = $local:manifestProperties.Name
$local:version = $local:manifestProperties.Version
Write-Host "${local:ziplfileName} ${local:version}"
$local:zipfilePath = (Join-Path $outputPath "${local:zipfileName}-${local:version}.zip")
Write-Host "zip file output path=${local:zipfilePath}"
if (Test-Path $local:zipfilePath)
{
Remove-Item $local:zipfilePath
}
Add-Type -Assembly System.IO.Compression.FileSystem
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory($builddir, $local:zipfilePath, $compressionLevel, $false)