@@ -14,36 +14,67 @@ var gutil = require('gulp-util');
1414var through = require ( 'through2' ) ;
1515var globby = require ( 'globby' ) ;
1616
17- var sources = [ './ lib/**/*.js' ] ;
18- var testSources = [ './ test/**/*.js' ] ;
17+ var sources = [ 'lib/**/*.js' ] ;
18+ var testSources = [ 'test/**/*.js' ] ;
1919
2020gulp . task ( 'lint' , function ( ) {
2121 return gulp . src ( sources )
2222 . pipe ( eslint ( {
2323 extends : 'eslint:recommended' ,
24- ecmaFeatures : {
25- 'modules' : true
26- }
24+ rules : {
25+ strict : 2
26+ } ,
27+ env : {
28+ node : true
29+ }
2730 } ) )
2831 . pipe ( eslint . format ( ) )
2932 . pipe ( eslint . failAfterError ( ) ) ;
3033} ) ;
3134
32- gulp . task ( 'test' , [ ] , function ( done ) {
33- return gulp . src ( testSources , { read : false } )
35+ gulp . task ( 'test' , [ 'lint' ] , function ( done ) {
36+ var prependToAll = function ( path , globs ) {
37+ var ret = [ ] ;
38+ for ( var v of globs ) {
39+ ret . push ( path + '/' + v ) ;
40+ }
41+ return ret ;
42+ } ;
43+ var fs = require ( 'fs' ) ;
44+ var target = 'target' ;
45+ if ( ! fs . existsSync ( target ) ) {
46+ fs . mkdirSync ( target ) ;
47+ }
48+ var pwd = process . cwd ( ) ;
49+ process . chdir ( target ) ;
50+ var testSrc = prependToAll ( '..' , testSources ) ;
51+ var src = prependToAll ( '..' , sources ) ;
52+ return gulp . src ( testSrc , { read : false } )
3453 . pipe ( cover . instrument ( {
35- pattern : sources ,
36- debugDirectory : 'debug'
54+ pattern : src ,
55+ debugDirectory : 'debug'
3756 } ) )
3857 . pipe ( mocha ( ) )
3958 . pipe ( cover . gather ( ) )
40- . pipe ( cover . format ( ) )
41- . pipe ( gulp . dest ( 'reports' ) ) ;
59+ . pipe ( cover . enforce ( {
60+ statements : 98 ,
61+ blocks : 98 ,
62+ lines : 98 ,
63+ } ) )
64+ . pipe ( cover . format ( [
65+ { reporter : 'html' , outFile : 'coverage.html' } ,
66+ { reporter : 'json' , outFile : 'coverage.json' } ,
67+ { reporter : 'lcov' , outFile : 'coverage.lcov' } ,
68+ ] ) )
69+ . pipe ( gulp . dest ( 'reports' ) )
70+ . on ( 'end' , function ( ) {
71+ process . chdir ( pwd ) ;
72+ } ) ;
4273} ) ;
4374gulp . task ( 'watch' , function ( ) {
4475 gulp . watch ( sources . concat ( testSources ) , [ 'test' ] ) ;
4576} ) ;
46- gulp . task ( 'build' , function ( ) {
77+ gulp . task ( 'build-browser' , [ 'test' ] , function ( ) {
4778 // gulp expects tasks to return a stream, so we create one here.
4879 var bundledStream = through ( ) ;
4980
@@ -53,13 +84,47 @@ gulp.task('build', function() {
5384 . pipe ( source ( 'eid.js' ) )
5485 // the rest of the gulp task, as you would normally write it.
5586 // here we're copying from the Browserify + Uglify2 recipe.
87+ . pipe ( buffer ( ) )
88+ . on ( 'error' , gutil . log )
89+ . pipe ( gulp . dest ( 'dist/browser/js/' ) ) ;
90+
91+ // "globby" replaces the normal "gulp.src" as Browserify
92+ // creates it's own readable stream.
93+ globby ( [ './lib/**/*.js' ] ) . then ( function ( entries ) {
94+ // create the Browserify instance.
95+ var b = browserify ( {
96+ entries : entries ,
97+ debug : true
98+ } ) ;
99+
100+ // pipe the Browserify stream into the stream we created earlier
101+ // this starts our gulp pipeline.
102+ b . bundle ( ) . pipe ( bundledStream ) ;
103+ } ) . catch ( function ( err ) {
104+ // ensure any errors from globby are handled
105+ bundledStream . emit ( 'error' , err ) ;
106+ } ) ;
107+
108+ // finally, we return the stream, so gulp knows when this task is done.
109+ return bundledStream ;
110+ } ) ;
111+ gulp . task ( 'build-minified' , [ 'test' ] , function ( ) {
112+ // gulp expects tasks to return a stream, so we create one here.
113+ var bundledStream = through ( ) ;
114+
115+ bundledStream
116+ // turns the output bundle stream into a stream containing
117+ // the normal attributes gulp plugins expect.
118+ . pipe ( source ( 'eid.min.js' ) )
119+ // the rest of the gulp task, as you would normally write it.
120+ // here we're copying from the Browserify + Uglify2 recipe.
56121 . pipe ( buffer ( ) )
57122 . pipe ( sourcemaps . init ( { loadMaps : true } ) )
58123 // Add gulp plugins to the pipeline here.
59124 . pipe ( uglify ( ) )
60125 . on ( 'error' , gutil . log )
61126 . pipe ( sourcemaps . write ( './' ) )
62- . pipe ( gulp . dest ( './ dist/js/' ) ) ;
127+ . pipe ( gulp . dest ( 'dist/browser /js/' ) ) ;
63128
64129 // "globby" replaces the normal "gulp.src" as Browserify
65130 // creates it's own readable stream.
@@ -81,4 +146,5 @@ gulp.task('build', function() {
81146 // finally, we return the stream, so gulp knows when this task is done.
82147 return bundledStream ;
83148} ) ;
149+ gulp . task ( 'build' , [ 'build-minified' , 'build-browser' ] ) ;
84150gulp . task ( 'default' , [ 'lint' , 'test' , 'build' ] ) ;
0 commit comments