-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.ps1
More file actions
130 lines (105 loc) · 3.98 KB
/
Copy pathpackage.ps1
File metadata and controls
130 lines (105 loc) · 3.98 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
param (
[switch]$NoArchive,
[string]$OutputDirectory = $PSScriptRoot
)
$ErrorActionPreference = "Stop"
Set-Location -Path $PSScriptRoot
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host "=== Packe die Mod ===" -ForegroundColor Cyan
Write-Host ""
# -------------------------------------------------
# Checks
# -------------------------------------------------
if (!(Test-Path "info.json")) { throw "info.json fehlt!" }
if (!(Test-Path "build")) { throw "build/-Ordner fehlt!" }
# -------------------------------------------------
# Mod-Infos
# -------------------------------------------------
$modInfo = Get-Content -Raw "info.json" | ConvertFrom-Json
$modId = $modInfo.Id
$modVersion = $modInfo.Version
Write-Host "Mod-ID: $modId"
Write-Host "Version: $modVersion"
# -------------------------------------------------
# Zielverzeichnisse
# -------------------------------------------------
$DistDir = Join-Path $OutputDirectory "dist"
$BackupDir = Join-Path $OutputDirectory "backup"
New-Item -Path $DistDir -ItemType Directory -Force | Out-Null
New-Item -Path $BackupDir -ItemType Directory -Force | Out-Null
# -------------------------------------------------
# TEMP Ordner (ORIGINALVERHALTEN)
# -------------------------------------------------
$TmpDir = Join-Path $DistDir "tmp"
$ZipOutDir = Join-Path $TmpDir $modId
if (Test-Path $ZipOutDir) {
Remove-Item $ZipOutDir -Recurse -Force
}
New-Item -Path $ZipOutDir -ItemType Directory -Force | Out-Null
# -------------------------------------------------
# RELEASE Dateien sammeln (EXAKT WIE IM ORIGINAL)
# -------------------------------------------------
$FilesToInclude = @(
"info.json",
"build\*",
"LICENSE"
)
foreach ($item in $FilesToInclude) {
Copy-Item -Path $item -Destination $ZipOutDir -Recurse -Force
}
# -------------------------------------------------
# ZIP erstellen (dist)
# -------------------------------------------------
if (-not $NoArchive) {
$fileName = "${modId}_v${modVersion}.zip"
$zipPath = Join-Path $DistDir $fileName
Compress-Archive `
-Path (Join-Path $ZipOutDir "*") `
-DestinationPath $zipPath `
-CompressionLevel Fastest `
-Force
Write-Host "ZIP erstellt: dist\$fileName"
# =================================================
# SOURCE BACKUP – BIN/OBJ ABSOLUT AUSGESCHLOSSEN
# =================================================
$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$sourceBackupName = "${modId}_v${modVersion}_$timestamp.zip"
$sourceBackupPath = Join-Path $BackupDir $sourceBackupName
$sourceTmp = Join-Path $TmpDir "source"
if (Test-Path $sourceTmp) {
Remove-Item $sourceTmp -Recurse -Force
}
New-Item -Path $sourceTmp -ItemType Directory -Force | Out-Null
$sourceFiles = Get-ChildItem -Path $PSScriptRoot -Recurse -File |
Where-Object {
$rel = $_.FullName.Substring($PSScriptRoot.Length).TrimStart('\','/')
# HARTE Ausschlüsse (egal wo im Pfad)
if ($rel -match '(^|[\\/])bin([\\/]|$)') { return $false }
if ($rel -match '(^|[\\/])obj([\\/]|$)') { return $false }
if ($rel -match '(^|[\\/])build([\\/]|$)') { return $false }
if ($rel -match '(^|[\\/])dist([\\/]|$)') { return $false }
if ($rel -match '(^|[\\/])backup([\\/]|$)'){ return $false }
# NUR Quellformate
return $_.Extension -in ".cs", ".csproj", ".txt"
}
foreach ($f in $sourceFiles) {
Copy-Item $f.FullName (Join-Path $sourceTmp $f.Name) -Force
}
Compress-Archive `
-Path (Join-Path $sourceTmp "*") `
-DestinationPath $sourceBackupPath `
-CompressionLevel Optimal `
-Force
Remove-Item $sourceTmp -Recurse -Force
Write-Host "Source-Backup erstellt: backup\$sourceBackupName"
}
else {
Write-Host "Archivieren übersprungen (-NoArchive)"
}
Write-Host ""
Write-Host "=== FERTIG ===" -ForegroundColor Green
Write-Host ""
Write-Host ""
Write-Host ""