text: /*
   * Copyright (c) 2015 airbug Inc. All rights reserved.
   *
   * buildbug may be freely distributed under the MIT license.
   */
  
  
  //-------------------------------------------------------------------------------
  // Requires
  //-------------------------------------------------------------------------------
  
  var buildbug            = require('buildbug');
  
  
  //-------------------------------------------------------------------------------
  // Simplify References
  //-------------------------------------------------------------------------------
  
  var buildProject        = buildbug.buildProject;
  var buildProperties     = buildbug.buildProperties;
  var buildScript         = buildbug.buildScript;
  var buildTarget         = buildbug.buildTarget;
  var enableModule        = buildbug.enableModule;
  var parallel            = buildbug.parallel;
  var series              = buildbug.series;
  var targetTask          = buildbug.targetTask;
  
  
  //-------------------------------------------------------------------------------
  // Enable Modules
  //-------------------------------------------------------------------------------
  
  var aws                 = enableModule("aws");
  var bugpack             = enableModule('bugpack');
  var bugunit             = enableModule('bugunit');
  var clientjs            = enableModule('clientjs');
  var core                = enableModule('core');
  var lintbug             = enableModule("lintbug");
  var nodejs              = enableModule('nodejs', {
      npmConfig: buildProject.getProperty("npmConfig")
  });
  
  
  //-------------------------------------------------------------------------------
  // Values
  //-------------------------------------------------------------------------------
  
  var name                = "buildbug";
  var version             = "0.2.3";
  var dependencies        = {
      "aws-sdk": "2.0.8",
      "bugpack-registry": "0.1.7",
      bugpack: "0.2.0",
      bugunit: "0.1.5",
      jszip: "2.5.0",
      lintbug: "0.1.0",
      "uglify-js": "2.4.15",
      npm: "1.4.21",
      tar: "0.1.20",
      fstream: "0.1.28"
  };
  
  
  //-------------------------------------------------------------------------------
  // Declare Properties
  //-------------------------------------------------------------------------------
  
  buildProperties({
      name: name,
      version: version
  });
  
  buildProperties({
      node: {
          packageJson: {
              name: "{{name}}",
              version: "{{version}}",
              main: "./scripts/buildbug-node.js",
              bin: {
                  buildbug: "bin/buildbug",
                  buildbugdaemon: "bin/buildbugdaemon"
              },
              dependencies: dependencies,
              author: "Brian Neisler <brian@airbug.com>",
              repository: {
                  type: "git",
                  url: "https://github.com/airbug/buildbug.git"
              },
              bugs: {
                  url: "https://github.com/airbug/buildbug/issues"
              },
              licenses: [
                  {
                      type : "MIT",
                      url : "https://raw.githubusercontent.com/airbug/buildbug/master/LICENSE"
                  }
              ]
          },
          readmePath: "./README.md",
          sourcePaths: [
              "../bugaws/libraries/bugaws/js/src",
              "../bugcli/libraries/bugcli/js/src",
              "../bugcore/libraries/bugcore/js/src",
              "../bugfs/libraries/bugfs/js/src",
              "../bugmeta/libraries/bugmeta/js/src",
              "../bugnpm/libraries/bugnpm/js/src",
              "./libraries/buildbug/js/src",
              "./projects/buildbug-node/js/src",
          ],
          scriptPaths: [
              "./libraries/buildbug/js/scripts",
              "./projects/buildbug-node/js/scripts"
          ],
          binPaths: [
              "./projects/buildbug-node/bin"
          ],
          unitTest: {
              packageJson: {
                  name: "buildbug-test",
                  version: version,
                  private: true,
                  main: "./scripts/buildbug-node.js",
                  bin: "bin/buildbug",
                  dependencies: dependencies,
                  scripts: {
                      test: "node ./test/scripts/bugunit-run.js"
                  }
              },
              sourcePaths: [
                  "../buganno/libraries/buganno/js/src",
                  "../bugdouble/libraries/bugdouble/js/src",
                  "../bugunit/libraries/bugunit/js/src",
                  "../bugyarn/libraries/bugyarn/js/src"
              ],
              scriptPaths: [
                  "../buganno/libraries/buganno/js/scripts",
                  "../bugunit/libraries/bugunit/js/scripts"
              ],
              testPaths: [
                  "../bugcli/libraries/bugcli/js/test",
                  "../bugcore/libraries/bugcore/js/test",
                  "../bugfs/libraries/bugfs/js/test",
                  "../bugmeta/libraries/bugmeta/js/test",
                  "./libraries/buildbug/js/test"
              ]
          }
      },
      lint: {
          targetPaths: [
              "."
          ],
          ignorePatterns: [
              ".*\\.buildbug$",
              ".*\\.bugunit$",
              ".*\\.git$",
              ".*node_modules$"
          ]
      }
  });
  
  
  //-------------------------------------------------------------------------------
  // Declare BuildTargets
  //-------------------------------------------------------------------------------
  
  // Clean BuildTarget
  //-------------------------------------------------------------------------------
  
  buildTarget('clean').buildFlow(
      targetTask('clean')
  );
  
  
  // Local BuildTarget
  //-------------------------------------------------------------------------------
  
  buildTarget('local').buildFlow(
      series([
  
          // TODO BRN: This "clean" task is temporary until we're not modifying the build so much. This also ensures that
          // old source files are removed. We should figure out a better way of doing that.
  
          targetTask('clean'),
          targetTask('lint', {
              properties: {
                  targetPaths: buildProject.getProperty("lint.targetPaths"),
                  ignores: buildProject.getProperty("lint.ignorePatterns"),
                  lintTasks: [
                      "cleanupExtraSpacingAtEndOfLines",
                      "ensureNewLineEnding",
                      "indentEqualSignsForPreClassVars",
                      "orderBugpackRequires",
                      "orderRequireAnnotations",
                      "updateCopyright"
                  ]
              }
          }),
          series([
              targetTask('createNodePackage', {
                  properties: {
                      packageJson: buildProject.getProperty("node.packageJson"),
                      packagePaths: {
                          "./": [buildProject.getProperty("node.readmePath")],
                          "./bin": buildProject.getProperty("node.binPaths"),
                          "./lib": buildProject.getProperty("node.sourcePaths"),
                          "./scripts": buildProject.getProperty("node.scriptPaths"),
                          "./test": buildProject.getProperty("node.unitTest.testPaths"),
                          "./test/lib": buildProject.getProperty("node.unitTest.sourcePaths"),
                          "./test/scripts": buildProject.getProperty("node.unitTest.scriptPaths")
                      }
                  }
              }),
              targetTask('generateBugPackRegistry', {
                  init: function(task, buildProject, properties) {
                      var nodePackage = nodejs.findNodePackage(
                          buildProject.getProperty("node.packageJson.name"),
                          buildProject.getProperty("node.packageJson.version")
                      );
                      task.updateProperties({
                          sourceRoot: nodePackage.getBuildPath()
                      });
                  }
              }),
              targetTask('packNodePackage', {
                  properties: {
                      packageName: buildProject.getProperty("node.packageJson.name"),
                      packageVersion: buildProject.getProperty("node.packageJson.version")
                  }
              }),
              targetTask('startNodeModuleTests', {
                  init: function(task, buildProject, properties) {
                      var packedNodePackage = nodejs.findPackedNodePackage(
                          buildProject.getProperty("node.packageJson.name"),
                          buildProject.getProperty("node.packageJson.version")
                      );
                      task.updateProperties({
                          modulePath: packedNodePackage.getFilePath()
                          //checkCoverage: true
                      });
                  }
              }),
              targetTask("s3PutFile", {
                  init: function(task, buildProject) {
                      var packedNodePackage = nodejs.findPackedNodePackage(buildProject.getProperty("node.packageJson.name"),
                          buildProject.getProperty("node.packageJson.version"));
                      task.updateProperties({
                          file: packedNodePackage.getFilePath(),
                          options: {
  
                              //TODO BRN: In order to protect this file we need to limit the access to this artifact and provide some sort of http auth access so that the artifacts are retrievable via npm install. This would need to be done in a server wrapper.
  
                              acl: 'public-read'
                          }
                      });
                  },
                  properties: {
                      bucket: "{{local-bucket}}"
                  }
              })
          ])
      ])
  ).makeDefault();
  
  
  // Prod BuildTarget
  //-------------------------------------------------------------------------------
  
  buildTarget("prod").buildFlow(
      series([
  
          // TODO BRN: This "clean" task is temporary until we're not modifying the build so much. This also ensures that
          // old source files are removed. We should figure out a better way of doing that.
  
          targetTask("clean"),
          targetTask('lint', {
              properties: {
                  targetPaths: buildProject.getProperty("lint.targetPaths"),
                  ignores: buildProject.getProperty("lint.ignorePatterns"),
                  lintTasks: [
                      "cleanupExtraSpacingAtEndOfLines",
                      "ensureNewLineEnding",
                      "indentEqualSignsForPreClassVars",
                      "orderBugpackRequires",
                      "orderRequireAnnotations",
                      "updateCopyright"
                  ]
              }
          }),
          parallel([
              series([
                  targetTask("createNodePackage", {
                      properties: {
                          packageJson: buildProject.getProperty("node.packageJson"),
                          packagePaths: {
                              "./": [buildProject.getProperty("node.readmePath")],
                              "./bin": buildProject.getProperty("node.binPaths"),
                              "./lib": buildProject.getProperty("node.sourcePaths"),
                              "./scripts": buildProject.getProperty("node.scriptPaths"),
                              "./test": buildProject.getProperty("node.unitTest.testPaths"),
                              "./test/lib": buildProject.getProperty("node.unitTest.sourcePaths"),
                              "./test/scripts": buildProject.getProperty("node.unitTest.scriptPaths")
                          }
                      }
                  }),
                  targetTask("generateBugPackRegistry", {
                      init: function(task, buildProject, properties) {
                          var nodePackage = nodejs.findNodePackage(
                              buildProject.getProperty("node.packageJson.name"),
                              buildProject.getProperty("node.packageJson.version")
                          );
                          task.updateProperties({
                              sourceRoot: nodePackage.getBuildPath()
                          });
                      }
                  }),
                  targetTask("packNodePackage", {
                      properties: {
                          packageName: buildProject.getProperty("node.packageJson.name"),
                          packageVersion: buildProject.getProperty("node.packageJson.version")
                      }
                  }),
                  targetTask("startNodeModuleTests", {
                      init: function(task, buildProject, properties) {
                          var packedNodePackage = nodejs.findPackedNodePackage(
                              buildProject.getProperty("node.packageJson.name"),
                              buildProject.getProperty("node.packageJson.version")
                          );
                          task.updateProperties({
                              modulePath: packedNodePackage.getFilePath(),
                              checkCoverage: true
                          });
                      }
                  })
              ]),
  
              // Create production package
  
              series([
                  targetTask("createNodePackage", {
                      properties: {
                          packageJson: buildProject.getProperty("node.packageJson"),
                          packagePaths: {
                              "./": [buildProject.getProperty("node.readmePath")],
                              "./bin": buildProject.getProperty("node.binPaths"),
                              "./lib": buildProject.getProperty("node.sourcePaths"),
                              "./scripts": buildProject.getProperty("node.scriptPaths")
                          }
                      }
                  }),
                  targetTask("generateBugPackRegistry", {
                      init: function(task, buildProject) {
                          var nodePackage = nodejs.findNodePackage(
                              buildProject.getProperty("node.packageJson.name"),
                              buildProject.getProperty("node.packageJson.version")
                          );
                          task.updateProperties({
                              sourceRoot: nodePackage.getBuildPath()
                          });
                      }
                  }),
                  targetTask("packNodePackage", {
                      properties: {
                          packageName: buildProject.getProperty("node.packageJson.name"),
                          packageVersion: buildProject.getProperty("node.packageJson.version")
                      }
                  }),
                  targetTask("s3PutFile", {
                      init: function(task, buildProject, properties) {
                          var packedNodePackage = nodejs.findPackedNodePackage(buildProject.getProperty("node.packageJson.name"),
                              buildProject.getProperty("node.packageJson.version"));
                          task.updateProperties({
                              file: packedNodePackage.getFilePath(),
                              options: {
  
                                  //TODO BRN: In order to protect this file we need to limit the access to this artifact and provide some sort of http auth access so that the artifacts are retrievable via npm install. This would need to be done in a server wrapper.
  
                                  acl: "public-read",
                                  encrypt: true
                              }
                          });
                      },
                      properties: {
                          bucket: "{{public-bucket}}"
                      }
                  }),
                  targetTask('npmConfigSet', {
                      properties: {
                          config: buildProject.getProperty("npmConfig")
                      }
                  }),
                  targetTask('npmAddUser'),
                  targetTask('publishNodePackage', {
                      properties: {
                          packageName: "{{node.packageJson.name}}",
                          packageVersion: "{{node.packageJson.version}}"
                      }
                  })
              ])
          ])
      ])
  );
  
  
  //-------------------------------------------------------------------------------
  // Build Scripts
  //-------------------------------------------------------------------------------
  
  buildScript({
      dependencies: [
          "bugcore",
          "bugflow",
          "bugfs"
      ],
      script: "./lintbug.js"
  });
  