<commit_before>// Copyright (c) 2012 Titanium I.T. LLC. All rights reserved. See LICENSE.txt for details.
/*global desc, task, file, jake, rule, fail, complete, directory*/

(function() {
	"use strict";

	var startTime = Date.now();

	// We've put most of our require statements in functions (or tasks) so we don't have the overhead of
	// loading modules we don't need. At the time this refactoring was done, module loading took about half a
	// second, which was 10% of our desired maximum of five seconds for a quick build.
	// The require statements here are just the ones that are used to set up the tasks.
	var paths = require("./build/config/paths.js");

	var strict = !process.env.loose;
	if (strict) console.log("For more forgiving test settings, use 'loose=true'");

	//*** DIRECTORIES

	directory(paths.tempTestfileDir);
	directory(paths.buildDir);
	directory(paths.buildClientDir);
	directory(paths.incrementalDir);


	//*** GENERAL

	jake.addListener('complete', function () {
		var elapsedSeconds = (Date.now() - startTime) / 1000;
		console.log("\n\nBUILD OK (" + elapsedSeconds.toFixed(2) + "s)");
	});

	desc("Delete all generated files");
	task("clean", [], function() {
		jake.rmRf(paths.generatedDir);
	});

	desc("Lint and test everything");
	task("default", [ "clean", "quick", "smoketest" ]);

	desc("Incrementally lint and test fast targets");
	task("quick", [ "nodeVersion", "lint", "testServer", "testClient" ]);

	desc("Start Karma server for testing");
	task("karma", function() {
		karmaRunner().serve(paths.karmaConfig, complete, fail);
	}, {async: true});

	desc("Start localhost server for manual testing");
	task("run", [ "build" ], function() {
		var runServer = require("./src/_run_server.js");

		console.log("Running server. Press Ctrl-C to stop.");
		runServer.runInteractively();
		// We never call complete() because we want the task to hang until the user presses 'Ctrl-C'.
	}, {async: true});


	//*** LINT

	desc("Lint everything");
	task("lint", [ "lintLog", "incrementalLint" ], function() {
		console.log();
	});

	task("lintLog", function() { process.stdout.write("Linting JavaScript: "); });

	task("incrementalLint", paths.lintDirectories());
	task("incrementalLint", paths.lintOutput());
	createDirectoryDependencies(paths.lintDirectories());

	rule(".lint", determineLintDependency, function() {
		var lint = require("./build/util/lint_runner.js");
		var lintConfig = require("./build/config/jshint.conf.js");

		var passed = lint.validateFile(this.source, lintConfig.options, lintConfig.globals);
		if (passed) fs().writeFileSync(this.name, "lint ok");
		else fail("Lint failed");
	});


	//*** TEST

	desc("Test server code");
	incrementalTask("testServer", paths.serverTestTarget, [ paths.tempTestfileDir ], paths.serverFiles(),
		function(complete, fail) {
		console.log("Testing server code: ");
		mochaRunner().runTests({
			files: paths.serverTestFiles(),
			options: mochaConfig()
		}, complete, fail);
	});


	desc("Test client code");
	incrementalTask("testClient", paths.clientTestTarget, [], paths.clientFiles(), function(complete, fail) {
		console.log("Testing browser code: ");
		karmaRunner().runTests({
			configFile: paths.karmaConfig,
			browsers: require("./build/config/tested_browsers.js"),
			strict: strict
		}, complete, fail);
	});

	desc("End-to-end smoke tests");
	task("smoketest", [ "build" ], function() {
		console.log("Smoke testing app: ");
		mochaRunner().runTests({
			files: paths.smokeTestFiles(),
			options: mochaConfig()
		}, complete, fail);
	}, { async: true });


	//*** BUILD

	desc("Bundle and build code");
	task("build", [ "cacheBust" ]);

	task("cacheBust", [ "collateClientFiles", "bundleClientJs" ], function() {
		console.log("Cache-busting CSS and JavaScript: .");

		var hashCatRunner = require("./build/util/hashcat_runner.js");
		hashCatRunner.go({
			indexFile: paths.buildClientIndexHtml
		}, removeHashCatIntermediateFiles, fail);


		function removeHashCatIntermediateFiles() {
			shell().rm(paths.buildIntermediateFilesToErase);
			complete();
		}

	}, { async: true });

	task("collateClientFiles", [ paths.buildClientDir ], function() {
		console.log("Collating client files: .");

		shell().rm("-rf", paths.buildClientDir + "/*");
		shell().cp(
			"-R",
			"src/client/*.html", "src/client/*.css", "src/client/images", "src/client/vendor", "src/shared/vendor",
			paths.buildClientDir
		);
	});

	task("bundleClientJs", [ paths.buildClientDir ], function() {
		process.stdout.write("Bundling client files with Browserify: ");

		var browserifyRunner = require("./build/util/browserify_runner.js");
		browserifyRunner.bundle({
			requires: [
				{ path: "./src/client/client.js", expose: "./client.js" },
				{ path: "./src/client/html_element.js", expose: "./html_element.js" }
			],
			outfile: paths.buildClientDir + "/bundle.js",
			options: { debug: true }
		}, complete, fail);
	}, {async: true});


	//*** CHECK VERSIONS

	task("nodeVersion", [], function() {
		console.log("Checking Node.js version: .");
		var version = require("./build/util/version_checker.js");

		version.check({
			name: "Node",
			expected: require("./package.json").engines.node,
			actual: process.version,
			strict: strict
		}, complete, fail);
	});


	//*** DEPLOY

	desc("Deploy to Heroku");
	task("deploy", function() {
		console.log("To deploy to production:");
		console.log("1. Make sure `git status` is clean");
		console.log("2. Deploy HEAD to staging server: `git push staging master`");
		console.log("3. Verify by visiting http://www-staging.herokuapp.com");
		console.log("4. Integrate");
		console.log("5. Deploy integrated code to staging: `git push staging integration:master`");
		console.log("6. Deploy integrated to production: `git push heroku integration:master`");
	});


	//*** INTEGRATE

	desc("Integration checklist");<commit_msg>Fixed deploy instructions with 'generated/build/client' info<commit_after>// Copyright (c) 2012 Titanium I.T. LLC. All rights reserved. See LICENSE.txt for details.
/*global desc, task, file, jake, rule, fail, complete, directory*/

(function() {
	"use strict";

	var startTime = Date.now();

	// We've put most of our require statements in functions (or tasks) so we don't have the overhead of
	// loading modules we don't need. At the time this refactoring was done, module loading took about half a
	// second, which was 10% of our desired maximum of five seconds for a quick build.
	// The require statements here are just the ones that are used to set up the tasks.
	var paths = require("./build/config/paths.js");

	var strict = !process.env.loose;
	if (strict) console.log("For more forgiving test settings, use 'loose=true'");

	//*** DIRECTORIES

	directory(paths.tempTestfileDir);
	directory(paths.buildDir);
	directory(paths.buildClientDir);
	directory(paths.incrementalDir);


	//*** GENERAL

	jake.addListener('complete', function () {
		var elapsedSeconds = (Date.now() - startTime) / 1000;
		console.log("\n\nBUILD OK (" + elapsedSeconds.toFixed(2) + "s)");
	});

	desc("Delete all generated files");
	task("clean", [], function() {
		jake.rmRf(paths.generatedDir);
	});

	desc("Lint and test everything");
	task("default", [ "clean", "quick", "smoketest" ]);

	desc("Incrementally lint and test fast targets");
	task("quick", [ "nodeVersion", "lint", "testServer", "testClient" ]);

	desc("Start Karma server for testing");
	task("karma", function() {
		karmaRunner().serve(paths.karmaConfig, complete, fail);
	}, {async: true});

	desc("Start localhost server for manual testing");
	task("run", [ "build" ], function() {
		var runServer = require("./src/_run_server.js");

		console.log("Running server. Press Ctrl-C to stop.");
		runServer.runInteractively();
		// We never call complete() because we want the task to hang until the user presses 'Ctrl-C'.
	}, {async: true});


	//*** LINT

	desc("Lint everything");
	task("lint", [ "lintLog", "incrementalLint" ], function() {
		console.log();
	});

	task("lintLog", function() { process.stdout.write("Linting JavaScript: "); });

	task("incrementalLint", paths.lintDirectories());
	task("incrementalLint", paths.lintOutput());
	createDirectoryDependencies(paths.lintDirectories());

	rule(".lint", determineLintDependency, function() {
		var lint = require("./build/util/lint_runner.js");
		var lintConfig = require("./build/config/jshint.conf.js");

		var passed = lint.validateFile(this.source, lintConfig.options, lintConfig.globals);
		if (passed) fs().writeFileSync(this.name, "lint ok");
		else fail("Lint failed");
	});


	//*** TEST

	desc("Test server code");
	incrementalTask("testServer", paths.serverTestTarget, [ paths.tempTestfileDir ], paths.serverFiles(),
		function(complete, fail) {
		console.log("Testing server code: ");
		mochaRunner().runTests({
			files: paths.serverTestFiles(),
			options: mochaConfig()
		}, complete, fail);
	});


	desc("Test client code");
	incrementalTask("testClient", paths.clientTestTarget, [], paths.clientFiles(), function(complete, fail) {
		console.log("Testing browser code: ");
		karmaRunner().runTests({
			configFile: paths.karmaConfig,
			browsers: require("./build/config/tested_browsers.js"),
			strict: strict
		}, complete, fail);
	});

	desc("End-to-end smoke tests");
	task("smoketest", [ "build" ], function() {
		console.log("Smoke testing app: ");
		mochaRunner().runTests({
			files: paths.smokeTestFiles(),
			options: mochaConfig()
		}, complete, fail);
	}, { async: true });


	//*** BUILD

	desc("Bundle and build code");
	task("build", [ "cacheBust" ]);

	task("cacheBust", [ "collateClientFiles", "bundleClientJs" ], function() {
		console.log("Cache-busting CSS and JavaScript: .");

		var hashCatRunner = require("./build/util/hashcat_runner.js");
		hashCatRunner.go({
			indexFile: paths.buildClientIndexHtml
		}, removeHashCatIntermediateFiles, fail);


		function removeHashCatIntermediateFiles() {
			shell().rm(paths.buildIntermediateFilesToErase);
			complete();
		}

	}, { async: true });

	task("collateClientFiles", [ paths.buildClientDir ], function() {
		console.log("Collating client files: .");

		shell().rm("-rf", paths.buildClientDir + "/*");
		shell().cp(
			"-R",
			"src/client/*.html", "src/client/*.css", "src/client/images", "src/client/vendor", "src/shared/vendor",
			paths.buildClientDir
		);
	});

	task("bundleClientJs", [ paths.buildClientDir ], function() {
		process.stdout.write("Bundling client files with Browserify: ");

		var browserifyRunner = require("./build/util/browserify_runner.js");
		browserifyRunner.bundle({
			requires: [
				{ path: "./src/client/client.js", expose: "./client.js" },
				{ path: "./src/client/html_element.js", expose: "./html_element.js" }
			],
			outfile: paths.buildClientDir + "/bundle.js",
			options: { debug: true }
		}, complete, fail);
	}, {async: true});


	//*** CHECK VERSIONS

	task("nodeVersion", [], function() {
		console.log("Checking Node.js version: .");
		var version = require("./build/util/version_checker.js");

		version.check({
			name: "Node",
			expected: require("./package.json").engines.node,
			actual: process.version,
			strict: strict
		}, complete, fail);
	});


	//*** DEPLOY

	desc("Deploy to Heroku");
	task("deploy", function() {
		console.log("To deploy to production:");
		console.log("1. Make sure `git status` is clean");
		console.log("2. Check in `generated/build/client`");
		console.log("2. Deploy HEAD to staging server: `git push staging master`");
		console.log("3. Verify by visiting http://www-staging.herokuapp.com");
		console.log("4. Integrate");
		console.log("5. Deploy integrated code to staging: `git push staging integration:master`");
		console.log("6. Deploy integrated to production: `git push heroku integration:master`");
		console.log("7. Remove `generated/build/client` from git");
	});


	//*** INTEGRATE

	desc("Integration checklist");
{'fraction_non_alphanumeric': 0.17405223251895535, 'fraction_numerical': 0.0030328559393428814, 'mean_word_length': 4.473029045643154, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '284449', 'n_tokens_mistral': 4057, 'n_tokens_neox': 3682, 'n_words': 919}