-
Notifications
You must be signed in to change notification settings - Fork 20
/
MakeZipWindows.ps1
executable file
·39 lines (33 loc) · 1.49 KB
/
MakeZipWindows.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
#!/usr/bin/env pwsh
Set-StrictMode -Version 5.0
$include_files = @( 'addon.py', 'addon.xml', 'LICENSE', 'README.md', 'service.py' )
$include_paths = @( 'resources/' )
$exclude_files = @( '*.new', '*.orig', '*.pyc' )
# Get addon metadata
[xml]$XmlDocument = Get-Content -LiteralPath 'addon.xml'
$name = $XmlDocument.addon.id
$version = $XmlDocument.addon.version
$git_hash = Invoke-Expression 'git rev-parse --short HEAD'
$zip_name = "$name-$version-$git_hash.zip"
# Remove file if it exists
if (Test-Path -LiteralPath $zip_name) {
Remove-Item -LiteralPath $zip_name
}
# Create ZIP file
Add-Type -AssemblyName System.IO.Compression.FileSystem
Write-Host -fore blue '= Building new package'
$zip_file = [System.IO.Compression.ZipFile]::Open($zip_name, 'Create')
ForEach ($relative_file in $include_files) {
$archive_file = Join-Path -Path $name -ChildPath $relative_file
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip_file, $relative_file, $archive_file)
}
ForEach ($path in $include_paths) {
Get-ChildItem -Recurse -File -Path $path -Exclude $exclude_files | ForEach-Object {
$relative_file = Resolve-Path -Path $_.FullName -Relative
$archive_file = Join-Path -Path $name -ChildPath $relative_file
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip_file, $relative_file, $archive_file)
}
}
$zip_file.Dispose()
Write-Host "= Successfully wrote package as: " -ForegroundColor:Blue -NoNewLine
Write-Host "$zip_name" -ForegroundColor:Cyan