-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
Showing
1 changed file
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var path = require('path'); | ||
var events = require('events'); | ||
var glob = require('glob'); | ||
|
||
var mapFormatters; | ||
var arrSupportedFormatters; | ||
var HTMLHint; | ||
var options; | ||
|
||
// load formatters | ||
mapFormatters = loadFormatters(); | ||
arrSupportedFormatters = []; | ||
for(var formatterName in mapFormatters){ | ||
if(formatterName !== 'default'){ | ||
arrSupportedFormatters.push(formatterName); | ||
} | ||
} | ||
|
||
// load all formatters | ||
function loadFormatters(){ | ||
var arrFiles = glob.sync('./formatters/*.js', { | ||
'cwd': __dirname, | ||
'dot': false, | ||
'nodir': true, | ||
'strict': false, | ||
'silent': true | ||
}); | ||
var mapFormatters = {}; | ||
arrFiles.forEach(function(file){ | ||
var fileInfo = path.parse(file); | ||
var formatterPath = path.resolve(__dirname, file); | ||
mapFormatters[fileInfo.name] = require(formatterPath); | ||
}); | ||
return mapFormatters; | ||
} | ||
|
||
var formatter =new events.EventEmitter(); | ||
formatter.getSupported = function(){ | ||
return arrSupportedFormatters; | ||
} | ||
formatter.init = function(tmpHTMLHint, tmpOptions){ | ||
HTMLHint = tmpHTMLHint; | ||
options = tmpOptions; | ||
} | ||
formatter.setFormat = function(format){ | ||
var formatHandel = mapFormatters[format]; | ||
if(formatHandel === undefined){ | ||
console.log('No supported formatter, supported formatters: %s'.red, arrSupportedFormatters.join(', ')); | ||
process.exit(1); | ||
} | ||
else{ | ||
formatHandel(formatter, HTMLHint, options) | ||
} | ||
} | ||
|
||
module.exports = formatter; |