Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
test
Empty file modified cli.js
100644 → 100755
Empty file.
16 changes: 6 additions & 10 deletions config/chrome.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
{
"project": "Test",
"project": "Google Test",
"domains": {
"bbc.co.uk": "http://www.bbc.co.uk",
"live.bbc.co.uk": "http://www.live.bbc.co.uk"
"usa": "http://www.google.com",
"canada": "http://www.google.ca"
},
"engines" : [
"phantomjs"
],
"sizes": [
"320",
"768",
"1440"
],
"paths": [
"/",
"/news",
"/weather",
"/tv",
"/aboutthebbc"
"/404"
],
"outputDir": "bbc",
"outputDir": "test",
"fuzz": "20%",
"maxConnections": 20
}
}
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

var fs = require('fs'),
wraith = require('./lib/wraith'),
spider = require('./lib/spider');
spider = require('./lib/spider'),
path = require('path');

module.exports.run = run;

Expand All @@ -13,10 +14,10 @@ function run(configFile) {
outputFolder = '',
baseFolder = process.cwd() + '/';

var config = require(baseFolder + 'config/' + configFile + '.json');
var config = require(path.join(baseFolder, configFile));

outputFolder = typeof config.outputDir === 'undefined' ? baseFolder + 'shots/' : baseFolder + 'shots/' + config.outputDir;

outputFolder = path.join(baseFolder, config.outputDir || 'shots/');
for(var domain in config.domains) {
domains.push(config.domains[domain].replace(/\/+$/, ''));
domainLabels.push(domain);
Expand Down Expand Up @@ -52,4 +53,4 @@ function run(configFile) {
wraith(config, config.engines, domains, config.sizes, domainLabels, outputFolder, cb);
}
}
}
}
7 changes: 4 additions & 3 deletions lib/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
var fs = require('fs');
var helpers = require('./helpers');
var mustache = require('mustache');
var path = require('path')

module.exports.generate = generate;

function generate(dirs, compareList, outputDir, project, cb) {
compareList = compareList.sort(helpers.sortByProp('sort'));
var template = __dirname + '/../gallery.html',
var template = path.join(__dirname, '/../gallery.html'),
view = {
'images' : compareList,
'dirs': dirs.sort(),
Expand All @@ -31,7 +32,7 @@ function generate(dirs, compareList, outputDir, project, cb) {
fs.readFile(template, function (err, data) {
if (err) { throw err; }
var output = mustache.render(data.toString(), view);
fs.writeFile(outputDir + 'gallery.html', output, function(err) {
fs.writeFile(path.join(outputDir, 'gallery.html'), output, function(err) {
if(err) {
console.log(err);
} else {
Expand All @@ -40,4 +41,4 @@ function generate(dirs, compareList, outputDir, project, cb) {
}
});
});
}
}
11 changes: 6 additions & 5 deletions lib/wraith.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var fs = require('fs'),
path = require('path'),
async = require('async'),
mkdirp = require('mkdirp'),
gallery = require('./gallery'),
Expand Down Expand Up @@ -37,7 +38,7 @@ function wraith(config, engines, domains, sizes, domainLabels, outputFolder, cb)
});

for(var url in urls) {
folder = outputFolder + urls[url].substring(1).replace(/\/+$/,'') + '/';
folder = path.join(outputFolder, urls[url].substring(1).replace(/\/+$/,'') + '/');
foldersQueue.push(folder);
dirs.push(folder);
}
Expand All @@ -55,7 +56,7 @@ function wraith(config, engines, domains, sizes, domainLabels, outputFolder, cb)
for(var domain in domains) {
for(url in urls) {
imageUrls.push(domains[domain] + urls[url]);
folder = outputFolder + urls[url].substring(1).replace(/\/+$/,'') + '/';
folder = path.join(outputFolder, urls[url].substring(1).replace(/\/+$/,'') + '/');
for(size in sizes) {
image = folder + domainLabels[domain] + '_' + sizes[size] + '.png';
screenshotQueue.push({
Expand All @@ -72,7 +73,7 @@ function wraith(config, engines, domains, sizes, domainLabels, outputFolder, cb)
for(url in urls) {
for(var engine in engines) {
imageUrls.push(domains[0] + urls[url]);
folder = outputFolder + urls[url].substring(1).replace(/\/+$/,'') + '/';
folder = path.join(outputFolder, urls[url].substring(1).replace(/\/+$/,'') + '/');
for(size in sizes) {
image = folder + engines[engine] + '_' + sizes[size] + '.png';
screenshotQueue.push({
Expand Down Expand Up @@ -105,7 +106,7 @@ function wraith(config, engines, domains, sizes, domainLabels, outputFolder, cb)

for(var url in urls) {
var dir = urls[url].substring(1).replace(/\/+$/,'') + '/';
folder = outputFolder + dir;
folder = path.join(outputFolder, dir);
for(var size in sizes) {
item = {
'dir': ( size > 0 ? false : folder),
Expand Down Expand Up @@ -133,4 +134,4 @@ function wraith(config, engines, domains, sizes, domainLabels, outputFolder, cb)
console.log('No url(s) provided');
return false;
}
}
}
21 changes: 18 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "wraith",
"version": "1.0.0",
"version": "1.0.1",
"description": "A responsive screenshot comparison tool. Based on the Ruby version available at http://github.comm/BBC-News/wraith",
"license": "MIT",
"repository": "jamesryanbell/node-wraith",
"repository": {
"type": "git",
"url": "git://github.com/thebyrd/node-wraith"
},
"bin": {
"wraith": "cli.js"
},
Expand Down Expand Up @@ -49,5 +52,17 @@
"mustache": "~0.8.1",
"rimraf": "~2.2.6"
},
"devDependencies": {}
"devDependencies": {},
"readme": "# Wraith\nA responsive screenshot comparison tool.\nBased on the Ruby version available at [http://github.com/BBC-News/wraith](http://github.com/BBC-News/wraith)\n\n## CLI app\n\n### Install\n\n```\n\tnpm install --global wraith\n```\n\n###Usage\n\n\tUsage:\n\twraith --config <config>\n\n\tOptions:\n\t-h, --help\t\tOutput help information\n\t--v, --version\tOutput version information\n\n\tExamples:\n\twraith --config ./config/chrome.json\n\n### Configuration file\n\nWraith uses a json based configuration file that allows you specify a large number of options. You can create as many configurations files as you need and call them from the cli using the --config flag. These configuration files can live anywhere that is addressable by a local path and they are passed as an argument like this:\n\n wraith --config ./path/to/my_config.json\n\nBelow is an example configuration file:\n\n\t{\n\t\t\"project\": \"Test\", (Optional name for the project, if supplied it will be used within the generated gallery only)\n\n\t\tSpecify one or two domains\n\t\t\"domains\": {\n\t\t\t\"bbb.co.uk\": \"http://www.bbc.co.uk\",\n\t\t\t\"live.bbc.co.uk\": \"http://live.bbc.co.uk\"\n\t\t},\n\n\t\tEngines supported are phantomjs, slimerjs and triflejs but in theory any phantomjs based headless browser can be supported via a custom snap.js file\n\t\t\"engines\" : [\n\t\t\t\"phantomjs\"\n\t\t],\n\n\t\tSpecify as many sizes as you wish\n\t\t\"sizes\": [\n\t\t\t\"320\",\n\t\t\t\"768\",\n\t\t\t\"1440\"\n\t\t],\n\n\t\t\"outputDir\": \"test/chrome/\", (defaults to \"shots\")\n\n\t\tYou can choose to specfiy a list of paths to be used or you can crawl the site. If paths are provided they will take precident and the spider file will be ignored.\n\n\t\t\"paths\": [\n\t\t\t\"/\",\n\t\t\t\"/news/\",\n\t\t\t\"/news/local/\",\n\t\t\t\"/news/england/york_and_north_yorkshire/\",\n\t\t\t\"/weather/\"\n\t\t],\n\n\t\tIf no paths are specified then a site crawl will take place and the results will be save in the location specified within this option\n\t\t\"spider\": \"spider/test.txt\", (Specify which file should be used for the spider txt file)\n\n\t\t\"snap\": \"snap/test/chrome.js\", (Specify snap.js which is used to take the screenshots)\n\t\t\"fuzz\": \"20%\", (Adjusts the sensitivity of the image comparison)\n\t\t\"maxConnections\": 20 (Limit the amount of concurrent processes)\n\t}\n\n## External Dependencies\nWraith requires [phantomjs](http://phantomjs.org/) & [imagemagick](http://www.imagemagick.org/) to be installed. On OS X this can easily be done with `npm install phantomjs` and `brew install imagemagick`.\n\n## License\n\nMIT © [James Bell](http://james-bell.co.uk)\n",
"readmeFilename": "readme.md",
"bugs": {
"url": "https://github.com/thebyrd/node-wraith/issues"
},
"homepage": "https://github.com/thebyrd/node-wraith",
"_id": "wraith@1.0.1",
"dist": {
"shasum": "6fe7dcbc35f8d4e3d5df72d796dd500ae8a84591"
},
"_resolved": "git+https://github.com/thebyrd/node-wraith.git#96e70c3c85256859c240b99ffa648ddfec8870c1",
"_from": "wraith@git+https://github.com/thebyrd/node-wraith.git#master"
}
13 changes: 9 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ Based on the Ruby version available at [http://github.com/BBC-News/wraith](http:
--v, --version Output version information

Examples:
wraith --config chrome
wraith --config ./config/chrome.json

### Configuration file

Wraith uses a json based configuration file that allows you specfify a large number of options. You can create as many configurations files as you need and call them from the cli using the --config flag. All congiguration files must be stored within the config folder.
Wraith uses a json based configuration file that allows you specify a large number of options. You can create as many configurations files as you need and call them from the cli using the --config flag. These configuration files can live anywhere that is addressable by a local path and they are passed as an argument like this:

wraith --config ./path/to/my_config.json

Below is an example configuration file:

Expand All @@ -49,7 +51,7 @@ Below is an example configuration file:
"1440"
],

"outputDir": "test/chrome/", (Output directory within the /shots directory)
"outputDir": "test/chrome/", (defaults to "shots")

You can choose to specfiy a list of paths to be used or you can crawl the site. If paths are provided they will take precident and the spider file will be ignored.

Expand All @@ -69,6 +71,9 @@ Below is an example configuration file:
"maxConnections": 20 (Limit the amount of concurrent processes)
}

## External Dependencies
Wraith requires [phantomjs](http://phantomjs.org/) & [imagemagick](http://www.imagemagick.org/) to be installed. On OS X this can easily be done with `npm install phantomjs` and `brew install imagemagick`.

## License

MIT © [James Bell](http://james-bell.co.uk)
MIT © [James Bell](http://james-bell.co.uk)