#**************************************************************************#
#**  QUADARAX DEPLOYMENT SCRIPTS                                         **#
#**  File: 202_publish_output.ps1                                        **#
#**  Description: PowerShell script library to publish current solution  **#
#**               to output directory                                    **#
#**  Version: 1.0.                                                       **#
#**  Updated: 29.7.2019                                                  **# 
#**************************************************************************#
param(
        # Solution file name with full path. If not defined use global solution
        [string] $solutionFile,
        # Build configuration Debug / Release. If not defined use Debug
        [string] $configurationName,
        # Defines if Clean will be called before build. If not defined use $false
        [bool] $cleanBeforeBuild        
)
. ./000_bootstrap.ps1


# Validate inputs
if (!$solutionFile) { $solutionFile = $solutionName}
if (!$configurationName) { $configurationName = $buildCfgDebug}
if (!$cleanBeforeBuild) { $cleanBeforeBuild = $false}
if ($configurationName -eq $buildCfgAll){
    Write-Host ("Configuration name {0} for this script is not allowed. Use only {1},{2}." -f $buildCfgAll, $buildCfgDebug, $buildCfgRelease) -ForegroundColor Red
    Break
}

# Script body section

# May create output directory
New-Item -ItemType Directory -Force -Path $projectOutputDir

Write-Host "*** PUBLISH - START ***" -ForegroundColor Green
$slnFullPath = ("{0}\{1}" -f $projectDir, $solutionFile)
Write-Host ("Solution name: {0}" -f $slnFullPath) -ForegroundColor Yellow
Write-host ("Configuration: {0}" -f $configurationName) -ForegroundColor Yellow
Write-host ("Output directory: {0}" -f $projectOutputDir) -ForegroundColor Yellow

if ($cleanBeforeBuild -eq $true){
    Write-Host "Cleaning output directory" -ForegroundColor White
    Remove-Item -Path "$projectOutputDir\*" -Recurse
}

PublishSolution -solutionFileName $slnFullPath -configurationName $configurationName -cleanBeforeBuild $cleanBeforeBuild
Write-Host "*** PUBLISH - END ***" -ForegroundColor Green
