@@ -14,36 +14,67 @@ var gutil = require('gulp-util');
14
14
var through = require ( 'through2' ) ;
15
15
var globby = require ( 'globby' ) ;
16
16
17
- var sources = [ './ lib/**/*.js' ] ;
18
- var testSources = [ './ test/**/*.js' ] ;
17
+ var sources = [ 'lib/**/*.js' ] ;
18
+ var testSources = [ 'test/**/*.js' ] ;
19
19
20
20
gulp . task ( 'lint' , function ( ) {
21
21
return gulp . src ( sources )
22
22
. pipe ( eslint ( {
23
23
extends : 'eslint:recommended' ,
24
- ecmaFeatures : {
25
- 'modules' : true
26
- }
24
+ rules : {
25
+ strict : 2
26
+ } ,
27
+ env : {
28
+ node : true
29
+ }
27
30
} ) )
28
31
. pipe ( eslint . format ( ) )
29
32
. pipe ( eslint . failAfterError ( ) ) ;
30
33
} ) ;
31
34
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 } )
34
53
. pipe ( cover . instrument ( {
35
- pattern : sources ,
36
- debugDirectory : 'debug'
54
+ pattern : src ,
55
+ debugDirectory : 'debug'
37
56
} ) )
38
57
. pipe ( mocha ( ) )
39
58
. 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
+ } ) ;
42
73
} ) ;
43
74
gulp . task ( 'watch' , function ( ) {
44
75
gulp . watch ( sources . concat ( testSources ) , [ 'test' ] ) ;
45
76
} ) ;
46
- gulp . task ( 'build' , function ( ) {
77
+ gulp . task ( 'build-browser' , [ 'test' ] , function ( ) {
47
78
// gulp expects tasks to return a stream, so we create one here.
48
79
var bundledStream = through ( ) ;
49
80
@@ -53,13 +84,47 @@ gulp.task('build', function() {
53
84
. pipe ( source ( 'eid.js' ) )
54
85
// the rest of the gulp task, as you would normally write it.
55
86
// 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.
56
121
. pipe ( buffer ( ) )
57
122
. pipe ( sourcemaps . init ( { loadMaps : true } ) )
58
123
// Add gulp plugins to the pipeline here.
59
124
. pipe ( uglify ( ) )
60
125
. on ( 'error' , gutil . log )
61
126
. pipe ( sourcemaps . write ( './' ) )
62
- . pipe ( gulp . dest ( './ dist/js/' ) ) ;
127
+ . pipe ( gulp . dest ( 'dist/browser /js/' ) ) ;
63
128
64
129
// "globby" replaces the normal "gulp.src" as Browserify
65
130
// creates it's own readable stream.
@@ -81,4 +146,5 @@ gulp.task('build', function() {
81
146
// finally, we return the stream, so gulp knows when this task is done.
82
147
return bundledStream ;
83
148
} ) ;
149
+ gulp . task ( 'build' , [ 'build-minified' , 'build-browser' ] ) ;
84
150
gulp . task ( 'default' , [ 'lint' , 'test' , 'build' ] ) ;
0 commit comments