@@ -8,6 +8,12 @@ var yargs = require('./yargs');
88
99var defaultReporterName = 'angularity-jshint-reporter' ;
1010
11+ /**
12+ * Cached copy of the reporter
13+ * @type {function }
14+ */
15+ var jsHintReporter ;
16+
1117/**
1218 * Dynamically load a JsHint reporter
1319 *
@@ -22,46 +28,44 @@ var defaultReporterName = 'angularity-jshint-reporter';
2228 * - The absolute path to a node package
2329 * @return {function } The `required`ed jshint report, ready to be piped a gulp stream
2430 */
25- var jsHintReporter ;
2631function getJsHintReporter ( reporterName ) {
2732 if ( typeof reporterName !== 'string' ) {
2833 throw 'Get JsHint Reporter: Reporter name is unspecified' ;
2934 }
30- if ( jsHintReporter ) {
31- return jsHintReporter ; //cached copy
32- }
3335
34- if ( reporterName === defaultReporterName ) {
35- jsHintReporter = require ( defaultReporterName ) ;
36- }
37- else {
38- var reporterPath = ( path . dirname ( reporterName ) === '.' ) ?
39- path . resolve ( 'node_modules' , reporterName ) :
40- reporterName ;
41- try {
42- jsHintReporter = require ( reporterPath ) ;
43- if ( typeof jsHintReporter === 'string' ) {
44- //In JsHint convention, the `index.js` file exports a string which jshint itself should require
45- //e.g. `module.exports = require('path').join(__dirname, 'reporter.js');`
46- jsHintReporter = gulpJshint . reporter ( require ( jsHintReporter ) ) ;
36+ // establish a cached copy
37+ if ( ! jsHintReporter ) {
38+ if ( reporterName === defaultReporterName ) {
39+ jsHintReporter = require ( defaultReporterName ) ;
40+ } else {
41+ var reporterPath = ( path . dirname ( reporterName ) === '.' ) ?
42+ path . resolve ( 'node_modules' , reporterName ) :
43+ reporterName ;
44+ try {
45+ jsHintReporter = require ( reporterPath ) ;
46+ if ( typeof jsHintReporter === 'string' ) {
47+ //In JsHint convention, the `index.js` file exports a string which jshint itself should require
48+ //e.g. `module.exports = require('path').join(__dirname, 'reporter.js');`
49+ jsHintReporter = gulpJshint . reporter ( require ( jsHintReporter ) ) ;
50+ }
51+ } catch ( ex ) {
52+ throw 'Get JsHint Reporter: Attempt to require reporter from path ' + reporterPath + ' with no success.' ;
4753 }
4854 }
49- catch ( ex ) {
50- throw 'Get JsHint Reporter: Attempt to require reporter from path ' + reporterPath + ' with no success.' ;
51- }
5255 }
5356
57+ // return cached copy
5458 return jsHintReporter ;
5559}
5660
5761var yargsOptionDefiniton = {
5862 key : 'reporter' ,
5963 value : {
60- describe : 'Specify a custom JsHint reporter to use. ' +
61- 'Either a locally npm installed module, or an asolute path to one.' ,
64+ describe : 'Specify a custom JsHint reporter to use. Either a locally npm installed module, or the absolute path ' +
65+ 'to one.' ,
6266 alias : [ 'r' ] ,
6367 default : defaultReporterName ,
64- string : true ,
68+ string : true
6569 }
6670} ;
6771var checkJsHintReporter = yargs . createCheck ( )
@@ -77,15 +81,15 @@ var checkJsHintReporter = yargs.createCheck()
7781 getJsHintReporter ( value ) ;
7882 }
7983 catch ( ex ) {
80- return 'Illegal value for "reporter"\n' + ex ;
84+ return 'Illegal value for "reporter"\n' + ex ;
8185 }
82- } ,
86+ }
8387 } )
8488 . commit ( ) ;
8589
8690module . exports = {
87- get : getJsHintReporter ,
88- yargsCheck : checkJsHintReporter ,
89- yargsOption : yargsOptionDefiniton ,
91+ get : getJsHintReporter ,
92+ yargsCheck : checkJsHintReporter ,
93+ yargsOption : yargsOptionDefiniton ,
9094 defaultReporterName : defaultReporterName
9195} ;
0 commit comments