-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprepare-publish.ps1
76 lines (60 loc) · 3.05 KB
/
prepare-publish.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
#Requires -Version 7.0
$ErrorActionPreference = "Stop"
Set-Location $PSScriptRoot
function ZipFiles($zipfilename, $sourcedir) {
Add-Type -Assembly System.IO.Compression.FileSystem
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, $zipfilename, $compressionLevel, $false)
MarkFilesInZipAsReadableOnLinux $zipfilename
}
function MarkFilesInZipAsReadableOnLinux($zipfilename) {
$zip = [System.IO.Compression.ZipFile]::Open($zipfilename, [System.IO.Compression.ZipArchiveMode]::Update)
foreach ($entry in $zip.Entries) {
$entry.ExternalAttributes = $entry.ExternalAttributes -bor ([Convert]::ToInt32("444", 8) -shl 16)
}
$zip.Dispose();
}
function ZipFile($zipfilename, $sourcefile) {
$sourceDir = Split-Path (Resolve-Path $sourcefile)
$tempDir = Join-Path $sourceDir "tempZipDir/"
New-Item $tempDir -ItemType Directory
Copy-Item $sourcefile $tempDir
ZipFiles $zipfilename $tempDir
Write-Host "Want to remove: $($tempDir)"
Remove-Item (Join-Path $tempDir (Split-Path -Leaf $sourcefile))
Remove-Item $tempDir
}
if (Test-Path dist) {
Get-ChildItem -Path "dist" -Recurse | Remove-Item -Force -Recurse
}
New-Item -ItemType directory -Path (Join-Path "dist" "release")
New-Item -ItemType directory -Path (Join-Path "dist" "source")
New-Item -ItemType directory -Path (Join-Path "dist" "ftp")
Copy-Item -Path "includes" -Destination (Join-Path "dist" "source") -Recurse
$plugins = @("waitforstv", "medicstats", "supstats2", "logstf", "restorescore", "countdown", "fixstvslot", "pause", "recordstv", "classwarning", "afk");
foreach ($p in $plugins) {
Write-Host "Compiling $p..."
& "spcomp" "$p.sp" "-i" (Join-Path ".." "includes") "-D" $p
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed compilation of $p"
Exit 1
}
# Copy the .smx and update.txt file to UPDATE
New-Item -ItemType directory -Path (Join-Path "dist" "ftp\$p\plugins")
Copy-Item -Path (Join-Path $p "update.txt") -Destination (Join-Path "dist" "ftp\$p")
Copy-Item -Path (Join-Path $p "$p.smx") -Destination (Join-Path "dist" "ftp\$p\plugins")
# Copy the .smx file to the common RELEASE directory
Copy-Item -Path (Join-Path $p "$p.smx") -Destination (Join-Path "dist" "release")
# Copy the .sp and .inc file to the common SOURCE directory
Copy-Item -Path (Join-Path $p "$p.sp") -Destination (Join-Path "dist" "source")
if (Test-Path (Join-Path $p "$p.inc")) {
Copy-Item -Path (Join-Path $p "$p.inc") -Destination (Join-Path "dist" "source/includes")
}
# Zip the single smx file
ZipFile (Join-Path $PSScriptRoot "dist" "ftp\$p.zip") (Join-Path $PSScriptRoot $p "$p.smx")
}
# Zip the common RELEASE directory
ZipFiles (Join-Path $PSScriptRoot "dist" "ftp\f2-sourcemod-plugins.zip") (Join-Path $PSScriptRoot "dist" "release")
# Zip the common SOURCE directory
ZipFiles (Join-Path $PSScriptRoot "dist" "ftp\f2-sourcemod-plugins-src.zip") (Join-Path $PSScriptRoot "dist" "source")
Write-Host "Finished successfully"