<commit_before>#r "System.Web.Extensions.dll"

/////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////

var Target = Argument("target", "Default");
var Configuration = Argument("configuration", "Release");

// VERSION INFORMATION
var BuildNumber = EnvironmentVariable("BUILD_NUMBER");
var Version = System.IO.File.ReadAllText("../VERSION");
var VersionSuffix = "";

// VARIOUS DIRECTORIES
var BinariesDirectory = "./build/bin/" + Configuration;
var OutputDirectory   = "./build/out/" + Configuration;

// GIT SPECIFIC VARIABLES
var GitHubToken      = EnvironmentVariable("GITHUB_TOKEN");
var GitBranch        = EnvironmentVariable("BUILD_VCS_BRANCH");
var GitCommitish     = EnvironmentVariable("BUILD_VCS_NUMBER");
var GitHubRepository = "hadouken/hadouken";

// CHOCOLATEY
var ChocolateyApiKey = EnvironmentVariable("CHOCOLATEY_API_KEY");

public string RunCommand(string executable, string args)
{
    IEnumerable<string> output;

    var exitCode = StartProcess(executable,
        new ProcessSettings
        {
            Arguments = args,
            RedirectStandardOutput = true
        },
        out output);

    if (exitCode == 0)
    {
        return output.First();
    }

    return string.Empty;
}

public string ToJson(object obj)
{
    return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(obj);
}

public T FromJson<T>(string json)
{
    return new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<T>(json);
}

Task("Clean")
    .Does(() =>
    {
        CleanDirectories(new[]
        {
            BinariesDirectory,
            BinariesDirectory + "/js/rpc",
            OutputDirectory,
            "./build/" + Configuration,
            "./build/wixobj"
        });
    });

Task("Prepare-Version-Suffix")
    .WithCriteria(() => GitBranch != "master")
    .Does(() =>
    {
        if(string.IsNullOrEmpty(GitBranch))
        {
            GitBranch = RunCommand("git", "rev-parse --abbrev-ref HEAD");        
        }

        if (GitBranch == "master") return;

        if (!string.IsNullOrEmpty(BuildNumber))
        {
            VersionSuffix = "-build" + BuildNumber;
        }
        else
        {
            VersionSuffix = "-local";
        }
    });

Task("Get-Git-Revision")
    .WithCriteria(() => string.IsNullOrEmpty(GitCommitish))
    .OnError(exception => { GitCommitish = "<norev>"; })
    .Does(() =>
    {
        GitCommitish = RunCommand("git", "log -1 --format=%H") ?? "<norev>";
    });

Task("Restore-NuGet-Packages")
    .Does(() =>
    {
        NuGetInstallFromConfig("./packages.config",
            new NuGetInstallSettings
            {
                ExcludeVersion = true,
                OutputDirectory = "./libs"
            });
    });

Task("Generate-CMake-Project")
    .Does(() =>
    {
        CreateDirectory("build");
        var cmakeExitCode = StartProcess("cmake",
            new ProcessSettings
            {
                Arguments = "../../ -G \"Visual Studio 12\" -T \"v120\"",
                WorkingDirectory = "./build"
            });

        if(cmakeExitCode != 0)
        {
            throw new CakeException("CMake failed to execute.");
        }
    });

Task("Compile")
    .IsDependentOn("Restore-NuGet-Packages")
    .IsDependentOn("Generate-CMake-Project")
    .IsDependentOn("Get-Git-Revision")
    .Does(() =>
    {
        MSBuild("./build/hadouken.sln", s =>
        {
            s.Configuration = Configuration;
        });
    });

Task("Output")
    .IsDependentOn("Compile")
    .Does(() =>
    {
        // Copy Boost and libtorrent binaries.
        var libtorrentBinaries = string.Format("libs/hadouken.libtorrent/win32/bin/" + Configuration + "/*.dll");
        CopyFiles(GetFiles(libtorrentBinaries), BinariesDirectory);

        // Copy OpenSSL binaries.
        var opensslBinaries = string.Format("libs/hadouken.openssl/win32/bin/" + Configuration + "/*.dll");
        CopyFiles(GetFiles(opensslBinaries), BinariesDirectory);

        // Copy Poco binaries.
        var pocoSuffix = (Configuration == "Release" ? string.Empty : "d");
        var pocoTemplate = "libs/hadouken.poco/win32/bin/Poco{0}{1}.dll";
        var pocoBinaries = new[]
        {
            string.Format(pocoTemplate, "Crypto", pocoSuffix),
            string.Format(pocoTemplate, "Foundation", pocoSuffix),
            string.Format(pocoTemplate, "JSON", pocoSuffix),
            string.Format(pocoTemplate, "Net", pocoSuffix),
            string.Format(pocoTemplate, "NetSSL", pocoSuffix),
            string.Format(pocoTemplate, "Util", pocoSuffix),
            string.Format(pocoTemplate, "XML", pocoSuffix)
        };

        CopyFiles(
            pocoBinaries,
            BinariesDirectory
        );

        // Copy JS files
        CopyFiles(GetFiles("../js/*.js"), BinariesDirectory + "/js");
        CopyFiles(GetFiles("../js/rpc/*.js"), BinariesDirectory + "/js/rpc");

        // Copy relevant dist files
        var distFiles = new []
        {
            "../dist/cacert.pem",
            "../dist/win32/hadoukend.json.template"
        };

        CopyFiles(distFiles, BinariesDirectory);
    });

Task("Create-Zip-Package")
    .IsDependentOn("Output")
    .Does(() =>
    {
        IEnumerable<FilePath> files = GetFiles(BinariesDirectory + "/*.dll");
        files = files.Union(GetFiles(BinariesDirectory + "/*.exe"));
        files = files.Union(GetFiles(BinariesDirectory + "/*.template"));

        Zip(BinariesDirectory,
            OutputDirectory + "/hadouken-" + Version + VersionSuffix + ".zip",
            files);
    });

Task("Create-Pdb-Package")
    .IsDependentOn("Output")
    .Does(() =>
    {
        var pdbFiles = GetFiles(BinariesDirectory + "/*.pdb");

        Zip(BinariesDirectory,
            OutputDirectory + "/hadouken-" + Version + VersionSuffix + ".symbols.zip",
            pdbFiles);
    });
<commit_msg>Zip package now includes JS files.<commit_after>#r "System.Web.Extensions.dll"

/////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////

var Target        = Argument("target", "Default");
var Configuration = Argument("configuration", "Release");

// VERSION INFORMATION
var BuildNumber   = EnvironmentVariable("BUILD_NUMBER");
var Version       = System.IO.File.ReadAllText("../VERSION");
var VersionSuffix = "";

// VARIOUS DIRECTORIES
var BinariesDirectory = "./build/bin/" + Configuration;
var OutputDirectory   = "./build/out/" + Configuration;

// GIT SPECIFIC VARIABLES
var GitHubToken      = EnvironmentVariable("GITHUB_TOKEN");
var GitBranch        = EnvironmentVariable("BUILD_VCS_BRANCH");
var GitCommitish     = EnvironmentVariable("BUILD_VCS_NUMBER");
var GitHubRepository = "hadouken/hadouken";

// CHOCOLATEY
var ChocolateyApiKey = EnvironmentVariable("CHOCOLATEY_API_KEY");

public string RunCommand(string executable, string args)
{
    IEnumerable<string> output;

    var exitCode = StartProcess(executable,
        new ProcessSettings
        {
            Arguments = args,
            RedirectStandardOutput = true
        },
        out output);

    if (exitCode == 0)
    {
        return output.First();
    }

    return string.Empty;
}

public string ToJson(object obj)
{
    return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(obj);
}

public T FromJson<T>(string json)
{
    return new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<T>(json);
}

Task("Clean")
    .Does(() =>
    {
        CleanDirectories(new[]
        {
            BinariesDirectory,
            BinariesDirectory + "/js/rpc",
            OutputDirectory,
            "./build/" + Configuration,
            "./build/wixobj"
        });
    });

Task("Prepare-Version-Suffix")
    .WithCriteria(() => GitBranch != "master")
    .Does(() =>
    {
        if(string.IsNullOrEmpty(GitBranch))
        {
            GitBranch = RunCommand("git", "rev-parse --abbrev-ref HEAD");        
        }

        if (GitBranch == "master") return;

        if (!string.IsNullOrEmpty(BuildNumber))
        {
            VersionSuffix = "-build" + BuildNumber;
        }
        else
        {
            VersionSuffix = "-local";
        }
    });

Task("Get-Git-Revision")
    .WithCriteria(() => string.IsNullOrEmpty(GitCommitish))
    .OnError(exception => { GitCommitish = "<norev>"; })
    .Does(() =>
    {
        GitCommitish = RunCommand("git", "log -1 --format=%H") ?? "<norev>";
    });

Task("Restore-NuGet-Packages")
    .Does(() =>
    {
        NuGetInstallFromConfig("./packages.config",
            new NuGetInstallSettings
            {
                ExcludeVersion = true,
                OutputDirectory = "./libs"
            });
    });

Task("Generate-CMake-Project")
    .Does(() =>
    {
        CreateDirectory("build");
        var cmakeExitCode = StartProcess("cmake",
            new ProcessSettings
            {
                Arguments = "../../ -G \"Visual Studio 12\" -T \"v120\"",
                WorkingDirectory = "./build"
            });

        if(cmakeExitCode != 0)
        {
            throw new CakeException("CMake failed to execute.");
        }
    });

Task("Compile")
    .IsDependentOn("Restore-NuGet-Packages")
    .IsDependentOn("Generate-CMake-Project")
    .IsDependentOn("Get-Git-Revision")
    .Does(() =>
    {
        MSBuild("./build/hadouken.sln", s =>
        {
            s.Configuration = Configuration;
        });
    });

Task("Output")
    .IsDependentOn("Compile")
    .Does(() =>
    {
        // Copy Boost and libtorrent binaries.
        var libtorrentBinaries = string.Format("libs/hadouken.libtorrent/win32/bin/" + Configuration + "/*.dll");
        CopyFiles(GetFiles(libtorrentBinaries), BinariesDirectory);

        // Copy OpenSSL binaries.
        var opensslBinaries = string.Format("libs/hadouken.openssl/win32/bin/" + Configuration + "/*.dll");
        CopyFiles(GetFiles(opensslBinaries), BinariesDirectory);

        // Copy Poco binaries.
        var pocoSuffix = (Configuration == "Release" ? string.Empty : "d");
        var pocoTemplate = "libs/hadouken.poco/win32/bin/Poco{0}{1}.dll";
        var pocoBinaries = new[]
        {
            string.Format(pocoTemplate, "Crypto", pocoSuffix),
            string.Format(pocoTemplate, "Foundation", pocoSuffix),
            string.Format(pocoTemplate, "JSON", pocoSuffix),
            string.Format(pocoTemplate, "Net", pocoSuffix),
            string.Format(pocoTemplate, "NetSSL", pocoSuffix),
            string.Format(pocoTemplate, "Util", pocoSuffix),
            string.Format(pocoTemplate, "XML", pocoSuffix)
        };

        CopyFiles(
            pocoBinaries,
            BinariesDirectory
        );

        // Copy JS files
        CopyFiles(GetFiles("../js/*.js"),     BinariesDirectory + "/js");
        CopyFiles(GetFiles("../js/rpc/*.js"), BinariesDirectory + "/js/rpc");

        // Copy relevant dist files
        var distFiles = new []
        {
            "../dist/cacert.pem",
            "../dist/win32/hadoukend.json.template"
        };

        CopyFiles(distFiles, BinariesDirectory);
    });

Task("Create-Zip-Package")
    .IsDependentOn("Output")
    .Does(() =>
    {
        IEnumerable<FilePath> files = GetFiles(BinariesDirectory + "/*.dll");
        files = files.Union(GetFiles(BinariesDirectory + "/*.exe"));
        files = files.Union(GetFiles(BinariesDirectory + "/*.template"));
        files = files.Union(GetFiles(BinariesDirectory + "/js/*.js"));
        files = files.Union(GetFiles(BinariesDirectory + "/js/rpc/*.js"));

        Zip(BinariesDirectory,
            OutputDirectory + "/hadouken-" + Version + VersionSuffix + ".zip",
            files);
    });

Task("Create-Pdb-Package")
    .IsDependentOn("Output")
    .Does(() =>
    {
        var pdbFiles = GetFiles(BinariesDirectory + "/*.pdb");

        Zip(BinariesDirectory,
            OutputDirectory + "/hadouken-" + Version + VersionSuffix + ".symbols.zip",
            pdbFiles);
    });

{'fraction_non_alphanumeric': 0.16663924987662446, 'fraction_numerical': 0.0029610133245599607, 'mean_word_length': 2.0994137139943922, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 41, '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': '7083281', 'n_tokens_mistral': 3539, 'n_tokens_neox': 3427, 'n_words': 605}