<commit_before>var crawl = require('./crawl.js');
var Spooky = require('spooky');

module.exports = function (url, targetDir, resolution, imageQuality, imageFormat, showControls, waitTime, maxIndex, callback) {
    var spookyOpts = {
        child: {
            transport: 'http'
        },
        casper: {
            logLevel: 'debug',
            verbose: true,
            viewportSize: resolution ? resolution : null
        },
        child: {
            command: require.resolve('casperjs/bin/casperjs')
        }
    };

    var spooky = new Spooky(spookyOpts, function (err) {
        if (err) {
            e = new Error('Failed to initialise SpookyJS');
            e.details = err;
            throw e;
        }

        spooky.start(url);
        testRevealVersion();
        if (!resolution) setResolution()
        configureReveal();
        crawl(spooky, targetDir, imageFormat, imageQuality, waitTime, maxIndex);

        spooky.run(function () {
            this.emit('finished');
            this.exit(0);
        });
    });

    spooky.on('error', function (e, stack) {
        console.error(e);
        if (stack) {
            console.log(stack);
        }
    });

    spooky.on('console', function (line) {
        console.log(line);<commit_msg>Explicit requirement of `casperjs`'s own `phantomjs` executable path.<commit_after>var crawl = require('./crawl.js');
var Spooky = require('spooky');

module.exports = function (url, targetDir, resolution, imageQuality, imageFormat, showControls, waitTime, maxIndex, callback) {
    var env = process.env;

    // forwarding the path towards the local copy of PhantomJS
    env.PHANTOMJS_EXECUTABLE = require.resolve('casperjs/node_modules/.bin/phantomjs');

    var spookyOpts = {
        child: {
            transport: 'http'
        },
        casper: {
            logLevel: 'debug',
            verbose: true,
            viewportSize: resolution ? resolution : null
        },
        child: {
            command: require.resolve('casperjs/bin/casperjs'),
            spawnOptions: {
                env: env
            }
        }
    };

    var spooky = new Spooky(spookyOpts, function (err) {
        if (err) {
            e = new Error('Failed to initialise SpookyJS');
            e.details = err;
            throw e;
        }

        spooky.start(url);
        testRevealVersion();
        if (!resolution) setResolution()
        configureReveal();
        crawl(spooky, targetDir, imageFormat, imageQuality, waitTime, maxIndex);

        spooky.run(function () {
            this.emit('finished');
            this.exit(0);
        });
    });

    spooky.on('error', function (e, stack) {
        console.error(e);
        if (stack) {
            console.log(stack);
        }
    });

    spooky.on('console', function (line) {
        console.log(line);
{'fraction_non_alphanumeric': 0.12613875262789068, 'fraction_numerical': 0.000700770847932726, 'mean_word_length': 1.913265306122449, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2786235', 'n_tokens_mistral': 859, 'n_tokens_neox': 833, 'n_words': 181}