Repository navigation
Expand file tree
/
Copy pathrelease.ps1
More file actions
50 lines (39 loc) · 1.63 KB
/
Copy pathrelease.ps1
File metadata and controls
50 lines (39 loc) · 1.63 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
50
$dir = $PSScriptRoot + "/bin/"
$Folder = $dir + "out"
# Ensure the folder exists
if (-not (Test-Path $Folder -PathType Container)) {
Write-Error "Folder '$Folder' does not exist."
exit 1
}
# Get all zip files in the folder
$zipFiles = Get-ChildItem -Path $Folder -Filter '*.zip' | Where-Object { -not $_.PSIsContainer }
# Get current date in YYYY-MM-DD format
$currentDate = Get-Date -Format 'yyyy-MM-dd'
# Group files by prefix (before first '_')
$groups = $zipFiles | Group-Object { $_.BaseName.Split('_')[0] }
foreach ($group in $groups) {
$prefix = $group.Name
$archiveName = $dir + $prefix + "_HSPlugins_" + $currentDate + ".zip"
Remove-Item $archiveName -ErrorAction SilentlyContinue
# Create a temporary directory for renamed files
$tempDir = Join-Path $dir "temp_$prefix"
if (Test-Path $tempDir) { Remove-Item $tempDir -Recurse -Force }
New-Item -ItemType Directory -Path $tempDir | Out-Null
# Copy and rename files to temp directory (remove prefix and underscore)
$renamedFiles = @()
foreach ($file in $group.Group) {
$originalName = $file.Name
$newName = $originalName -replace "^$prefix[_]", ''
$destPath = Join-Path $tempDir $newName
Copy-Item $file.FullName $destPath
$renamedFiles += $destPath
}
$licensePath = Join-Path $dir "..\LICENSE"
$readmePath = Join-Path $dir "..\Readme.md"
$renamedFiles += $licensePath
$renamedFiles += $readmePath
Compress-Archive -Path $renamedFiles -DestinationPath $archiveName
Write-Host "Created archive: $archiveName"
# Clean up temp directory
Remove-Item $tempDir -Recurse -Force
}