-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReleaseIt.ps1
155 lines (142 loc) · 5.1 KB
/
ReleaseIt.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
################################################################################
# Configs
$libVersion = "1.0";
# Die Dateien, die für das Include-Release benötigt werden
$incExtensions = @(
".h",
".hpp",
".inl"
)
$srcExtensions = @(
".c",
".cpp"
)
#Konfiguration für Windows Release-Extensions
$windowsReleaseExtensions = @(
".dll",
".lib"
)
# Konfiguration für Platformunabhängige Releaseordner
$releases = @(
@{
"name" = "includes";
"zipFile" = ".\RELEASE\ecm-$libVersion-includes.7z";
"src_dir" = "";
"src_extensions" = @();
"dirs" = @(
".\RELEASE\include\"
)
}, @{
"name" = "win32_x64";
"zipfile" = ".\RELEASE\ecm-$libVersion-win32-x64.7z";
"src_dir" = "Release-x64\";
"src_extensions" = $windowsReleaseExtensions;
"dirs" = @(
".\RELEASE\Release-x64\"
)
}, @{
"name" = "win32_x86";
"zipfile" = ".\RELEASE\ecm-$libVersion-win32-x86.7z";
"src_dir" = "Release-Win32\";
"src_extensions" = $windowsReleaseExtensions;
"dirs" = @(
".\RELEASE\Release-Win32\"
)
}, @{
"name" = "win32_x64_dev";
"zipfile" = ".\RELEASE\ecm-$libVersion-dev-win32-x64.7z";
"src_dir" = "Release-x64\";
"src_extensions" = $windowsReleaseExtensions;
"dirs" = @(
".\RELEASE\Release-x64\",
".\RELEASE\include\"
)
}, @{
"name" = "win32_x86_dev";
"zipfile" = ".\RELEASE\ecm-$libVersion-dev-win32-x86.7z";
"src_dir" = "Release-Win32\";
"src_extensions" = $windowsReleaseExtensions;
"dirs" = @(
".\RELEASE\Release-Win32\",
".\RELEASE\include\"
)
}
)
################################################################################
# Static data
$licenseText = [IO.File]::ReadAllText("LICENSE");
################################################################################
# Functions
function CopyAllFileExtensions {
param (
[string]$path,
[string]$targetPath,
[string[]]$extensions,
[bool]$copyrightSign = 0
)
# Überprüft , ob das Zielpfadverzeichnis existiert, andernfalls erstellen
if (-not (Test-Path $targetPath)) {
New-Item -ItemType Directory -Path $targetPath -Force
}
# Konvertiere den Eingabepfad in einen absoluten Pfad
$path = Resolve-Path -Path $path
# Hole alle Dateien mit den angegebenen Extensions rekursiv
Get-ChildItem -Path $path -Recurse | Where-Object {
$extensions -contains $_.Extension -and !$_.PSIsContainer
} | ForEach-Object {
$relativePath = $_.FullName.Substring($path.Length)
$destinationPath = Join-Path -Path $targetPath -ChildPath $relativePath
$destinationDir = Split-Path -Path $destinationPath -Parent
# Überprüfen, ob das Zielverzeichnis existiert, andernfalls erstellen
if (-not (Test-Path $destinationDir)) {
New-Item -ItemType Directory -Path $destinationDir -Force
}
Write-Host "Kopiere $relativePath nach $destinationPath"
# Prüfe ob Copyright-Text hinzugefügt werden soll
if ($copyrightSign -eq 1) {
# Füge Copyright-Text hinzu
$srcFileContent = [IO.File]::ReadAllText($_.FullName).Trim();
$outContent = "/*`n" + $licenseText + "*/`n`n" + $srcFileContent;
# Kopiere Datei
Set-Content -Path $destinationPath -Value $outContent -Force;
} else {
# Kopiert eine Datei ins Ziel(unter)verzeichnis
Copy-Item -Path $_.FullName -Destination $destinationPath -Force
}
}
}
function AddFileToZip {
param (
[string]$zipFile,
[string]$file
)
&"C:\Program Files\7-Zip\7z.exe" a -r -mx9 $zipFile $file
}
function AddFullDirectoryToZip {
param (
[string]$zipFile,
[string]$dir
)
&"C:\Program Files\7-Zip\7z.exe" a -r -mx9 $zipFile $dir
}
################################################################################
# Application
# Kopiere die Include-Dateien
Write-Host "Copy include files..."
CopyAllFileExtensions -path "libs\ecm" -targetPath "RELEASE\include\ecm" -extensions $incExtensions -copyrightSign 1
# Kopiere die Source-Dateien
Write-Host "Copy source files..."
CopyAllFileExtensions -path "libs\source" -targetPath "RELEASE\source" -extensions $srcExtensions -copyrightSign 1
# Kopiere die Binaries und Packe die Release-Zips
foreach ($release in $releases) {
$srcDir = $release.src_dir
$zipFile = $release.zipfile
Remove-Item -Path $zipfile
CopyAllFileExtensions -path $srcDir -targetPath "RELEASE\$srcDir" -extensions $release.src_extensions
foreach ($dir in $release.dirs) {
AddFullDirectoryToZip -zipFile $zipFile -dir $dir
}
AddFileToZip -zipFile $zipFile -file "LICENSE"
}
Write-Host "`nRelease-Tool vollständig durchgelaufen"
Start-Sleep -Seconds (60 * 1)