<commit_before># params

param(
	[string]$push = "false",
	[string]$v = "",
	[string]$prerelease = "false",
	[string]$source = ""
)

# functions

function ReadLinesFromFile([string] $fileName)
{
 [string]::join([environment]::newline, (get-content -path $fileName))
}

function BuildSolution
{
  [CmdletBinding()]
  param()
  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe ..\SevenDigital.Api.Wrapper.sln /t:build /p:Configuration=Debug
}

function GetLatestFullVersionOnNuget()
{
  [CmdletBinding()]
  param()

   $packageDetails = &nuget list SevenDigital.Api.Wrapper
   $lineParts = $packageDetails.Split(' ')
   [string]$lineParts[1]
}

function GetLastVersionNumber()
{
  [CmdletBinding()]
  param()

  $fullVersionString = GetLatestFullVersionOnNuget
  $versionParts = $fullVersionString.Split('.')
  $versionParts
}

function NextFullVersion()
{
  [CmdletBinding()]
  param()
  
  $parts = GetLastVersionNumber
  $lastPart = $parts[2]
  $newVersion = [int]$lastPart + 1 
  
  $parts[2] = [string]$newVersion
  
  $newVersion = [string]::Join(".", $parts)
  $newVersion
}

function CleanupBuildArtifacts
{
  [CmdletBinding()]
  param()
  
  del SevenDigital.Api.Wrapper.nuspec
  del *.nupkg
}

# main script

BuildSolution

$fullVersion = $v
if ($fullVersion -eq "")
{
  write-output "Reading package version from nuget..."
  $fullVersion = NextFullVersion 
  if ($prerelease -eq "true")
  {
	$fullVersion = $fullVersion + "-prerelease"
  }
  write-output "Next package version from nuget: $fullVersion"
}
else
{
  write-output "Next package version from params: $fullVersion"
}


# make the nuspec file with the target version number
$nuspecTemplate = ReadLinesFromFile "SevenDigital.Api.Wrapper.nuspec.template"
$nuspecWithVersion = $nuspecTemplate.Replace("#version#", $fullVersion)
$nuspecWithVersion > SevenDigital.Api.Wrapper.nuspec

nuget pack SevenDigital.Api.Wrapper.nuspec 

$pushCommand = "NuGet Push SevenDigital.Api.Wrapper.#version#.nupkg -NonInteractive".Replace("#version#", $fullVersion)

if ($source -ne "")
{
  $pushCommand = $pushCommand + " -source $source"
}

if ($push -eq "true")
{
  # push to nuget:
  Invoke-Expression $pushCommand
  write-output "Pushed package version $fullVersion"<commit_msg>Removed the -prerelease switch from this script - it was not flexible enough, we need multiple prereleases with different names - the -v switch achieves this by allowing you to specify any version number/name - better docs now explain how to use -v to generate a named prerelease build<commit_after># params

param(
	[string]$push = "false",
	[string]$v = "",
	[string]$source = ""
)

# functions

function ReadLinesFromFile([string] $fileName)
{
 [string]::join([environment]::newline, (get-content -path $fileName))
}

function BuildSolution
{
  [CmdletBinding()]
  param()
  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe ..\SevenDigital.Api.Wrapper.sln /t:build /p:Configuration=Debug
}

function GetLatestFullVersionOnNuget()
{
  [CmdletBinding()]
  param()

   $packageDetails = &nuget list SevenDigital.Api.Wrapper
   $lineParts = $packageDetails.Split(' ')
   [string]$lineParts[1]
}

function GetLastVersionNumber()
{
  [CmdletBinding()]
  param()

  $fullVersionString = GetLatestFullVersionOnNuget
  $versionParts = $fullVersionString.Split('.')
  $versionParts
}

function NextFullVersion()
{
  [CmdletBinding()]
  param()
  
  $parts = GetLastVersionNumber
  $lastPart = $parts[2]
  $newVersion = [int]$lastPart + 1 
  
  $parts[2] = [string]$newVersion
  
  $newVersion = [string]::Join(".", $parts)
  $newVersion
}

function CleanupBuildArtifacts
{
  [CmdletBinding()]
  param()
  
  del SevenDigital.Api.Wrapper.nuspec
  del *.nupkg
}

# main script

BuildSolution

$fullVersion = $v
if ($fullVersion -eq "")
{
  write-output "Reading package version from nuget..."
  $fullVersion = NextFullVersion 
  write-output "Next package version from nuget: $fullVersion"
}
else
{
  write-output "Next package version from params: $fullVersion"
}


# make the nuspec file with the target version number
$nuspecTemplate = ReadLinesFromFile "SevenDigital.Api.Wrapper.nuspec.template"
$nuspecWithVersion = $nuspecTemplate.Replace("#version#", $fullVersion)
$nuspecWithVersion > SevenDigital.Api.Wrapper.nuspec

nuget pack SevenDigital.Api.Wrapper.nuspec 

$pushCommand = "NuGet Push SevenDigital.Api.Wrapper.#version#.nupkg -NonInteractive".Replace("#version#", $fullVersion)

if ($source -ne "")
{
  $pushCommand = $pushCommand + " -source $source"
}

if ($push -eq "true")
{
  # push to nuget:
  Invoke-Expression $pushCommand
  write-output "Pushed package version $fullVersion"
{'fraction_non_alphanumeric': 0.13494287561974563, 'fraction_numerical': 0.005604656175899978, 'mean_word_length': 4.785536159600998, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5603139', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1528, 'n_words': 345}