Comparing version 0.0.3 to 0.0.4
@@ -7,3 +7,3 @@ var fs = require('fs-extra'), | ||
function normalize(name) { | ||
return name.replace(/[^\w_-]+/g, '_'); | ||
return name.replace(/[^\w()._-]+/g, '_'); | ||
} | ||
@@ -55,13 +55,18 @@ | ||
var loadImage = gm.subClass({ imageMagick: !options.gm }); | ||
var filepath = path.join(options.path, fixedName); | ||
var image = new Buffer(imageData, 'base64'); | ||
var ref = path.join(filepath, '_ref.png'); | ||
if (options.ref && !fs.existsSync(ref)) { | ||
console.log('===> Missing reference ' + ref); | ||
return done(); | ||
} | ||
var loadImage = gm.subClass({ imageMagick: !options.gm }); | ||
var indexedImages = initializeCache(filepath, fixedName); | ||
var imageChunk = path.join(filepath, 'ref_' + indexedImages.src.length + '.png'); | ||
var imageChunk = path.join(filepath, 'ref.' + indexedImages.src.length + '.png'); | ||
fs.outputFileSync(imageChunk, image); | ||
fs.outputFileSync(imageChunk, new Buffer(imageData, 'base64')); | ||
@@ -108,9 +113,9 @@ var shot = loadImage(imageChunk).quality(100); | ||
if (cache && ((cache.src.length > 1) || options.ref)) { | ||
var a = options.ref ? '_ref' : ('ref_' + (cache.src.length - 2)), | ||
var a = options.ref ? '_ref' : (cache.src.length - 2), | ||
b = cache.src.length - 1; | ||
return { | ||
latest: path.join(cache.filepath, a + '.png'), | ||
current: path.join(cache.filepath, 'ref_' + b + '.png'), | ||
filepathDiff: path.join(cache.filepath, 'ref_' + a + '_' + b + '.png') | ||
latest: path.join(cache.filepath, (options.ref ? a : ('ref.' + a)) + '.png'), | ||
current: path.join(cache.filepath, 'ref.' + b + '.png'), | ||
filepathDiff: path.join(cache.filepath, 'ref.' + a + '_' + b + '.png') | ||
}; | ||
@@ -136,6 +141,17 @@ } | ||
if (!(diffImages && fs.existsSync(diffImages.latest) && fs.existsSync(diffImages.current))) { | ||
if (!diffImages) { | ||
console.log('===> Missing references, initializing...'); | ||
return cb(); | ||
} | ||
if (!fs.existsSync(diffImages.latest)) { | ||
console.log('===> Missing latest reference ' + diffImages.latest); | ||
return cb(); | ||
} | ||
if (!fs.existsSync(diffImages.current)) { | ||
console.log('===> Missing current reference ' + diffImages.current); | ||
return cb(); | ||
} | ||
resemble(diffImages.current) | ||
@@ -142,0 +158,0 @@ .compareTo(diffImages.latest) |
{ | ||
"name": "dayguard", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
5308
140