var path = require('path');
var _ = require('lodash');

function pathToArray(parts) {
  var part = parts.shift();
  if (parts.length > 0) {
    var obj = {};
    obj[part] = pathToArray(parts);
    return obj;
  } else {
    return part;
  }
}

module.exports = function(grunt) {
  grunt.registerMultiTask('examples', 'Build examples site.', function() {
    var options = this.options({
      base: '',
      excludes: []
    });

    this.files.forEach(function(f) {
      var results = {};
      f.src.filter(function(filepath) {
        if (!grunt.file.exists(filepath)) {
          grunt.log.warn('Source file "' + filepath + '" not found.');
          return false;
        } else {
          filepath = path.relative(options.base, filepath);
          return options.excludes.every(function(dir) {
            return filepath.indexOf(dir + '/') < 0;
          });
        }
      }).map(function(filepath) {
        return pathToArray(path.relative(options.base, filepath).split('/'));
      }).forEach(function(parts) {
        _.merge(results, parts, function(a, b) {
          var example = {
            file: encodeURIComponent(b).replace(/%20/g, '+'),
            title: b.substr(0, b.length - 3)
          };
          return _.isArray(a) ? a.concat(example) : [example];
        });
      });

      grunt.file.write(f.dest, JSON.stringify(results, null, '  '));
    });
  });
};

@@ -458,24 +458,272 @@
 nction(f) %7B%0A
+      if (grunt.option('verbose')) %7B%0A        if (grunt.file.exists(f.dest)) %7B%0A          grunt.verbose.writeln();%0A          grunt.verbose.warn('Destination file %22%25s%22 will be overridden.', f.dest);%0A        %7D%0A        grunt.verbose.writeln();%0A      %7D%0A%0A
       var re
@@ -739,16 +739,28 @@
 %7D;%0A     
+ var files =
  f.src.f
@@ -1070,22 +1070,26 @@
         
-return
+var keep =
  filepat
@@ -1128,30 +1128,492 @@
     
-%7D);%0A        %7D%0A      %7D)
+  if (!keep) %7B%0A              grunt.verbose.writeln('Skipping %25s%25s...', (dir + '/').inverse.red, filepath.substr(dir.length + 1));%0A            %7D%0A            return keep;%0A          %7D);%0A        %7D%0A      %7D);%0A%0A      if (grunt.option('verbose')) %7B%0A        grunt.verbose.writeln();%0A        grunt.verbose.writeln('Found ' + files.length.toString().cyan + ' examples:');%0A        files.forEach(function(file) %7B%0A          grunt.verbose.writeln(' * '.cyan + file);%0A        %7D);%0A      %7D%0A%0A      files
 .map
@@ -2024,24 +2024,444 @@
 %0A      %7D);%0A%0A
+      if (grunt.option('verbose')) %7B%0A        var categories = Object.keys(results);%0A        grunt.verbose.writeln();%0A        grunt.verbose.writeln('Extracted ' + categories.length.toString().cyan + ' categories:');%0A        categories.forEach(function(cat) %7B%0A          grunt.verbose.writeln(' * '.cyan + cat);%0A        %7D);%0A      %7D%0A%0A      grunt.verbose.writeln();%0A      grunt.verbose.or.write('Writing ' + f.dest + '...');%0A
       grunt.
@@ -2513,24 +2513,53 @@
 ll, '  '));%0A
+      grunt.verbose.or.ok();%0A
     %7D);%0A  %7D)

Add verbose output to examples task