<commit_before>properties {
  $baseDir = Resolve-Path .
  $configuration = "debug"
  $xUnit = Resolve-Path .\3rdParty\XUnit\xunit.console.clr4.exe
  $filesDir = "$baseDir\_build"
  $nugetDir = "$baseDir\_nuget"
  $packageDir = "$baseDir\_package"
  $mainVersion = "2.0.1"
  $version = $mainVersion  + "." + (hg log --limit 9999999 --template '{rev}:{node}\n' | measure-object).Count 
  # Import environment variables for Visual Studio
  if (test-path ("vsvars2010.ps1")) { 
    . vsvars2010.ps1 
    }
  
}

# Aliases
task Default -depends Run-Build
task Package -depends Clean-Solution,Clean-PackageFiles, Update-AssemblyInfoFiles, Build-Solution, Package-Files, Package-NuGet
task Build -depends Run-Build
task Clean -depends Clean-Solution

# Build Tasks
task Run-Build -depends  Clean-Solution, Build-Solution, Run-UnitTests, Run-IntegrationTests

task Update-AssemblyInfoFiles {
	$commit = hg log --template '{rev}:{node}\n' -l 1
	Update-AssemblyInfoFiles $version $commit
}

task Run-Chutzpah -depends  Build-Solution {
  exec { & .\ConsoleRunner\bin\$configuration\chutzpah.console.exe ConsoleRunner\JS\test.html /file ConsoleRunner\JS\tests.js}
}

task Clean-PackageFiles {
    clean $nugetDir
    clean $filesDir
    clean $packageDir
}

task Clean-Solution {
    exec { msbuild Chutzpah.VS2010.sln /t:Clean /v:quiet }
    exec { msbuild Chutzpah.VS2012.sln /t:Clean /v:quiet }
}

task Build-Solution {
    exec { msbuild Chutzpah.VS2010.sln /maxcpucount /t:Build /v:Minimal /p:Configuration=$configuration }
    exec { msbuild Chutzpah.VS2012.sln /maxcpucount /t:Build /v:Minimal /p:Configuration=$configuration }
}

task Run-PerfTester {
    $result = & "PerfTester\bin\$configuration\chutzpah.perftester.exe"
    Write-Output $result
    $result | Out-File "perf_results.txt" -Encoding ASCII
}

task Run-UnitTests {
    exec { & $xUnit "Facts\bin\$configuration\Facts.Chutzpah.dll" }
}

task Run-IntegrationTests {
    exec { & $xUnit "Facts.Integration\bin\$configuration\Facts.Integration.Chutzpah.dll" }
}

task Run-Phantom {
  $type = $arg1;
  $mode = $arg2;
  if(-not $type){
    $type = "qunit";
  }
  $phantom = "3rdParty\Phantom\phantomjs.exe";
  
  $testFilePath = Resolve-Path "Facts.Integration/JS/Test/basic-$($type).html";
  $testFilePath = $testFilePath.Path.Replace("\","/");
  
  exec {  & $phantom "Chutzpah\JSRunners\$($type)Runner.js" "file:///$testFilePath" $mode }
}

task Package-Files -depends Clean-PackageFiles {
    
    create $filesDir, $packageDir
    copy-item "$baseDir\License.txt" -destination $filesDir
    roboexec {robocopy "$baseDir\ConsoleRunner\bin\$configuration\" $filesDir /S /xd JS /xf *.xml}
    
    cd $filesDir
    exec { &"$baseDir\3rdParty\Zip\zip.exe" -r -9 "$packageDir\Chutzpah.$mainVersion.zip" *.* }
    cd $baseDir
    
    # Copy over Vsix Files
    copy-item "$baseDir\VisualStudio\bin\$configuration\chutzpah.visualstudio.vsix" -destination $packageDir
    copy-item "$baseDir\VS2012\bin\$configuration\Chutzpah.VS2012.vsix" -destination $packageDir
}

task Package-NuGet -depends Clean-PackageFiles {
    $nugetTools = "$nugetDir\tools"
    $nuspec = "$baseDir\Chutzpah.nuspec"
    
    create $nugetDir, $nugetTools, $packageDir
    
    copy-item "$baseDir\License.txt", $nuspec -destination $nugetDir
    roboexec {robocopy "$baseDir\ConsoleRunner\bin\$configuration\" $nugetTools /S /xd JS /xf *.xml}
    $v = new-object -TypeName System.Version -ArgumentList $version
    regex-replace "$nugetDir\Chutzpah.nuspec" '(?m)@Version@' $v.ToString(3)
    exec { .\Tools\nuget.exe pack "$nugetDir\Chutzpah.nuspec" -o $packageDir }
}

task Push-Nuget {
  $v = new-object -TypeName System.Version -ArgumentList $version
	exec { .\Tools\nuget.exe push $packageDir\Chutzpah.$($v.ToString(3)).nupkg }
}


# Help 
task ? -Description "Help information" {
	Write-Documentation
}

function create([string[]]$paths) {
  foreach ($path in $paths) {<commit_msg>add supprot for environment build number<commit_after>properties {
  $baseDir = Resolve-Path .
  $configuration = "debug"
  $xUnit = Resolve-Path .\3rdParty\XUnit\xunit.console.clr4.exe
  $filesDir = "$baseDir\_build"
  $nugetDir = "$baseDir\_nuget"
  $packageDir = "$baseDir\_package"
  $mainVersion = "2.0.1"
  $buildNumber = if ($env:build_number -ne $NULL) { $env:build_number } else { '0' }
  # Import environment variables for Visual Studio
  if (test-path ("vsvars2010.ps1")) { 
    . ./vsvars2010.ps1 
    }
}

# Aliases
task Default -depends Run-Build
task Package -depends Clean-Solution,Clean-PackageFiles, Set-Version, Update-AssemblyInfoFiles, Build-Solution, Package-Files, Package-NuGet
task Build -depends Run-Build
task Clean -depends Clean-Solution

# Build Tasks
task Run-Build -depends  Clean-Solution, Build-Solution, Run-UnitTests, Run-IntegrationTests

task Set-Version {
  if($buildNumber -gt 0){
    $last = $buildNumber
  }
  else{
    $last = (hg log --limit 9999999 --template '{rev}:{node}\n' | measure-object).Count 
  }
  
  $global:version = $mainVersion  + "." + $last
}

task Update-AssemblyInfoFiles {
	$commit = hg log --template '{rev}:{node}\n' -l 1
	Update-AssemblyInfoFiles $global:version $commit
}

task Run-Chutzpah -depends  Build-Solution {
  exec { & .\ConsoleRunner\bin\$configuration\chutzpah.console.exe ConsoleRunner\JS\test.html /file ConsoleRunner\JS\tests.js}
}

task Clean-PackageFiles {
    clean $nugetDir
    clean $filesDir
    clean $packageDir
}

task Clean-Solution {
    exec { msbuild Chutzpah.VS2010.sln /t:Clean /v:quiet }
    exec { msbuild Chutzpah.VS2012.sln /t:Clean /v:quiet }
}

task Build-Solution {
    exec { msbuild Chutzpah.VS2010.sln /maxcpucount /t:Build /v:Minimal /p:Configuration=$configuration }
    exec { msbuild Chutzpah.VS2012.sln /maxcpucount /t:Build /v:Minimal /p:Configuration=$configuration }
}

task Run-PerfTester {
    $result = & "PerfTester\bin\$configuration\chutzpah.perftester.exe"
    Write-Output $result
    $result | Out-File "perf_results.txt" -Encoding ASCII
}

task Run-UnitTests {
    exec { & $xUnit "Facts\bin\$configuration\Facts.Chutzpah.dll" }
}

task Run-IntegrationTests {
    exec { & $xUnit "Facts.Integration\bin\$configuration\Facts.Integration.Chutzpah.dll" }
}

task Run-Phantom {
  $type = $arg1;
  $mode = $arg2;
  if(-not $type){
    $type = "qunit";
  }
  $phantom = "3rdParty\Phantom\phantomjs.exe";
  
  $testFilePath = Resolve-Path "Facts.Integration/JS/Test/basic-$($type).html";
  $testFilePath = $testFilePath.Path.Replace("\","/");
  
  exec {  & $phantom "Chutzpah\JSRunners\$($type)Runner.js" "file:///$testFilePath" $mode }
}

task Package-Files -depends Clean-PackageFiles {
    
    create $filesDir, $packageDir
    copy-item "$baseDir\License.txt" -destination $filesDir
    roboexec {robocopy "$baseDir\ConsoleRunner\bin\$configuration\" $filesDir /S /xd JS /xf *.xml}
    
    cd $filesDir
    exec { &"$baseDir\3rdParty\Zip\zip.exe" -r -9 "$packageDir\Chutzpah.$mainVersion.zip" *.* }
    cd $baseDir
    
    # Copy over Vsix Files
    copy-item "$baseDir\VisualStudio\bin\$configuration\chutzpah.visualstudio.vsix" -destination $packageDir
    copy-item "$baseDir\VS2012\bin\$configuration\Chutzpah.VS2012.vsix" -destination $packageDir
}

task Package-NuGet -depends Clean-PackageFiles {
    $nugetTools = "$nugetDir\tools"
    $nuspec = "$baseDir\Chutzpah.nuspec"
    
    create $nugetDir, $nugetTools, $packageDir
    
    copy-item "$baseDir\License.txt", $nuspec -destination $nugetDir
    roboexec {robocopy "$baseDir\ConsoleRunner\bin\$configuration\" $nugetTools /S /xd JS /xf *.xml}
    $v = new-object -TypeName System.Version -ArgumentList $global:version
    regex-replace "$nugetDir\Chutzpah.nuspec" '(?m)@Version@' $v.ToString(3)
    exec { .\Tools\nuget.exe pack "$nugetDir\Chutzpah.nuspec" -o $packageDir }
}

task Push-Nuget -depends Set-Version {
  $v = new-object -TypeName System.Version -ArgumentList $global:version
	exec { .\Tools\nuget.exe push $packageDir\Chutzpah.$($v.ToString(3)).nupkg }
}


# Help 
task ? -Description "Help information" {
	Write-Documentation
}

function create([string[]]$paths) {
  foreach ($path in $paths) {
{'fraction_non_alphanumeric': 0.1441940647703485, 'fraction_numerical': 0.013545129910109593, 'mean_word_length': 3.741389375364857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 2, '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': '1814055', 'n_tokens_mistral': 3043, 'n_tokens_neox': 2857, 'n_words': 570}