Skip to content

Commit

Permalink
Add packaging script
Browse files Browse the repository at this point in the history
  • Loading branch information
DrakiaXYZ committed Jul 20, 2024
1 parent 14b88ec commit b11cabe
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
14 changes: 13 additions & 1 deletion DrakiaXYZ-BigBrain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Package|AnyCPU'">
<OutputPath>bin\Package\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\..\BepInEx\core\0Harmony.dll</HintPath>
Expand Down Expand Up @@ -110,6 +119,9 @@
<PreBuildEvent>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(ProjectDir)\VersionChecker\setbuild.ps1</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(ProjectDir)\..\..\BepInEx\plugins\$(TargetFileName)"</PostBuildEvent>
<PostBuildEvent>copy "$(TargetPath)" "$(ProjectDir)\..\..\BepInEx\plugins\$(TargetFileName)"
if $(ConfigurationName) == Package (
powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(ProjectDir)\package.ps1
)</PostBuildEvent>
</PropertyGroup>
</Project>
3 changes: 3 additions & 0 deletions DrakiaXYZ-BigBrain.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Package|Any CPU = Package|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C3C9EBDF-AF8A-4E59-B18F-E76FAE66001C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3C9EBDF-AF8A-4E59-B18F-E76FAE66001C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3C9EBDF-AF8A-4E59-B18F-E76FAE66001C}.Package|Any CPU.ActiveCfg = Package|Any CPU
{C3C9EBDF-AF8A-4E59-B18F-E76FAE66001C}.Package|Any CPU.Build.0 = Package|Any CPU
{C3C9EBDF-AF8A-4E59-B18F-E76FAE66001C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3C9EBDF-AF8A-4E59-B18F-E76FAE66001C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
50 changes: 50 additions & 0 deletions package.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Configuration
$packageDir = '.\Package'
$artifactDir = '.\bin\Package'

# Make sure our CWD is where the script lives
Set-Location $PSScriptRoot

# Fetch the plugin info
$assemblyInfoPath = 'Properties\AssemblyInfo.cs'
$versionPattern = '^\[assembly: AssemblyVersion\("(.*)"\)\]'
$namePattern = '<AssemblyName>(.*)</AssemblyName>'
(Get-Content $assemblyInfoPath) | ForEach-Object {
if ($_ -match $versionPattern) {
$assemblyVersion = [version]$matches[1]
}
}
$csprojPath = Get-ChildItem '.' -filter '*.csproj'
(Get-Content $csprojPath) | ForEach-Object {
if ($_ -match $namePattern) {
$modName = $matches[1]
}
}

# Format the version number for our archive
$modVersion = '{0}.{1}.{2}' -f $assemblyVersion.Major, $assemblyVersion.Minor, $assemblyVersion.Build
if ($assemblyVersion.Revision -ne 0)
{
$modVersion = '{0}.{1}' -f $modVersion, $assemblyVersion.Revision
}

Write-Host ('Packaging {0} v{1}' -f $modName, $modVersion)

# Create the package structure
$bepInExDir = '{0}\BepInEx' -f $packageDir
$pluginsDir = '{0}\plugins' -f $bepInExDir
$null = mkdir $pluginsDir -ea 0

# Copy required files to the package structure
$artifactPath = ('{0}\{1}.dll' -f $artifactDir, $modName)
Copy-Item $artifactPath -Destination $pluginsDir

# Create the archive
$archivePath = '{0}\{1}-{2}.7z' -f $packageDir, $modName, $modVersion
if (Test-Path $archivePath)
{
Remove-Item $archivePath
}
7z a $archivePath $bepInExDir

Write-Host ('Mod packaging complete')

0 comments on commit b11cabe

Please sign in to comment.