Commit 8364ad8c by Andrew Nesbitt

Fixed some jshint warnings and errors

parent 49a0c0a9
......@@ -35,8 +35,8 @@ var optimist = require('optimist')
alias: 'help'
})
.check(function(argv){
if (argv.help) return true;
if (argv._.length < 1) return false;
if (argv.help) { return true; }
if (argv._.length < 1) { return false; }
});
// throttle function, used so when multiple files change at the same time
......
var sass = require('../sass')
, fs = require('fs')
, url = require('url')
, basename = require('path').basename
, dirname = require('path').dirname
, mkdirp = require('mkdirp')
, join = require('path').join;
var sass = require('../sass'),
fs = require('fs'),
url = require('url'),
dirname = require('path').dirname,
mkdirp = require('mkdirp'),
join = require('path').join;
var imports = {};
......@@ -57,7 +56,7 @@ module.exports = function(options){
// Source dir required
var src = options.src;
if (!src) throw new Error('sass.middleware() requires "src" directory');
if (!src) { throw new Error('sass.middleware() requires "src" directory'); }
// Default dest dir to source
var dest = options.dest
......@@ -68,20 +67,20 @@ module.exports = function(options){
// Default compile callback
options.compile = options.compile || function(){
return sass
return sass;
};
// Middleware
return function sass(req, res, next){
if ('GET' != req.method && 'HEAD' != req.method) return next();
if ('GET' != req.method && 'HEAD' != req.method) { return next(); }
var path = url.parse(req.url).pathname;
if (options.prefix && 0 === path.indexOf(options.prefix)) {
path = path.substring(options.prefix.length);
}
if (/\.css$/.test(path)) {
var cssPath = join(dest, path)
, sassPath = join(src, path.replace('.css', '.scss'))
, sassDir = dirname(sassPath);
var cssPath = join(dest, path),
sassPath = join(src, path.replace('.css', '.scss')),
sassDir = dirname(sassPath);
if (root) {
cssPath = join(root, dest, path.replace(dest, ''));
......@@ -97,29 +96,29 @@ module.exports = function(options){
}
// Ignore ENOENT to fall through as 404
function error(err) {
var error = function(err) {
next('ENOENT' == err.code
? null
: err);
}
};
// Force
if (force) return compile();
if (force) { return compile(); }
// Compile to cssPath
function compile() {
if (debug) log('read', cssPath);
var compile = function() {
if (debug) { log('read', cssPath); }
fs.readFile(sassPath, 'utf8', function(err, str){
if (err) return error(err);
if (err) { return error(err); }
var style = options.compile();
var paths = [];
delete imports[sassPath];
style.render(str, function(err, css){
if (err) return next(err);
if (debug) log('render', sassPath);
if (err) { return next(err); }
if (debug) { log('render', sassPath); }
imports[sassPath] = paths;
mkdirp(dirname(cssPath), 0700, function(err){
if (err) return error(err);
if (err) { return error(err); }
fs.writeFile(cssPath, css, 'utf8', next);
});
}, {
......@@ -127,20 +126,20 @@ module.exports = function(options){
output_style: options.output_style || options.outputStyle
});
});
}
};
// Re-compile on server restart, disregarding
// mtimes since we need to map imports
if (!imports[sassPath]) return compile();
if (!imports[sassPath]) { return compile(); }
// Compare mtimes
fs.stat(sassPath, function(err, sassStats){
if (err) return error(err);
if (err) { return error(err); }
fs.stat(cssPath, function(err, cssStats){
// CSS has not been compiled, compile it!
if (err) {
if ('ENOENT' == err.code) {
if (debug) log('not found', cssPath);
if (debug) { log('not found', cssPath); }
compile();
} else {
next(err);
......@@ -148,7 +147,7 @@ module.exports = function(options){
} else {
// Source has changed, compile it
if (sassStats.mtime > cssStats.mtime) {
if (debug) log('modified', cssPath);
if (debug) { log('modified', cssPath); }
compile();
// Already compiled, check imports
} else {
......@@ -167,7 +166,7 @@ module.exports = function(options){
} else {
next();
}
}
};
};
/**
......@@ -180,11 +179,11 @@ module.exports = function(options){
function checkImports(path, fn) {
var nodes = imports[path];
if (!nodes) return fn();
if (!nodes.length) return fn();
if (!nodes) { return fn(); }
if (!nodes.length) { return fn(); }
var pending = nodes.length
, changed = [];
var pending = nodes.length,
changed = [];
nodes.forEach(function(imported){
fs.stat(imported.path, function(err, stat){
......
var sass = require('../sass'),
colors = require('colors'),
fs = require('fs');
var cwd = process.cwd();
function render(options, emitter) {
sass.render({
......@@ -17,7 +14,7 @@ function render(options, emitter) {
emitter.emit('warn', 'Rendering Complete, saving .css file...'.green);
fs.writeFile(options.outFile, css, function(err) {
if (err) return emitter.emit('error', ('Error: ' + err).red);
if (err) { return emitter.emit('error', ('Error: ' + err).red); }
emitter.emit('warn', ('Wrote CSS to ' + options.outFile).green);
emitter.emit('write', err, options.outFile, css);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment