/* global complete, desc, directory, fail, jake, task */
"use strict";

desc("Full build.");
task("default", ["check node version", "lint", "test"]);

directory("build");

desc("Runs JSLint (to catch common JavaScript errors).");
task("lint", /* jshint latedef: false */ function() {
  var lint_runner = require("./src/build/lint/lint_runner.js");

  var allJavaScriptSources = new jake.FileList();
  allJavaScriptSources.include("**/*.js");
  allJavaScriptSources.exclude("node_modules");  // assuming these are properly linted, already.
  var passesLint = lint_runner.validateFileList(allJavaScriptSources, getJSHintOptions());

  if(!passesLint) { fail("Task 'lint' failed (see above)."); }
});

desc("Runs unit tests.");
task("test", ["build"], function() {
  var reporter = require('nodeunit').reporters.default;
  reporter.run(['src/specs/server'], null, function(failureOccurred) {
      if(failureOccurred) { fail("Task 'test' failed (see above)."); }
      complete();
    });
}, {async: true});

desc("Integration");
task("integrate", ["default"], function() {
  console.log("Steps for the commit tango...");
  console.log("1. Verify the build on the master branch, locally.\n   yourbox$ ./jake.sh\n");
  console.log("2. Pull to the Integation Station and verify the build there.\n   integration$ git pull && ./jake.sh\n");
  console.log("3. If all good, merge changes into 'last-known-good'\n   yourbox$ merge-to-integration.sh\n");
});

function getJSHintOptions() {
  return {
    bitwise: false,
    curly: true,
    eqeqeq: true,
    forin: true,
    immed: true,
    latedef: true,
    newcap: true,
    noarg: true,
    nonew: true,
    undef: true,
    unused: true,
    strict: true,
    trailing: true,
    maxstatements: 15,
    maxcomplexity: 10,
    node: true
  };
}

task("check node version", function() {
  var expectedNodeVersion = "v0.10.8";
  var actualNodeVersion = process.version;

  // since node.js is changes quite frequently, making this an exact match, for now.
  if(actualNodeVersion !== expectedNodeVersion) {
    fail(actualNodeVersion + " is an unsupported version of node.js.  Must be " + expectedNodeVersion);
  }
});


@@ -65,16 +65,42 @@
 rict%22;%0A%0A
+var BUILD_DIR = %22build%22;%0A%0A
 desc(%22Fu
@@ -150,16 +150,25 @@
 ersion%22,
+ %22clean%22,
  %22lint%22,
@@ -189,23 +189,150 @@
 rectory(
-%22build%22
+BUILD_DIR);%0A%0Adesc(%22Purges the build output directory (i.e. %22 + BUILD_DIR + %22).%22);%0Atask(%22clean%22, function() %7B%0A  jake.rmRf(BUILD_DIR);%0A%7D
 );%0A%0Adesc
@@ -894,23 +894,25 @@
 test%22, %5B
-%22build%22
+BUILD_DIR
 %5D, funct

Build script can create and purge the build directory.