// Generated by CoffeeScript 1.7.1
(function() {
  var path, through, glob, _, del;

  glob = require("glob-all");

  through = require("through");

  path = require("path");

  _ = require("underscore");

  del = require("del");

  module.exports = function(dest, destPatterns) {
    var srcFiles, destFiles, files, onEnd, onFile;
    files = [];
    srcFiles = [];

    destFiles = glob.sync( destPatterns );

    onFile = function(file) {
      srcFiles.push(file.path);
      this.push(file);
      return files.push(file);
    };
    onEnd = function() {
      _.each(srcFiles, function(item, index) {
        srcFiles[index] = item.substr(process.cwd().length);
      });
      _.each(destFiles, function(item, index) {
        destFiles[index] = item.substr(dest.length);
      })
      //compare source and destination files and delete any missing in source at destination
      var deletedFiles = _.difference(destFiles, srcFiles);
      _.each(deletedFiles, function(item, index) {
        deletedFiles[index] = dest + deletedFiles[index];
        del.sync(deletedFiles[index]);
      })

      return this.emit("end");
    };
    return through(onFile, onEnd);
  };

}).call(this);

// Generated by CoffeeScript 1.7.1
(function() {
  var path, through, glob, _, del;

  glob = require("glob-all");

  through = require("through");

  path = require("path");

  _ = require("underscore");

  del = require("del");

  module.exports = function(dest, destPatterns, options) {
    var srcFiles, destFiles, files, onEnd, onFile;
    files = [];
    srcFiles = [];

    destFiles = glob.sync( destPatterns );

    onFile = function(file) {
      srcFiles.push(file.path);
      this.push(file);
      return files.push(file);
    };
    onEnd = function() {
      _.each(srcFiles, function(item, index) {
        srcFiles[index] = item.substr(process.cwd().length);
      });
      _.each(destFiles, function(item, index) {
        destFiles[index] = item.substr(dest.length);
      })
      //compare source and destination files and delete any missing in source at destination
      var deletedFiles = _.difference(destFiles, srcFiles);
      _.each(deletedFiles, function(item, index) {
        deletedFiles[index] = dest + deletedFiles[index];
        del.sync(deletedFiles[index], {force: (options ? (options.force && typeof options.force === 'boolean') : false)});
      })

      return this.emit("end");
    };
    return through(onFile, onEnd);
  };

}).call(this);

Allow deletion outside working dir