Comparing version 0.0.11 to 0.0.12
62
index.js
'use strict'; | ||
var _ = require('lodash'); | ||
var q = require('q'); | ||
var glob = require('glob'); | ||
var shell = require('shelljs/global'); | ||
var async = require('async'); | ||
var cache = require('./cache'); | ||
var stdout = false; | ||
var linter = require('./lib/linter'); | ||
var processPatterns = require('./lib/process'); | ||
var linter = function (file, cb) { | ||
cache.has(file, function(err, isCached, hash) { | ||
if (err) return cb(err); | ||
if (isCached) { | ||
if (stdout) { | ||
cache.get(hash, function (err, cached) { | ||
process.stdout.write(cached.contents); | ||
}); | ||
} | ||
return cb(); | ||
} | ||
exec('php -l '+file, {silent: ! stdout}, function (code, output) { | ||
var err = (code === 0) ? null : output.trim(); | ||
if (err) return cb(err); | ||
cache.put(hash, output, cb); | ||
}); | ||
}); | ||
}; | ||
var processPatterns = function (patterns) { | ||
var result = []; | ||
if (_.isString(patterns)) { | ||
patterns = [patterns]; | ||
} | ||
_.each(patterns, function (pattern) { | ||
var exclusion = pattern.indexOf('!') === 0; | ||
if (exclusion) { | ||
pattern = pattern.slice(1); | ||
} | ||
var matches = glob.sync(pattern); | ||
if (exclusion) { | ||
result = _.difference(result, matches); | ||
} else { | ||
result = _.union(result, matches); | ||
} | ||
}); | ||
return result; | ||
}; | ||
module.exports = function (patterns, options) { | ||
@@ -68,5 +16,7 @@ var deferred = q.defer(); | ||
var limit = options.limit ? options.limit : 10; | ||
stdout = options.stdout ? options.stdout : false; | ||
var stdout = options.stdout ? options.stdout : false; | ||
async.eachLimit(result, limit, linter, function (err) { | ||
async.eachLimit(result, limit, function (file, cb) { | ||
linter(file, {stdout: stdout}, cb); | ||
}, function (err) { | ||
if (err) return deferred.reject(new Error(err.trim())); | ||
@@ -73,0 +23,0 @@ |
{ | ||
"name": "phplint", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "wrapper for php -l", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,3 +23,3 @@ 'use strict'; | ||
it('should call the then method', function (cb) { | ||
var lint = phplint('test/pass.php', {stdout: true}); | ||
var lint = phplint('test/pass.php'); | ||
lint.then(function (msg) { | ||
@@ -26,0 +26,0 @@ cb(); |
6169
13
116