diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f05b1f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +test diff --git a/cli.js b/cli.js old mode 100644 new mode 100755 diff --git a/config/chrome.json b/config/chrome.json index 22c20a4..66478af 100644 --- a/config/chrome.json +++ b/config/chrome.json @@ -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 -} \ No newline at end of file +} diff --git a/index.js b/index.js index 7c309f6..9e10c02 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; @@ -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); @@ -52,4 +53,4 @@ function run(configFile) { wraith(config, config.engines, domains, config.sizes, domainLabels, outputFolder, cb); } } -} \ No newline at end of file +} diff --git a/lib/gallery.js b/lib/gallery.js index aa4cdb9..2510c22 100644 --- a/lib/gallery.js +++ b/lib/gallery.js @@ -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(), @@ -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/lib/wraith.js b/lib/wraith.js index f583bcc..f518586 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'), @@ -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); } @@ -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({ @@ -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({ @@ -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), @@ -133,4 +134,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 998b66a..4ddb29c 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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" } diff --git a/readme.md b/readme.md index ef407cd..a464712 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 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: @@ -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. @@ -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) \ No newline at end of file +MIT © [James Bell](http://james-bell.co.uk)