<commit_before>function RestoreNugetPackages($solutionPath) {
	$packagesDirectory = Resolve-Path "$PSScriptRoot\..\packages"
	$nugetPath = "$packagesDirectory\NuGet.CommandLine.3.4.3\tools\NuGet.exe"
	
	& $nugetPath restore -PackagesDirectory $packagesDirectory $solutionPath
}

function EnsureDeploymentOutputExists($deploymentOutput) {
	if (-Not (Test-Path $deploymentOutput)) {
		New-Item -ItemType Directory $deploymentOutput
	}
}

function DeployEsf() {
	Write-Host -ForegroundColor Cyan "Deployment process of ES Fiddle"
	Import-Module $PSScriptRoot\MSBuild.psm1
	$esfSolution = Resolve-Path "$PSScriptRoot\..\Esf.sln"
	$deploymentOutput = "$PSScriptRoot\DeploymentOutput"
	EnsureDeploymentOutputExists $deploymentOutput
	
	Write-Progress -Activity "Prerequisites" -Status "Started"
	TestPrerequisites $deploymentOutput
	Write-Progress -Activity "Prerequisites" -Status "Finished"
	RestoreNugetPackages $esfSolution *>&1 | Out-File $deploymentOutput\EsfNugetPackagesRestore.txt
	$esfDeploymentSolution = Resolve-Path "$PSScriptRoot\..\Esf.Deployment.sln"
	RestoreNugetPackages $esfDeploymentSolution *>&1 | Out-File $deploymentOutput\EsfDeploymentNugetPackagesRestore.txt
	Write-Progress -Activity "Esf MS build" -Status "Started"
	InvokeMsBuildOnSolution $esfSolution $deploymentOutput *>&1 | Out-File $deploymentOutput\Esf.MsBuild.txt
	Write-Progress -Activity "Esf MS build" -Status "Finished"
	$esfDataAccessDeploymentTests = Resolve-Path "$PSScriptRoot\..\Esf.DataAccess.DeploymentTests\Esf.DataAccess.DeploymentTests.csproj"
	Write-Progress -Activity "esfDataAccessDeploymentTests MS build" -Status "Started"
	InvokeMsBuildOnProject $esfDataAccessDeploymentTests $deploymentOutput *>&1 | Out-File $deploymentOutput\Esf.DataAccess.DeploymentTests.MsBuild.txt
	Write-Progress -Activity "$esfDataAccessDeploymentTests MS build" -Status "Finished"
	Import-Module $PSScriptRoot\Esf.Website.GulpBuild.psm1
	Write-Progress -Activity "Esf.Website Gulp Build" -Status "Started"
	EsfWebsiteGulpBuild *>&1 | Out-File $PSScriptRoot\DeploymentOutput\Esf.Website.GulpBuild.txt
	Write-Progress -Activity "Esf.Website Gulp Build" -Status "Finished"
	Import-Module $PSScriptRoot\..\Esf.DataAccess.Deployment\DeployDb.psm1
	Write-Progress -Activity "Deploy DB" -Status "Started"
	& DeployDb *>&1 |  Out-File $PSScriptRoot\DeploymentOutput\DeployDB.output.txt
	($deployDbTestsResult = RunEsfNUnitDeploymentTests $deploymentOutput) *>&1 |  Out-File $PSScriptRoot\DeploymentOutput\DeployDB.tests.txt
	ReportTestsResult "deploy DB tests" $deployDbTestsResult.FailedTestsCount
	Write-Progress -Activity "Deploy DB" -Status "Finished"
	Import-Module $PSScriptRoot\DeployToIss.psm1
	Write-Progress -Activity "Deploy Website and web api" -Status "Started"
	DeployWebsiteAndWebApi *>&1 | Out-File $PSScriptRoot\DeploymentOutput\DeployWebsiteAndWebApi.txt
	Write-Progress -Activity "Deploy Website and web api" -Status "Finished"
	($deployWebsiteAndWebApiTestsResult = RunDeployWebsiteAndWebApiTests) *>&1 | Out-File $PSScriptRoot\DeploymentOutput\DeployWebsiteAndWebApi.tests.txt
	ReportTestsResult "website and web api tests" $deployWebsiteAndWebApiTestsResult.FailedTestsCount
	
	Import-Module $PSScriptRoot\DeployToIss.psm1
	Write-Progress -Activity "Deploy Website and web api" -Status "Started"
	DeployWebsiteAndWebApi *>&1 | Out-File $PSScriptRoot\DeploymentOutput\DeployWebsiteAndWebApi.txt
	Write-Progress -Activity "Deploy Website and web api" -Status "Finished"
	
	Write-Output "Deployment finished. To check if it is successful go to:"
	Write-Output $deploymentOutput
	
	If ($deployWebsiteAndWebApiTestsResult.FailedTestsCount -eq 0) { 
		OpenWebsite 
	}
}

function ReportTestsResult($message, $testsFailedCount) {
	if ($testsFailedCount -eq 0) {
		Write-Host -ForegroundColor Green "All $message succeeded"
	}
	if ($testsFailedCount -gt 0) {
		Write-Host -ForegroundColor Red "$message failed"
	}
}

function OpenWebsite() {
	$port = $((Get-Content "$PSScriptRoot\esfWebsite.config.json") -join "`n" | ConvertFrom-Json).Port
	start "http://localhost:$port"
}

function TestPrerequisites($deploymentOutput) {
	Import-Module $PSScriptRoot\PesterSuite.psm1
	$preqequisitesTestsResult = (RunPesterSuite $PSScriptRoot\Prerequisites.tests.ps1) *>&1 |  Out-File $deploymentOutput\DeployDB.tests.txt
	ReportTestsResult "environment prerequisites tests" $preqequisitesTestsResult.FailedTestsCount
}

Clear-Host
DeployEsf
Pause<commit_msg>#18 fixed the deployment output file name for prerequisites tests<commit_after>function RestoreNugetPackages($solutionPath) {
	$packagesDirectory = Resolve-Path "$PSScriptRoot\..\packages"
	$nugetPath = "$packagesDirectory\NuGet.CommandLine.3.4.3\tools\NuGet.exe"
	
	& $nugetPath restore -PackagesDirectory $packagesDirectory $solutionPath
}

function EnsureDeploymentOutputExists($deploymentOutput) {
	if (-Not (Test-Path $deploymentOutput)) {
		New-Item -ItemType Directory $deploymentOutput
	}
}

function DeployEsf() {
	Write-Host -ForegroundColor Cyan "Deployment process of ES Fiddle"
	Import-Module $PSScriptRoot\MSBuild.psm1
	$esfSolution = Resolve-Path "$PSScriptRoot\..\Esf.sln"
	$deploymentOutput = "$PSScriptRoot\DeploymentOutput"
	EnsureDeploymentOutputExists $deploymentOutput
	
	Write-Progress -Activity "Prerequisites" -Status "Started"
	TestPrerequisites $deploymentOutput
	Write-Progress -Activity "Prerequisites" -Status "Finished"
	RestoreNugetPackages $esfSolution *>&1 | Out-File $deploymentOutput\EsfNugetPackagesRestore.txt
	$esfDeploymentSolution = Resolve-Path "$PSScriptRoot\..\Esf.Deployment.sln"
	RestoreNugetPackages $esfDeploymentSolution *>&1 | Out-File $deploymentOutput\EsfDeploymentNugetPackagesRestore.txt
	Write-Progress -Activity "Esf MS build" -Status "Started"
	InvokeMsBuildOnSolution $esfSolution $deploymentOutput *>&1 | Out-File $deploymentOutput\Esf.MsBuild.txt
	Write-Progress -Activity "Esf MS build" -Status "Finished"
	$esfDataAccessDeploymentTests = Resolve-Path "$PSScriptRoot\..\Esf.DataAccess.DeploymentTests\Esf.DataAccess.DeploymentTests.csproj"
	Write-Progress -Activity "esfDataAccessDeploymentTests MS build" -Status "Started"
	InvokeMsBuildOnProject $esfDataAccessDeploymentTests $deploymentOutput *>&1 | Out-File $deploymentOutput\Esf.DataAccess.DeploymentTests.MsBuild.txt
	Write-Progress -Activity "$esfDataAccessDeploymentTests MS build" -Status "Finished"
	Import-Module $PSScriptRoot\Esf.Website.GulpBuild.psm1
	Write-Progress -Activity "Esf.Website Gulp Build" -Status "Started"
	EsfWebsiteGulpBuild *>&1 | Out-File $PSScriptRoot\DeploymentOutput\Esf.Website.GulpBuild.txt
	Write-Progress -Activity "Esf.Website Gulp Build" -Status "Finished"
	Import-Module $PSScriptRoot\..\Esf.DataAccess.Deployment\DeployDb.psm1
	Write-Progress -Activity "Deploy DB" -Status "Started"
	& DeployDb *>&1 |  Out-File $PSScriptRoot\DeploymentOutput\DeployDB.output.txt
	($deployDbTestsResult = RunEsfNUnitDeploymentTests $deploymentOutput) *>&1 |  Out-File $PSScriptRoot\DeploymentOutput\DeployDB.tests.txt
	ReportTestsResult "deploy DB tests" $deployDbTestsResult.FailedTestsCount
	Write-Progress -Activity "Deploy DB" -Status "Finished"
	Import-Module $PSScriptRoot\DeployToIss.psm1
	Write-Progress -Activity "Deploy Website and web api" -Status "Started"
	DeployWebsiteAndWebApi *>&1 | Out-File $PSScriptRoot\DeploymentOutput\DeployWebsiteAndWebApi.txt
	Write-Progress -Activity "Deploy Website and web api" -Status "Finished"
	($deployWebsiteAndWebApiTestsResult = RunDeployWebsiteAndWebApiTests) *>&1 | Out-File $PSScriptRoot\DeploymentOutput\DeployWebsiteAndWebApi.tests.txt
	ReportTestsResult "website and web api tests" $deployWebsiteAndWebApiTestsResult.FailedTestsCount
	
	Import-Module $PSScriptRoot\DeployToIss.psm1
	Write-Progress -Activity "Deploy Website and web api" -Status "Started"
	DeployWebsiteAndWebApi *>&1 | Out-File $PSScriptRoot\DeploymentOutput\DeployWebsiteAndWebApi.txt
	Write-Progress -Activity "Deploy Website and web api" -Status "Finished"
	
	Write-Output "Deployment finished. To check if it is successful go to:"
	Write-Output $deploymentOutput
	
	If ($deployWebsiteAndWebApiTestsResult.FailedTestsCount -eq 0) { 
		OpenWebsite 
	}
}

function ReportTestsResult($message, $testsFailedCount) {
	if ($testsFailedCount -eq 0) {
		Write-Host -ForegroundColor Green "All $message succeeded"
	}
	if ($testsFailedCount -gt 0) {
		Write-Host -ForegroundColor Red "$message failed"
	}
}

function OpenWebsite() {
	$port = $((Get-Content "$PSScriptRoot\esfWebsite.config.json") -join "`n" | ConvertFrom-Json).Port
	start "http://localhost:$port"
}

function TestPrerequisites($deploymentOutput) {
	Import-Module $PSScriptRoot\PesterSuite.psm1
	$preqequisitesTestsResult = (RunPesterSuite $PSScriptRoot\Prerequisites.tests.ps1) *>&1 |  Out-File $deploymentOutput\prerequisites.tests.txt	
	ReportTestsResult "environment prerequisites tests" $preqequisitesTestsResult.FailedTestsCount
}

Clear-Host
DeployEsf
Pause
{'fraction_non_alphanumeric': 0.10379263913824058, 'fraction_numerical': 0.005610412926391382, 'mean_word_length': 6.2997542997543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '5428116', 'n_tokens_mistral': 3011, 'n_tokens_neox': 2818, 'n_words': 580}