-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish.ps1
120 lines (97 loc) · 4.67 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
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
param(
[Parameter(Mandatory)]
[ValidateSet('Debug','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
)
########
# You need to run the following command as admin, only once.
# It installs a module that fixes a bug with Compress-Archive using backward slashes as path separators, which should be forward slashes.
# https://github.com/PowerShell/Microsoft.PowerShell.Archive/issues/48#issuecomment-491968156
#
# Install-Module Microsoft.PowerShell.Archive -MinimumVersion 1.2.3.0 -Repository PSGallery -Force
########
if ([version]$(Get-Module -ListAvailable Microsoft.PowerShell.Archive | Sort-Object Version -Descending | Select-Object Version -First 1 | Select-Object @{n='ModuleVersion'; e={$_.Version -as [string]}} | Select-Object ModuleVersion -ExpandProperty ModuleVersion) -lt [version]"1.2.3.0")
{
Write-Error -ErrorAction Stop -Message "Microsoft.PowerShell.Archive is not the correct version. Read the comments in publish.ps1 to fix this."
}
if ($DeployPath.Equals("") -Or $DeployPath.Equals("Build")){
Write-Host "Fix DeployPath"
$DeployPath = "$ValheimPath\BepInEx\plugins"
}
# Make sure Get-Location is the script path
Push-Location -Path (Split-Path -Parent $MyInvocation.MyCommand.Path)
# Add some more locations
$SolutionPath = $(Get-Location)
$PackagePath = New-Item -Type Directory -Path "$SolutionPath\Package\$Target" -Force
$ReleasePath = New-Item -Type Directory -Path "$SolutionPath\Release" -Force
$DocsPath = "$SolutionPath\Docs"
$TranslationsPath = "$ProjectPath\Translations"
# Print an overview of variables
Write-Host "Target: $Target"
Write-Host "TargetPath: $TargetPath"
Write-Host "TargetAssembly: $TargetAssembly"
Write-Host "ValheimPath: $ValheimPath"
Write-Host "ProjectPath: $ProjectPath"
Write-Host "DeployPath: $DeployPath"
Write-Host "SolutionPath: $SolutionPath"
Write-Host "PackagePath: $PackagePath"
Write-Host "ReleasePath: $ReleasePath"
Write-Host "DocsPath: $DocsPath"
Write-Host "TranslationsPath: $TranslationsPath"
# Test some preliminaries
("$TargetPath",
"$ValheimPath",
"$(Get-Location)\libraries"
) | % {
if (!(Test-Path "$_")) {Write-Error -ErrorAction Stop -Message "$_ directory 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 "& `"$SolutionPath\libraries\Debug\pdb2mdb.exe`" `"$TargetPath\$TargetAssembly`""
}
# Main Script
Write-Host "Publishing for $Target from $TargetPath"
if ($Target.Equals("Debug"))
{
$PluginPath = New-Item -Type Directory -Path "$DeployPath\$name" -Force
Write-Host "Copy $TargetAssembly to $PluginPath"
Copy-Item -Path "$TargetPath\$name.dll" -Destination "$PluginPath" -Force
Copy-Item -Path "$TargetPath\$name.pdb" -Destination "$PluginPath" -Force
Copy-Item -Path "$TargetPath\$name.dll.mdb" -Destination "$PluginPath" -Force
#Copy-Item -Path "$TranslationsPath" -Destination "$PluginPath\" -Recurse -Force
Write-Host "Packaging debug release..."
Copy-Item -Path "$TargetPath\$name.dll" -Destination "$PackagePath\" -Force
Copy-Item -Path "$TargetPath\$name.pdb" -Destination "$PackagePath\" -Force
Copy-Item -Path "$TargetPath\$name.dll.mdb" -Destination "$PackagePath\" -Force
$CompressedOutputFilename = "$ReleasePath\$name-debug-new.zip"
Compress-Archive -Path "$PackagePath\*" -DestinationPath "$CompressedOutputFilename" -Force
Write-Host "Debug package ready: $CompressedOutputFilename"
}
if($Target.Equals("Release"))
{
Write-Host "Copying SolutionDir docs... "
Copy-Item -Path "$DocsPath\SolutionDir\*" -Destination "$SolutionPath\" -Exclude @("*.tt") -Recurse -Force
Write-Host "Packaging for ThunderStore..."
$PackagePluginPath = New-Item -Type Directory -Path "$PackagePath\plugins\$name" -Force
Copy-Item -Path "$TargetPath\$TargetAssembly" -Destination "$PackagePluginPath\" -Force
#Copy-Item -Path "$TranslationsPath" -Destination "$PackagePluginPath\" -Recurse -Force
Copy-Item -Path "$SolutionPath\Images\icon.png" -Destination "$PackagePath\" -Force
$CompressedOutputFilename = "$ReleasePath\$name-new.zip"
Compress-Archive -Path "$PackagePath\*" -DestinationPath "$CompressedOutputFilename" -Force
Write-Host "Package ready: $CompressedOutputFilename"
}
# Pop Location
Pop-Location