forked from JacksonTian/modulelint
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8c7004
commit bacd04a
Showing
3 changed files
with
55 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,46 @@ | ||
var folder = require('./items/folder.js'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var EventProxy = require('eventproxy'); | ||
|
||
exports.loadChecklist = function () { | ||
var checklist = []; | ||
// the acutal commands. read them dynamicaly | ||
var files = fs.readdirSync(path.join(__dirname, 'checklist')); | ||
|
||
for(var i = 0, ii = files.length; i < ii; i++) { | ||
if (path.extname(files[i]) === ".js") { | ||
var name = path.basename(files[i], '.js'); | ||
var checker = require(path.join(__dirname, 'checklist', files[i])); | ||
checker.name = name; | ||
checklist.push(checker); | ||
} | ||
} | ||
return checklist; | ||
}; | ||
|
||
/** | ||
* In me the tiger sniffe the rose | ||
*/ | ||
exports.sniffe = function (source, callback) { | ||
folder.check(source, callback); | ||
var checklist = exports.loadChecklist(); | ||
var proxy = new EventProxy(); | ||
var length = checklist.length; | ||
|
||
proxy.after('checked', length, function (results) { | ||
callback(null, results); | ||
}); | ||
proxy.on('error', function (err) { | ||
proxy.unbind(); | ||
callback(err); | ||
}); | ||
checklist.forEach(function (checker) { | ||
checker.check(source, function (err, result) { | ||
if (err) { | ||
proxy.fire('error', err); | ||
return; | ||
} | ||
result.name = checker.name; | ||
proxy.fire('checked', result); | ||
}); | ||
}); | ||
}; |