forked from kucherenko/jscpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.coffee
45 lines (31 loc) · 1.1 KB
/
report.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
fs = require 'fs'
logger = require 'winston'
path = require 'path'
class Report
constructor: (@options) ->
reporter = @options.reporter
ext = @options.output.split('.').pop() if @options.output
if ext is 'xml' and reporter is 'json' or
ext is 'json' and reporter is 'xml'
logger.warn "output file extention '#{@options.output}'
does not match reporter '#{reporter}'"
switch reporter
when 'xml' then reporter = './reporters/xml-pmd'
when 'json' then reporter = './reporters/json'
else
cwd = process.cwd()
reporter = path.normalize reporter
isAbsolute = reporter.indexOf(cwd) is 0
reporter = path.join(cwd, reporter) unless isAbsolute
@reporter = require reporter
@stdReporter = require './reporters/_std-log'
generate: (@map) ->
[raw, dump, log] = @reporter @options
log = @stdReporter() unless log
logger.info log
if @options.output
fs.writeFileSync(@options.output, dump or raw)
else
logger.warn 'output file is not provided'
return raw or dump
exports.Report = Report