/*
 * Scale-Out-Agile
 * 
 * Arlo Belshee
 * https://github.com/arlobelshee/Scale-Out-Agile
 * 
 * Copyright (c) 2014
 * Licensed under the MIT license.
 */

module.exports = function(grunt) {
'use strict';

  // Delete after first run
  if(!grunt.file.exists('vendor/bootstrap')) {
    grunt.fail.fatal('>> Please run "bower install" before continuing.');
  }

  // Project configuration.
  grunt.initConfig({

    // Project metadata
    pkg   : grunt.file.readJSON('package.json'),
    vendor: grunt.file.readJSON('.bowerrc').directory,
    site  : grunt.file.readYAML('_config.yml'),
    bootstrap: '<%= vendor %>/bootstrap',


    // Before generating any new files, remove files from previous build.
    clean: {
      example: ['<%= site.dest %>/*.html'],
      // Delete this target after first run!!!
      once: ['<%= site.theme %>/bootstrap/{var*,mix*,util*}.less']
    },


    // Lint JavaScript
    jshint: {
      all: ['Gruntfile.js', 'templates/helpers/*.js'],
      options: {
        jshintrc: '.jshintrc'
      }
    },


    // Build HTML from templates and data
    assemble: {
      options: {
        flatten: true,
        production: false,
        assets: '<%= site.assets %>',
        postprocess: require('pretty'),

        // Metadata
        pkg: '<%= pkg %>',
        site: '<%= site %>',
        data: ['<%= site.data %>'],

        // Templates
        partials: '<%= site.includes %>',
        layoutdir: '<%= site.layouts %>',
        layout: '<%= site.layout %>',

        // Extensions
        helpers: '<%= site.helpers %>',
        plugins: '<%= site.plugins %>'
      },
      example: {
        files: {'<%= site.dest %>/': ['<%= site.templates %>/*.hbs']}
      }
    },


    // Compile LESS to CSS
    less: {
      options: {
        vendor: 'vendor',
        paths: [
          '<%= site.theme %>',
          '<%= site.theme %>/bootstrap',
          '<%= site.theme %>/components',
          '<%= site.theme %>/utils'
        ],
      },
      site: {
        src: ['<%= site.theme %>/site.less'],
        dest: '<%= site.assets %>/css/site.css'
      }
    },


    // Copy Bootstrap's assets to site assets
    copy: {
      // Delete this target after first run!!! Afterwards you'll need to
      // decide on a strategy for adding javascripts, fonts etc.
      once: {
        files: [
          {expand: true, cwd: '<%= bootstrap %>/less', src: ['*', '!{var*,mix*,util*}'], dest: '<%= site.theme %>/bootstrap/'},
          {expand: true, cwd: '<%= bootstrap %>/less', src: ['{util*,mix*}.less'], dest: '<%= site.theme %>/utils'},
          {expand: true, cwd: '<%= bootstrap %>/less', src: ['variables.less'], dest: '<%= site.theme %>/'},
          {expand: true, cwd: 'node_modules/showup', src: ['showup.js'], dest: '<%= site.assets %>/js/'},
          {expand: true, cwd: 'node_modules/showup', src: ['showup.css'], dest: '<%= site.theme %>/components/', ext: '.less'},
        ]
      },
      // Keep this target as a getting started point
      assets: {
        files: [
          {expand: true, cwd: '<%= bootstrap %>/dist/fonts', src: ['*.*'], dest: '<%= site.assets %>/fonts/'},
          {expand: true, cwd: '<%= bootstrap %>/dist/js',    src: ['*.*'], dest: '<%= site.assets %>/js/'},
        ]
      }
    },

    watch: {
      all: {
        files: ['<%= jshint.all %>'],
        tasks: ['jshint', 'nodeunit']
      },
      site: {
        files: ['Gruntfile.js', '<%= less.options.paths %>/*.less', 'templates/**/*.hbs'],
        tasks: ['design']
      }
    }
  });

  // Load npm plugins to provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-readme');
  grunt.loadNpmTasks('grunt-sync-pkg');
  grunt.loadNpmTasks('assemble-less');
  grunt.loadNpmTasks('assemble');

  // Run this task once, then delete it as well as all of the "once" targets.
  grunt.registerTask('setup', ['copy:once', 'clean:once']);

  // Build HTML, compile LESS and watch for changes. You must first run "bower install"
  // or install Bootstrap to the "vendor" directory before running this command.
  grunt.registerTask('design', ['clean', 'assemble', 'less:site', 'watch:site']);

  grunt.registerTask('docs', ['readme', 'sync']);

  // Delete this conditional logic after first run.
  if(!grunt.file.exists('_gh_pages_/assets/fonts') && !grunt.file.exists('_gh_pages_/assets/js')) {
    grunt.registerTask('default', ['setup', 'clean', 'jshint', 'copy:assets', 'assemble', 'less', 'docs']);
  } else {
    // Use this going forward.
    grunt.registerTask('default', ['clean', 'jshint', 'copy:assets', 'assemble', 'less', 'docs']);
  }
};
@@ -205,162 +205,8 @@
 ';%0A%0A
-  // Delete after first run%0A  if(!grunt.file.exists('vendor/bootstrap')) %7B%0A    grunt.fail.fatal('%3E%3E Please run %22bower install%22 before continuing.');%0A  %7D%0A%0A
   //
@@ -229,16 +229,16 @@
 ration.%0A
+
   grunt.
@@ -606,122 +606,8 @@
 '%5D,%0A
-      // Delete this target after first run!!!%0A      once: %5B'%3C%25= site.theme %25%3E/bootstrap/%7Bvar*,mix*,util*%7D.less'%5D%0A
     
@@ -1898,837 +1898,8 @@
 : %7B%0A
-      // Delete this target after first run!!! Afterwards you'll need to%0A      // decide on a strategy for adding javascripts, fonts etc.%0A      once: %7B%0A        files: %5B%0A          %7Bexpand: true, cwd: '%3C%25= bootstrap %25%3E/less', src: %5B'*', '!%7Bvar*,mix*,util*%7D'%5D, dest: '%3C%25= site.theme %25%3E/bootstrap/'%7D,%0A          %7Bexpand: true, cwd: '%3C%25= bootstrap %25%3E/less', src: %5B'%7Butil*,mix*%7D.less'%5D, dest: '%3C%25= site.theme %25%3E/utils'%7D,%0A          %7Bexpand: true, cwd: '%3C%25= bootstrap %25%3E/less', src: %5B'variables.less'%5D, dest: '%3C%25= site.theme %25%3E/'%7D,%0A          %7Bexpand: true, cwd: 'node_modules/showup', src: %5B'showup.js'%5D, dest: '%3C%25= site.assets %25%3E/js/'%7D,%0A          %7Bexpand: true, cwd: 'node_modules/showup', src: %5B'showup.css'%5D, dest: '%3C%25= site.theme %25%3E/components/', ext: '.less'%7D,%0A        %5D%0A      %7D,%0A      // Keep this target as a getting started point%0A
     
@@ -2821,147 +2821,8 @@
 );%0A%0A
-  // Run this task once, then delete it as well as all of the %22once%22 targets.%0A  grunt.registerTask('setup', %5B'copy:once', 'clean:once'%5D);%0A%0A
   //
@@ -3124,312 +3124,8 @@
 );%0A%0A
-  // Delete this conditional logic after first run.%0A  if(!grunt.file.exists('_gh_pages_/assets/fonts') && !grunt.file.exists('_gh_pages_/assets/js')) %7B%0A    grunt.registerTask('default', %5B'setup', 'clean', 'jshint', 'copy:assets', 'assemble', 'less', 'docs'%5D);%0A  %7D else %7B%0A    // Use this going forward.%0A  
   gr
@@ -3217,14 +3217,10 @@
 ocs'%5D);%0A
-  %7D%0A
 %7D;

Remove all the one-time targets from the Gruntfile.