Skip to content

Commit

Permalink
resolves #41, change default phantomjs bin
Browse files Browse the repository at this point in the history
  • Loading branch information
localnerve committed Aug 7, 2015
1 parent 566639f commit c2f5e28
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
36 changes: 27 additions & 9 deletions lib/html-snapshots.js
Expand Up @@ -3,7 +3,7 @@
*
* Produce html snapshots using for a website for SEO purposes.
* This is required for javascript SPAs or ajax page output.
* By default, uses a selector to search content to determine if
* By default, uses a selector to search content to determine if
* a page is "ready" for its html snapshot.
*
* Copyright (c) 2013, 2014, Alex Grant, LocalNerve, contributors
Expand All @@ -20,15 +20,33 @@ var inputFactory = require("./input-generators");
var async = require("./async");
var phantomDir = "./phantom";
var snapshotScript = path.join(phantomDir, "default.js");
var phantomJS = "../node_modules/.bin/phantomjs" +
(process.platform === "win32" ? ".cmd" : "");

/**
* Determine the default phantomJS module path. This is overridden by the
* phatomjs option.
*
* Technique (and concerns) from karma-phantomjs-launcher (MIT).
*/
var defaultPhantomJSExePath = function () {
// If the path we're given by phantomjs is to a .cmd, it is pointing to a global copy.
// Using the cmd as the process to execute causes problems cleaning up the processes
// so we walk from the cmd to the phantomjs.exe and use that instead.

var phantomSource = require('phantomjs').path;

if (path.extname(phantomSource).toLowerCase() === '.cmd') {
return path.join(path.dirname( phantomSource ), '//node_modules//phantomjs//lib//phantom//phantomjs.exe');
}

return phantomSource;
};

/**
* This module's defaults
*/
var defaults = {
input: "robots",
phantomjs: path.join(__dirname, phantomJS),
phantomjs: defaultPhantomJSExePath(),
snapshotScript: path.join(__dirname, snapshotScript),
outputDirClean: false,
pollInterval: 500,
Expand All @@ -43,7 +61,7 @@ function worker(input, options, notifier, qcb) {
customModule,
snapshotScript = options.snapshotScript,
phantomjsOptions = Array.isArray(input.phantomjsOptions) ? input.phantomjsOptions : [input.phantomjsOptions];

// map snapshotScript object script to a real path
if (_.isObject(options.snapshotScript)) {
snapshotScript = path.join(__dirname, phantomDir, options.snapshotScript.script) + ".js";
Expand Down Expand Up @@ -77,7 +95,7 @@ function worker(input, options, notifier, qcb) {
});

// start counting
notifier.add(input.outputFile, input.timeout);
notifier.add(input.outputFile, input.timeout);
}

module.exports = {
Expand Down Expand Up @@ -110,15 +128,15 @@ module.exports = {
task(_.once(callback));
}, options.processLimit);

// have the queue call notifier.empty when last item
// have the queue call notifier.empty when last item
// from the queue is given to a worker.
q.empty = notifier.qEmpty;

// expose abort callback to input generators via options
options._abort = function(err) {
notifier.abort(q, err);
};

// generate input for the snapshots
result = inputGenerator.run(options, function(input) {
// give the worker the input and place into the queue
Expand All @@ -128,4 +146,4 @@ module.exports = {

return result;
}
};
};
16 changes: 6 additions & 10 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "html-snapshots",
"version": "0.9.0",
"version": "0.10.0",
"author": {
"name": "Alex Grant",
"email": "alex@localnerve.com",
Expand All @@ -21,7 +21,8 @@
"lint": "grunt lint",
"test": "grunt test",
"coverage": "istanbul cover -- grunt test",
"ci": "grunt lint && istanbul cover -- grunt test && grunt coveralls"
"ci": "grunt lint && istanbul cover -- grunt test && grunt coveralls",
"validate": "npm ls"
},
"pre-commit": [
"lint"
Expand Down Expand Up @@ -58,16 +59,11 @@
"istanbul": "^0.3.14",
"matchdep": "^0.3.0",
"mkdirp": "^0.5.1",
"precommit-hook": "^2.0.1",
"precommit-hook": "^3.0.0",
"sitemap-xml": "~0.1.0"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/localnerve/html-snapshots/blob/master/LICENSE"
}
],
"license": "MIT",
"engines": {
"node": "^0.10.0"
"node": "^0.12.0"
}
}

0 comments on commit c2f5e28

Please sign in to comment.