-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakeModFolder.ps1
More file actions
128 lines (106 loc) · 3.67 KB
/
Copy pathMakeModFolder.ps1
File metadata and controls
128 lines (106 loc) · 3.67 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
#!powershell.exe -ExecutionPolicy Bypass -File
param (
[string] $Configuration
)
# Check params
if (-not $Configuration)
{
Write-Host "Usage: .\MakeModFolder.ps1 <Debug|Release>"
Exit 1
}
# Source the mod file lists
. ./ModFiles.ps1
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Find the single .sln file
$solutionFiles = Get-ChildItem -Path $scriptDir -Filter *.sln
if ($solutionFiles.Count -eq 1) {
$solutionPath = $solutionFiles[0].FullName
} else {
Write-Host "Error: Expected exactly one .sln file in $scriptDir, found $($solutionFiles.Count)."
Exit 1
}
# Build the whole solution (all three projects)
Write-Output "Building solution $solutionPath in configuration $Configuration..."
dotnet build $solutionPath -c $Configuration -v minimal /t:Rebuild | Tee-Object -FilePath 'build.log'
if ($LASTEXITCODE -ne 0)
{
Write-Error "Build failed. See build.log for details."
Exit 1
}
# Reset the Output directory
$outputRoot = Join-Path $scriptDir 'Output'
if (-not (Test-Path $outputRoot))
{
New-Item -ItemType Directory -Path $outputRoot -Force | Out-Null
} else {
Get-ChildItem $outputRoot -Recurse | Remove-Item -Force -Recurse
}
$tfm = 'net10.0'
# The two mods and where their files come from. Each becomes its own folder under Output:
# ExampleMod.Client -> copy into the server's mods/ directory (as a folder or a .zip)
# ExampleMod.Server -> copy into the server's server_mods/ directory
$clientBuildDir = Join-Path $scriptDir "ExampleMod.Client/bin/$Configuration/$tfm"
$serverBuildDir = Join-Path $scriptDir "ExampleMod.Server/bin/$Configuration/$tfm"
$contentDir = Join-Path $scriptDir 'Content'
# Copies the named files from $BaseDir into $DestRoot, preserving any relative subpaths.
function Copy-BuildArtifacts
{
param(
[Parameter(Mandatory = $true)]
[AllowEmptyCollection()]
[string[]] $Files,
[Parameter(Mandatory = $true)]
[string] $BaseDir,
[Parameter(Mandatory = $true)]
[string] $DestRoot
)
foreach ($file in $Files)
{
$sourceFile = Join-Path -Path $BaseDir -ChildPath $file
$destFile = Join-Path -Path $DestRoot -ChildPath $file
if (Test-Path -Path $sourceFile)
{
$destDir = Split-Path -Parent $destFile
if (-not (Test-Path -Path $destDir))
{
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
}
Copy-Item -Path $sourceFile -Destination $destFile -Force
Write-Output "Copied $file"
}
else
{
Write-Warning "Source file not found: $sourceFile"
}
}
}
# --- Client mod ---
$clientDest = Join-Path $outputRoot 'ExampleMod.Client'
New-Item -ItemType Directory -Path $clientDest -Force | Out-Null
$clientFiles = $clientBuildFiles
if ($Configuration -eq 'Debug')
{
$clientFiles += $clientDebugFiles
}
Write-Output "`nPackaging client mod -> $clientDest"
Copy-BuildArtifacts -Files $clientFiles -BaseDir $clientBuildDir -DestRoot $clientDest
Copy-BuildArtifacts -Files $clientContentFiles -BaseDir $contentDir -DestRoot $clientDest
# --- Server mod ---
$serverDest = Join-Path $outputRoot 'ExampleMod.Server'
New-Item -ItemType Directory -Path $serverDest -Force | Out-Null
$serverFiles = $serverBuildFiles
if ($Configuration -eq 'Debug')
{
$serverFiles += $serverDebugFiles
}
Write-Output "`nPackaging server mod -> $serverDest"
Copy-BuildArtifacts -Files $serverFiles -BaseDir $serverBuildDir -DestRoot $serverDest
# Open explorer to the output directory
if ($PSVersionTable.PSEdition -eq 'Core')
{
Start-Process "explorer.exe" -ArgumentList $outputRoot
}
else
{
Invoke-Item $outputRoot
}