Skip to content

Commit

Permalink
Merge pull request #36 from selaux/overhaul-test-system
Browse files Browse the repository at this point in the history
Overhaul test system
  • Loading branch information
selaux committed Jun 4, 2015
2 parents f105bd5 + d1503cd commit 1d6ecc8
Show file tree
Hide file tree
Showing 35 changed files with 179 additions and 229 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/**
.idea/**
build/**
24 changes: 24 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"env": {
"node": true
},
"rules": {
"quotes": [2, "single"],
"no-warning-comments": [2, { "terms": ["todo", "fixme", "wtf"], "location": "anywhere" }],
"strict": 2,
"no-process-exit": 2,
"eqeqeq": 2,
"no-delete-var": 2,
"one-var": 2,
"max-params": [2, 4],
"no-plusplus": 2,
"semi": [2, "always"],
"no-mixed-requires": 0,
"valid-jsdoc": 0,
"wrap-iife": [2, "outside"],
"no-new-require": 2,
"no-catch-shadow": 2,
"dot-notation": 0,
"max-params": [2, 5]
}
}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
node-sprite-generator.iml
node_modules/*
**/.DS_Store
coverage.html
coverage.lcov
build/*
6 changes: 6 additions & 0 deletions .istanbul.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
reporting:
print: summary
reports:
- lcov
- html
dir: ./build/coverage
6 changes: 5 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
build/
node_modules/
.git*
npm-debug.log
test/
.travis.yml
.*rc
.*.yml
.*ignore
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: node_js
node_js:
- "iojs"
- "0.12"
- "0.10"
before_install:
- sudo apt-get update
Expand Down
74 changes: 0 additions & 74 deletions Gruntfile.js

This file was deleted.

12 changes: 6 additions & 6 deletions lib/compositor/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ function renderSprite(layout, filePath, options, callback) {
});

// store canvas to file
canvas.toBuffer(function (err, buffer) {
if (err) {
return callback(err);
canvas.toBuffer(function (bufferError, buffer) {
if (bufferError) {
return callback(bufferError);
}

fs.writeFile(filePath, buffer, function (err) {
callback(err);
fs.writeFile(filePath, buffer, function (writeError) {
callback(writeError);
});
}, options.compressionLevel, filterToParam(options.filter, canvas));
}
Expand All @@ -83,4 +83,4 @@ module.exports = {
readImages: readImages,
render: renderSprite,
filterToParam: filterToParam
};
};
18 changes: 9 additions & 9 deletions lib/compositor/gm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ var _ = require('underscore'),
all: 9
};

function readImage(path, callback) {
fs.readFile(path, function (err, data) {
if (err) {
return callback(err);
function readImage(filePath, callback) {
fs.readFile(filePath, function (readError, data) {
if (readError) {
return callback(readError);
}

gm(data).size(function (err, size) {
if (err) {
return callback(err);
gm(data).size(function (sizeError, size) {
if (sizeError) {
return callback(sizeError);
}
callback(null, {
path: path,
path: filePath,
width: size.width,
height: size.height,
data: data
Expand Down Expand Up @@ -74,4 +74,4 @@ module.exports = {
readImages: readImages,
render: renderSprite,
filterToQuality: filterToQuality
};
};
30 changes: 14 additions & 16 deletions lib/nsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

var async = require('async'),
glob = require('glob'),
path = require('path'),
fs = require('fs'),
_ = require('underscore'),
changeDetector = require('./utils/changeDetector'),
providedLayouts = {
Expand Down Expand Up @@ -63,33 +61,33 @@ function generateSprite(options, callback) {
}

// do glob pattern matching
async.map(options.src, glob, function (err, fileNames) {
if (err) {
callback(err);
async.map(options.src, glob, function (globError, fileNames) {
if (globError) {
callback(globError);
return;
}

// filter duplicates from glob pattern matching
fileNames = _(fileNames).chain().flatten().uniq().value();

async.waterfall([
function (callback) {
compositor.readImages(fileNames, callback);
function (cb) {
compositor.readImages(fileNames, cb);
},
function (images, callback) {
layout(images, options.layoutOptions, callback);
function (images, cb) {
layout(images, options.layoutOptions, cb);
},
function (newLayout, callback) {
function (newLayout, cb) {
// store layout so it can be used for stylesheet generation
generatedLayout = newLayout;
compositor.render(generatedLayout, options.spritePath, options.compositorOptions, callback);
compositor.render(generatedLayout, options.spritePath, options.compositorOptions, cb);
},
function (callback) {
stylesheet(generatedLayout, options.stylesheetPath, options.spritePath, options.stylesheetOptions, callback);
function (cb) {
stylesheet(generatedLayout, options.stylesheetPath, options.spritePath, options.stylesheetOptions, cb);
}
], function (err) {
], function (pipelineError) {
if (callback) {
callback(err);
callback(pipelineError);
}
});
});
Expand All @@ -113,4 +111,4 @@ generateSprite.middleware = function (options) {
};
};

module.exports = generateSprite;
module.exports = generateSprite;
2 changes: 1 addition & 1 deletion lib/stylesheet/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
var getTemplatedStylesheet = require('./templatedStylesheet'),
path = require('path');

module.exports = getTemplatedStylesheet(path.join(__dirname + '/templates/css.tpl'));
module.exports = getTemplatedStylesheet(path.join(__dirname, '/templates/css.tpl'));
2 changes: 1 addition & 1 deletion lib/stylesheet/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
var getTemplatedStylesheet = require('./templatedStylesheet'),
path = require('path');

module.exports = getTemplatedStylesheet(path.join(__dirname + '/templates/less.tpl'));
module.exports = getTemplatedStylesheet(path.join(__dirname, '/templates/less.tpl'));
6 changes: 3 additions & 3 deletions lib/stylesheet/prefixed-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var _ = require('underscore'),
getTemplatedStylesheet = require('./templatedStylesheet'),
path = require('path'),
generateSpriteSheet = getTemplatedStylesheet(path.join(__dirname + '/templates/prefixed-css.tpl'));
generateSpriteSheet = getTemplatedStylesheet(path.join(__dirname, '/templates/prefixed-css.tpl'));

module.exports = function(layout, filePath, spritePath, options, callback) {
var localOptions = _.clone(options);
Expand All @@ -12,8 +12,8 @@ module.exports = function(layout, filePath, spritePath, options, callback) {
localOptions.commonHeight = layout.images[0].height;

layout.images.every(function(image) {
if (image.width != localOptions.commonWidth ||
image.height != localOptions.commonHeight)
if (image.width !== localOptions.commonWidth ||
image.height !== localOptions.commonHeight)
{
localOptions.commonWidth = localOptions.commonHeight = false;
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/stylesheet/sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
var getTemplatedStylesheet = require('./templatedStylesheet'),
path = require('path');

module.exports = getTemplatedStylesheet(path.join(__dirname + '/templates/sass.tpl'));
module.exports = getTemplatedStylesheet(path.join(__dirname, '/templates/sass.tpl'));
2 changes: 1 addition & 1 deletion lib/stylesheet/scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
var getTemplatedStylesheet = require('./templatedStylesheet'),
path = require('path');

module.exports = getTemplatedStylesheet(path.join(__dirname + '/templates/scss.tpl'));
module.exports = getTemplatedStylesheet(path.join(__dirname, '/templates/scss.tpl'));
2 changes: 1 addition & 1 deletion lib/stylesheet/stylus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
var getTemplatedStylesheet = require('./templatedStylesheet'),
path = require('path');

module.exports = getTemplatedStylesheet(path.join(__dirname + '/templates/stylus.tpl'));
module.exports = getTemplatedStylesheet(path.join(__dirname, '/templates/stylus.tpl'));
9 changes: 4 additions & 5 deletions lib/stylesheet/templatedStylesheet.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use strict';

var path = require('path'),
fs = require('fs'),
var fs = require('fs'),
utils = require('../utils/stylesheet'),
_ = require('underscore');

module.exports = function getTemplatedStylesheet(path) {
var template = _.template(fs.readFileSync(path).toString());
module.exports = function getTemplatedStylesheet(templatePath) {
var template = _.template(fs.readFileSync(templatePath).toString());

return function generateSpritesheet(layout, filePath, spritePath, options, callback) {
var scaledLayout,
Expand Down Expand Up @@ -35,4 +34,4 @@ module.exports = function getTemplatedStylesheet(path) {
layout: scaledLayout
}), callback);
};
};
};
23 changes: 12 additions & 11 deletions lib/utils/changeDetector.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,35 @@ var fs = require('fs'),
_ = require('underscore');

function stat(path, callback) {
fs.stat(path, function (err, stat) {
fs.stat(path, function (err, fileStat) {
if (err) {
if (err.code === 'ENOENT') {
return callback(null, null);
}
return callback(err);
}
return callback(null, stat);
return callback(null, fileStat);
});
}

function generateTimestamps(patterns, callback) {
var timestamps = {};

async.map(patterns, glob, function (err, fileNames) {
if (err) {
return callback(err);
async.map(patterns, glob, function (globErr, fileNames) {
if (globErr) {
return callback(globErr);
}

fileNames = _(fileNames).chain().flatten().uniq().value();

async.map(fileNames, stat, function (err, stats) {
if (err) {
return callback(err);
async.map(fileNames, stat, function (statError, stats) {
if (statError) {
return callback(statError);
}

_(stats).each(function (stat, it) {
timestamps[fileNames[it]] = stat ? stat.mtime.getTime() : null;
_(stats).each(function (fStat, it) {
var timestamp = fStat ? fStat.mtime.getTime() : null;
timestamps[fileNames[it]] = timestamp;
});

callback(null, timestamps);
Expand Down Expand Up @@ -68,4 +69,4 @@ module.exports = function (options) {
});
}
};
};
};
2 changes: 1 addition & 1 deletion lib/utils/stylesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ module.exports = {

return relativePath;
}
};
};
Loading

0 comments on commit 1d6ecc8

Please sign in to comment.