11"use strict" ;
22
3+ var fs = require ( 'fs' ) ;
4+ var _ = require ( 'lodash' ) ;
5+ var stripJsonComments = require ( 'strip-json-comments' ) ;
6+
37var gulp = require ( 'gulp' ) ;
48var log = require ( 'gulp-util' ) . log ;
59var concat = require ( 'gulp-concat' ) ;
@@ -25,6 +29,23 @@ var ignoredFiles = '!src/angular.bind.js';
2529var assets = 'app/assets/**/*' ;
2630
2731
32+ var getJshintConfig = function ( filepath ) {
33+ return JSON . parse ( stripJsonComments ( fs . readFileSync ( filepath , { encoding : 'utf-8' } ) ) ) ;
34+ } ;
35+
36+ var getMergedJshintConfig = function ( filepath ) {
37+ // "extends" doesn't work in configuration passed by an object, we need to do the extending ourselves.
38+ var config = getJshintConfig ( filepath ) ;
39+ var baseConfig = getJshintConfig ( '../.jshintrc-base' ) ;
40+ _ . merge ( config , baseConfig ) ;
41+ delete config . extends ;
42+
43+ // Examples don't run in strict mode; accept that for now.
44+ config . strict = false ;
45+
46+ return config ;
47+ } ;
48+
2849var copyComponent = function ( component , pattern , sourceFolder , packageFile ) {
2950 pattern = pattern || '/**/*' ;
3051 sourceFolder = sourceFolder || bowerFolder ;
@@ -90,17 +111,35 @@ gulp.task('assets', ['bower'], function() {
90111
91112gulp . task ( 'doc-gen' , [ 'bower' ] , function ( ) {
92113 var dgeni = new Dgeni ( [ require ( './config' ) ] ) ;
93- return dgeni . generate ( ) . catch ( function ( error ) {
114+ return dgeni . generate ( ) . catch ( function ( ) {
94115 process . exit ( 1 ) ;
95116 } ) ;
96117} ) ;
97118
98119// JSHint the example and protractor test files
99120gulp . task ( 'jshint' , [ 'doc-gen' ] , function ( ) {
100- gulp . src ( [ outputFolder + '/ptore2e/**/*.js' , outputFolder + '/examples/**/*.js' ] )
101- . pipe ( jshint ( ) )
102- . pipe ( jshint . reporter ( 'jshint-stylish' ) )
103- . pipe ( jshint . reporter ( 'fail' ) ) ;
121+ var examplesConfig = getMergedJshintConfig ( '../docs/app/test/.jshintrc' ) ;
122+ // Some tests use `alert` which is not assumed to be available even with `"browser": true`.
123+ examplesConfig . globals . alert = false ;
124+
125+ var protractorConfig = getMergedJshintConfig ( '../docs/app/e2e/.jshintrc' ) ;
126+
127+ return merge (
128+ gulp . src ( [
129+ outputFolder + '/examples/**/*.js' ,
130+ '!' + outputFolder + '/examples/**/protractor.js' ,
131+ ] )
132+ . pipe ( jshint ( examplesConfig ) )
133+ . pipe ( jshint . reporter ( 'jshint-stylish' ) )
134+ . pipe ( jshint . reporter ( 'fail' ) ) ,
135+ gulp . src ( [
136+ outputFolder + '/ptore2e/**/*.js' ,
137+ outputFolder + '/examples/**/protractor.js' ,
138+ ] )
139+ . pipe ( jshint ( protractorConfig ) )
140+ . pipe ( jshint . reporter ( 'jshint-stylish' ) )
141+ . pipe ( jshint . reporter ( 'fail' ) )
142+ ) ;
104143} ) ;
105144
106145
0 commit comments