-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
publish.ps1
95 lines (77 loc) · 3.21 KB
/
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
param(
[Parameter(Mandatory)]
[ValidateSet('Debug','DebugServer','Release')]
[System.String]$Target,
[Parameter(Mandatory)]
[System.String]$TargetPath,
[Parameter(Mandatory)]
[System.String]$TargetAssembly,
[Parameter(Mandatory)]
[System.String]$ValheimPath,
[Parameter(Mandatory)]
[System.String]$ProjectPath,
[System.String]$DeployPath
)
# Make sure Get-Location is the script path
Push-Location -Path (Split-Path -Parent $MyInvocation.MyCommand.Path)
# If debugging server set the Valheim dedicated server path
if ($Target.Equals("DebugServer")){
$ValheimServerPath = "${ValheimPath} dedicated server"
}
# Test some preliminaries
("$TargetPath",
"$ValheimPath",
"$(Get-Location)\libraries"
) | % {
if (!(Test-Path "$_")) {Write-Error -ErrorAction Stop -Message "$_ folder is missing"}
if ("$ValheimServerPath"){
if (!(Test-Path "$ValheimServerPath")) {Write-Error -ErrorAction Stop -Message "$ValheimServerPath folder is missing"}
}
}
# Plugin name without ".dll"
$name = "$TargetAssembly" -Replace('.dll')
# Create the mdb file
$pdb = "$TargetPath\$name.pdb"
if (Test-Path -Path "$pdb") {
Write-Host "Create mdb file for plugin $name"
Invoke-Expression "& `"$(Get-Location)\libraries\Debug\pdb2mdb.exe`" `"$TargetPath\$TargetAssembly`""
}
# Main Script
Write-Host "Publishing for $Target from $TargetPath"
if ($Target.Equals("Debug")) {
if ($DeployPath.Equals("")){
$DeployPaths = "$ValheimPath\BepInEx\plugins"
}
} elseif ($Target.Equals("DebugServer")) {
if ($DeployPath.Equals("")){
$DeployPaths = "$ValheimPath\BepInEx\plugins", "$ValheimServerPath\BepInEx\plugins"
}
}
if ($Target.Equals("Debug") -or $Target.Equals("DebugServer")) {
foreach ($DeployPath in $DeployPaths) {
$plug = New-Item -Type Directory -Path "$DeployPath\$name" -Force
Write-Host "Copy $TargetAssembly to $plug"
Copy-Item -Path "$TargetPath\$name.dll" -Destination "$plug" -Force
Write-Host "Copy $name.pdb to $plug"
Copy-Item -Path "$TargetPath\$name.pdb" -Destination "$plug" -Force
Write-Host "Copy $name.dll.mdb to $plug"
Copy-Item -Path "$TargetPath\$name.dll.mdb" -Destination "$plug" -Force
Write-Host "Copy Assets to $plug"
Copy-Item -Recurse -Path "$ProjectPath\Assets" -Destination "$plug" -Force
}
}
if($Target.Equals("Release")) {
Write-Host "Packaging for ThunderStore..."
$Package="Package"
$PackagePath="$ProjectPath\$Package"
Write-Host "$PackagePath\$TargetAssembly"
New-Item -Type Directory -Path "$PackagePath\plugins" -Force
New-Item -Type Directory -Path "$PackagePath\plugins\ChebsNecromancy" -Force
Copy-Item -Path "$TargetPath\$TargetAssembly" -Destination "$PackagePath\plugins\ChebsNecromancy\$TargetAssembly" -Force
Copy-Item -Path "README.md" -Destination "$PackagePath\README.md" -Force
New-Item -Type Directory -Path "$PackagePath\plugins\ChebsNecromancy\Assets" -Force
Copy-Item -Path "$ProjectPath\Assets\*" -Destination "$PackagePath\plugins\ChebsNecromancy\Assets" -Force -Recurse
Compress-Archive -Path "$PackagePath\*" -DestinationPath "$TargetPath\$TargetAssembly.zip" -Force
}
# Pop Location
Pop-Location