var PDFShooter = require('./pdf-shooter'),
    Q = require('q'),
    Screenshot = require('./screenshot'),
    Sitemap = require('./sitemap'),
    utils = require('./utils'),
    Website = require('./website');


function checkForCommand(options) {

    var commands = [
            'pdf',
            'screenshots',
            'sitemap',
            'website'
        ],
        hasCommand = commands.filter(function(item) {
            return (options[item]);
        });

    return hasCommand;
}

/**
 * Tasks Object
 * @author Steven Britton
 * @date   2016-04-12
 * @param  {Object}   options Contains configuration options and CLI arguments
 */
function Tasks(options) {

    var deferred = Q.defer(),
        hasCommand = checkForCommand(options),
        pdfShooter,
        screenshot,
        sitemap = new Sitemap({
            auth: {
                pwd: options.domain.auth.pwd,
                user: options.domain.auth.user
            },
            url: options.domain.name,
            filename: options.domain.sitemap.url + '.' + options.domain.sitemap.type
        }),
        website;


    // if 0 commands were passed, run the following in sequence
    if (hasCommand.length === 0) {
        options.sitemap = 'create';
        options.screenshots = true;
        options.pdf = true;
    }

    utils.executeWhen(options.sitemap && options.sitemap === 'create', () => sitemap.create(), '')
        .then(function() {
            return utils.executeWhen(options.sitemap && options.sitemap === 'delete', () => sitemap.delete());
        })
        .then(function() {

            // are we screenshooting?
            return utils.executeWhen(options.screenshots, function() {

                // get local sitemap.xml and convert to JSON format
                return sitemap.toJSON()
                    .then(function(data) {

                        // set screenshots object
                        screenshot = new Screenshot({
                            pages: data,
                            options: options
                        });

                        // run screenshots
                        return screenshot.start();
                    });
            });
        })
        .then(function() {

            // are we generating PDFs?
            return utils.executeWhen(options.pdf, function() {

                pdfShooter = new PDFShooter(options);

                return pdfShooter.start();

            });
        })
        .then(function() {

            // are we looking for website information
            return utils.executeWhen(options.website, function() {

                website = new Website(options);

                return website.get();

            });
        })

    .done(function() {
            deferred.resolve();
        },
        function(err) {
            deferred.reject(err);
        });


    return deferred.promise;

}


module.exports = {
    init: Tasks
};

@@ -1,12 +1,48 @@
 var 
+Crawler = require('./crawler'),%0A    
 PDFShoot
@@ -68,24 +68,24 @@
 -shooter'),%0A
-
     Q = requ
@@ -300,16 +300,39 @@
 nds = %5B%0A
+            'crawler',%0A
         
@@ -740,16 +740,33 @@
     var 
+crawler,%0A        
 deferred
@@ -1386,24 +1386,212 @@
 %0A    %7D%0A%0A    
+utils.executeWhen(options.crawler, function() %7B%0A%0A            crawler = new Crawler(options);%0A%0A            return crawler.start();%0A%0A        %7D)%0A        .then(function() %7B%0A            return 
 utils.execut
@@ -1671,12 +1671,20 @@
 te()
-, ''
+);%0A        %7D
 )%0A  

add crawler function to tasks