|
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | 4 | var gulp = require('gulp'); |
5 | | -var eslint = require('gulp-eslint'); |
6 | | -var mocha = require('gulp-mocha'); |
7 | | -var cover = require('gulp-coverage'); |
8 | | -var browserify = require('browserify'); |
9 | | -var source = require('vinyl-source-stream'); |
10 | | -var buffer = require('vinyl-buffer'); |
11 | | -var uglify = require('gulp-uglify'); |
12 | | -var sourcemaps = require('gulp-sourcemaps'); |
13 | | -var gutil = require('gulp-util'); |
14 | | -var through = require('through2'); |
15 | | -var globby = require('globby'); |
16 | 5 |
|
17 | | -var sources = ['lib/**/*.js']; |
18 | | -var testSources = ['test/**/*.js']; |
| 6 | +var tests = require('./gulp/tests'); |
| 7 | +var build = require('./gulp/build'); |
| 8 | +var clean = require('./gulp/clean'); |
19 | 9 |
|
20 | | -gulp.task('lint', function () { |
21 | | - return gulp.src(sources) |
22 | | - .pipe(eslint({ |
23 | | - extends: 'eslint:recommended', |
24 | | - rules: { |
25 | | - strict: 2 |
26 | | - }, |
27 | | - env: { |
28 | | - node: true |
29 | | - } |
30 | | - })) |
31 | | - .pipe(eslint.format()) |
32 | | - .pipe(eslint.failAfterError()); |
33 | | -}); |
34 | | - |
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 }) |
53 | | - .pipe(cover.instrument({ |
54 | | - pattern: src, |
55 | | - debugDirectory: 'debug' |
56 | | - })) |
57 | | - .pipe(mocha()) |
58 | | - .pipe(cover.gather()) |
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 | | - }); |
73 | | -}); |
| 10 | +gulp.task('clean', clean); |
| 11 | +gulp.task('lint', tests.lint); |
| 12 | +gulp.task('specs', ['lint'], tests.specs); |
| 13 | +gulp.task('test', ['lint', 'specs']); |
74 | 14 | gulp.task('watch', function() { |
75 | 15 | gulp.watch(sources.concat(testSources), ['test']); |
76 | 16 | }); |
77 | | -gulp.task('build-browser', ['test'], function() { |
78 | | - // gulp expects tasks to return a stream, so we create one here. |
79 | | - var bundledStream = through(); |
80 | | - |
81 | | - bundledStream |
82 | | - // turns the output bundle stream into a stream containing |
83 | | - // the normal attributes gulp plugins expect. |
84 | | - .pipe(source('eid.js')) |
85 | | - // the rest of the gulp task, as you would normally write it. |
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. |
121 | | - .pipe(buffer()) |
122 | | - .pipe(sourcemaps.init({loadMaps: true})) |
123 | | - // Add gulp plugins to the pipeline here. |
124 | | - .pipe(uglify()) |
125 | | - .on('error', gutil.log) |
126 | | - .pipe(sourcemaps.write('./')) |
127 | | - .pipe(gulp.dest('dist/browser/js/')); |
128 | | - |
129 | | - // "globby" replaces the normal "gulp.src" as Browserify |
130 | | - // creates it's own readable stream. |
131 | | - globby(['./lib/**/*.js']).then(function(entries) { |
132 | | - // create the Browserify instance. |
133 | | - var b = browserify({ |
134 | | - entries: entries, |
135 | | - debug: true |
136 | | - }); |
137 | | - |
138 | | - // pipe the Browserify stream into the stream we created earlier |
139 | | - // this starts our gulp pipeline. |
140 | | - b.bundle().pipe(bundledStream); |
141 | | - }).catch(function(err) { |
142 | | - // ensure any errors from globby are handled |
143 | | - bundledStream.emit('error', err); |
144 | | - }); |
145 | | - |
146 | | - // finally, we return the stream, so gulp knows when this task is done. |
147 | | - return bundledStream; |
148 | | -}); |
149 | | -gulp.task('build', ['build-minified', 'build-browser']); |
150 | | -gulp.task('default', ['lint', 'test', 'build']); |
| 17 | +gulp.task('build-browser', ['test'], build.browserify); |
| 18 | +gulp.task('build-minified', ['test'], build.minified); |
| 19 | +gulp.task('build', ['build-browser', 'build-minified']); |
| 20 | +gulp.task('default', ['test', 'build']); |
0 commit comments