From dcd5a994cbd6de4c317edd22104701e1250b493f Mon Sep 17 00:00:00 2001 From: Joe Pettersson Date: Wed, 16 Jul 2014 11:44:42 +0100 Subject: [PATCH 1/8] Remove implicit config folder structure Remove the need for an implicit config folder structure (which is badly documented, in the original Wraith Ruby project as well). Now you pass a full relative path e.g. `./config/my_config.json` --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7c309f6..3fa8837 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ function run(configFile) { outputFolder = '', baseFolder = process.cwd() + '/'; - var config = require(baseFolder + 'config/' + configFile + '.json'); + var config = require(baseFolder + configFile); outputFolder = typeof config.outputDir === 'undefined' ? baseFolder + 'shots/' : baseFolder + 'shots/' + config.outputDir; @@ -52,4 +52,4 @@ function run(configFile) { wraith(config, config.engines, domains, config.sizes, domainLabels, outputFolder, cb); } } -} \ No newline at end of file +} From e45109ace695d3ffb2d7fd1448b3440cf34a2526 Mon Sep 17 00:00:00 2001 From: Joe Pettersson Date: Wed, 16 Jul 2014 11:47:39 +0100 Subject: [PATCH 2/8] Update README.md to reflect new config changes --- readme.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index ef407cd..fe9196b 100644 --- a/readme.md +++ b/readme.md @@ -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 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. 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: @@ -71,4 +73,4 @@ Below is an example configuration file: ## License -MIT © [James Bell](http://james-bell.co.uk) \ No newline at end of file +MIT © [James Bell](http://james-bell.co.uk) From 124bad7fae57864769a9b512104b3de19b7ec8ef Mon Sep 17 00:00:00 2001 From: David Byrd Date: Tue, 26 Aug 2014 11:10:04 -0400 Subject: [PATCH 3/8] ability to specify output directory --- index.js | 5 +++-- lib/gallery.js | 5 +++-- package.json | 4 ++-- readme.md | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 3fa8837..374f34a 100644 --- a/index.js +++ b/index.js @@ -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; @@ -15,7 +16,7 @@ function run(configFile) { var config = require(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(/\/+$/, '')); diff --git a/lib/gallery.js b/lib/gallery.js index aa4cdb9..75bc7f9 100644 --- a/lib/gallery.js +++ b/lib/gallery.js @@ -3,6 +3,7 @@ var fs = require('fs'); var helpers = require('./helpers'); var mustache = require('mustache'); +var path = require('path') module.exports.generate = generate; @@ -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 { @@ -40,4 +41,4 @@ function generate(dirs, compareList, outputDir, project, cb) { } }); }); -} \ No newline at end of file +} diff --git a/package.json b/package.json index 998b66a..3258a70 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "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": "thebyrd/node-wraith", "bin": { "wraith": "cli.js" }, diff --git a/readme.md b/readme.md index fe9196b..db6ab56 100644 --- a/readme.md +++ b/readme.md @@ -24,7 +24,7 @@ Based on the Ruby version available at [http://github.com/BBC-News/wraith](http: ### 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. These configuration files can live anywhere that is addressable by a local path and they are passed as an argument like this: +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 @@ -51,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. From 5fa34178df6defc1bf8252d261e4a76d44dcfa69 Mon Sep 17 00:00:00 2001 From: David Byrd Date: Tue, 26 Aug 2014 11:34:05 -0400 Subject: [PATCH 4/8] updated README --- readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.md b/readme.md index db6ab56..a464712 100644 --- a/readme.md +++ b/readme.md @@ -71,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) From 38ca44c1539150194c5521c4d9e61e8bbba474e8 Mon Sep 17 00:00:00 2001 From: David Byrd Date: Tue, 26 Aug 2014 14:53:45 -0400 Subject: [PATCH 5/8] got it working --- cli.js | 0 index.js | 5 +++-- lib/gallery.js | 4 +++- lib/wraith.js | 13 ++++++++----- package.json | 19 +++++++++++++++++-- 5 files changed, 31 insertions(+), 10 deletions(-) mode change 100644 => 100755 cli.js diff --git a/cli.js b/cli.js old mode 100644 new mode 100755 diff --git a/index.js b/index.js index 374f34a..03e04b4 100644 --- a/index.js +++ b/index.js @@ -14,10 +14,11 @@ function run(configFile) { outputFolder = '', baseFolder = process.cwd() + '/'; - var config = require(baseFolder + configFile); + var config = require(path.join(baseFolder, configFile)); - outputFolder = path.join(baseFolder, config.outputDir || 'shots/'); + outputFolder = path.join(baseFolder, config.outputDir || 'shots/'); + console.log('$$$$5', outputFolder, baseFolder, config.outputDir) for(var domain in config.domains) { domains.push(config.domains[domain].replace(/\/+$/, '')); domainLabels.push(domain); diff --git a/lib/gallery.js b/lib/gallery.js index 75bc7f9..a10ea01 100644 --- a/lib/gallery.js +++ b/lib/gallery.js @@ -9,7 +9,7 @@ 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(), @@ -29,9 +29,11 @@ function generate(dirs, compareList, outputDir, project, cb) { } }; + console.log('read tmpl') fs.readFile(template, function (err, data) { if (err) { throw err; } var output = mustache.render(data.toString(), view); + console.log('write out', path.join(outputDir, 'gallery.html')) fs.writeFile(path.join(outputDir, 'gallery.html'), output, function(err) { if(err) { console.log(err); diff --git a/lib/wraith.js b/lib/wraith.js index f583bcc..fa1fedf 100644 --- a/lib/wraith.js +++ b/lib/wraith.js @@ -1,6 +1,7 @@ 'use strict'; var fs = require('fs'), + path = require('path'), async = require('async'), mkdirp = require('mkdirp'), gallery = require('./gallery'), @@ -30,6 +31,7 @@ function wraith(config, engines, domains, sizes, domainLabels, outputFolder, cb) console.log('Cleaned up old folders and files'); var foldersQueue = async.queue(function(folder, callback) { + console.log('$$$1folder', folder) mkdirp(folder, function (err) { if (err) { throw err; } callback(); @@ -37,7 +39,8 @@ 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(/\/+$/,'') + '/'); + console.log('$$$$2', folder, outputFolder) foldersQueue.push(folder); dirs.push(folder); } @@ -55,7 +58,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({ @@ -72,7 +75,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({ @@ -105,7 +108,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), @@ -133,4 +136,4 @@ function wraith(config, engines, domains, sizes, domainLabels, outputFolder, cb) console.log('No url(s) provided'); return false; } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 3258a70..4ddb29c 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,10 @@ "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": "thebyrd/node-wraith", + "repository": { + "type": "git", + "url": "git://github.com/thebyrd/node-wraith" + }, "bin": { "wraith": "cli.js" }, @@ -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 \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" } From 3afded4af1f7b09660fab043dc2337a09fea2af1 Mon Sep 17 00:00:00 2001 From: David Byrd Date: Tue, 26 Aug 2014 14:56:30 -0400 Subject: [PATCH 6/8] added .gitignore and remove debug --- .gitignore | 2 ++ index.js | 1 - lib/wraith.js | 2 -- 3 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d9308f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +bbc diff --git a/index.js b/index.js index 03e04b4..9e10c02 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,6 @@ function run(configFile) { outputFolder = path.join(baseFolder, config.outputDir || 'shots/'); - console.log('$$$$5', outputFolder, baseFolder, config.outputDir) for(var domain in config.domains) { domains.push(config.domains[domain].replace(/\/+$/, '')); domainLabels.push(domain); diff --git a/lib/wraith.js b/lib/wraith.js index fa1fedf..f518586 100644 --- a/lib/wraith.js +++ b/lib/wraith.js @@ -31,7 +31,6 @@ function wraith(config, engines, domains, sizes, domainLabels, outputFolder, cb) console.log('Cleaned up old folders and files'); var foldersQueue = async.queue(function(folder, callback) { - console.log('$$$1folder', folder) mkdirp(folder, function (err) { if (err) { throw err; } callback(); @@ -40,7 +39,6 @@ function wraith(config, engines, domains, sizes, domainLabels, outputFolder, cb) for(var url in urls) { folder = path.join(outputFolder, urls[url].substring(1).replace(/\/+$/,'') + '/'); - console.log('$$$$2', folder, outputFolder) foldersQueue.push(folder); dirs.push(folder); } From c826ff3f5ba228ba1838736ccfba80254758ff33 Mon Sep 17 00:00:00 2001 From: David Byrd Date: Tue, 26 Aug 2014 14:58:43 -0400 Subject: [PATCH 7/8] change example from bbc to google --- .gitignore | 2 +- config/chrome.json | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index d9308f4..f05b1f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ node_modules -bbc +test diff --git a/config/chrome.json b/config/chrome.json index 22c20a4..0cbf831 100644 --- a/config/chrome.json +++ b/config/chrome.json @@ -1,25 +1,21 @@ { "project": "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 -} \ No newline at end of file +} From 64f83e6347d0d3d3d66ad40be836cc0c65ce07bb Mon Sep 17 00:00:00 2001 From: David Byrd Date: Tue, 26 Aug 2014 14:59:30 -0400 Subject: [PATCH 8/8] remove debug --- config/chrome.json | 2 +- lib/gallery.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/config/chrome.json b/config/chrome.json index 0cbf831..66478af 100644 --- a/config/chrome.json +++ b/config/chrome.json @@ -1,5 +1,5 @@ { - "project": "Test", + "project": "Google Test", "domains": { "usa": "http://www.google.com", "canada": "http://www.google.ca" diff --git a/lib/gallery.js b/lib/gallery.js index a10ea01..2510c22 100644 --- a/lib/gallery.js +++ b/lib/gallery.js @@ -29,11 +29,9 @@ function generate(dirs, compareList, outputDir, project, cb) { } }; - console.log('read tmpl') fs.readFile(template, function (err, data) { if (err) { throw err; } var output = mustache.render(data.toString(), view); - console.log('write out', path.join(outputDir, 'gallery.html')) fs.writeFile(path.join(outputDir, 'gallery.html'), output, function(err) { if(err) { console.log(err);