49 lines
1.9 KiB
PowerShell
49 lines
1.9 KiB
PowerShell
# Prueft und verpackt alle Skills (oder nur den angegebenen) als dist\<name>-v<version>.zip.
|
|
# Im ZIP liegt der Ordner <name>/ auf oberster Ebene.
|
|
# README.md und CHANGELOG.md werden nicht mitverpackt.
|
|
# Pfade im ZIP immer mit "/" (Compress-Archive in Windows PowerShell 5.1 schreibt "\",
|
|
# das bricht den Upload). Deshalb System.IO.Compression direkt.
|
|
# Aufruf: scripts\package.ps1 [-Name <skill-name>]
|
|
param([string]$Name)
|
|
. (Join-Path $PSScriptRoot 'lib.ps1')
|
|
|
|
& (Join-Path $PSScriptRoot 'validate.ps1') -Name $Name
|
|
if ($LASTEXITCODE -ne 0) { exit 1 }
|
|
|
|
Add-Type -AssemblyName System.IO.Compression
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
|
|
if ($Name) { $names = @($Name) } else { $names = @(Get-SkillNames) }
|
|
New-Item -ItemType Directory -Force -Path $DistDir | Out-Null
|
|
$exclude = @('CHANGELOG.md', 'README.md', '.DS_Store', 'Thumbs.db')
|
|
|
|
foreach ($n in $names) {
|
|
$src = (Get-Item (Join-Path $SkillsDir $n)).FullName
|
|
$version = Get-SkillVersion $src
|
|
$zipPath = Join-Path $DistDir "$n-v$version.zip"
|
|
if (Test-Path $zipPath) { Remove-Item $zipPath }
|
|
|
|
$files = @(Get-ChildItem -Path $src -Recurse -File -Force |
|
|
Where-Object { $exclude -notcontains $_.Name } |
|
|
ForEach-Object { $_.FullName })
|
|
[Array]::Sort($files, [StringComparer]::Ordinal)
|
|
|
|
$zip = [IO.Compression.ZipFile]::Open($zipPath, [IO.Compression.ZipArchiveMode]::Create)
|
|
try {
|
|
[void]$zip.CreateEntry("$n/")
|
|
foreach ($f in $files) {
|
|
$rel = $f.Substring($src.Length).TrimStart('\', '/') -replace '\\', '/'
|
|
[void][IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $f, "$n/$rel")
|
|
}
|
|
}
|
|
finally { $zip.Dispose() }
|
|
|
|
Write-Host ''
|
|
Write-Host "dist/$n-v$version.zip"
|
|
$read = [IO.Compression.ZipFile]::OpenRead($zipPath)
|
|
try {
|
|
foreach ($e in $read.Entries) { Write-Host ('{0,9} {1}' -f $e.Length, $e.FullName) }
|
|
}
|
|
finally { $read.Dispose() }
|
|
}
|