This repository has been archived by the owner on Feb 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
109 lines (99 loc) · 2.74 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var meta = require('./package.json');
var gulp = require('gulp');
var browserify = require('browserify');
var reactify = require('reactify');
var watchify = require('watchify');
var transform = require('vinyl-transform');
var uglify = require('gulp-uglify');
var less = require('gulp-less');
var usemin = require('gulp-usemin');
var minifyCss = require('gulp-minify-css');
var rev = require('gulp-rev');
var argv = require('yargs').argv;
var eslint = require('gulp-eslint');
var jest = require('gulp-jest');
var cache = require('gulp-cached');
var rimraf = require('rimraf');
var rename = require('gulp-rename');
var gutil = require('gulp-util');
var plumber = require('gulp-plumber');
var filter = require('gulp-filter');
var coveralls = require('gulp-coveralls');
var source = require('vinyl-source-stream');
var onError = function(err) {
gutil.beep();
return err;
};
// Compile JS using Browserify.
function compileScripts() {
function bundle(bro) {
return bro.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('./src'));
}
var b = browserify({
debug: true,
cache: {},
packageCache: {},
fullPaths: false
});
if (argv.watch) {
// If watch is enabled, wrap this bundle inside watchify.
b = watchify(b);
b.on('update', function(ids){
ids.forEach(function(id){
gutil.log(id + ' changed.');
});
bundle(b);
});
b.on('log', function(msg){
gutil.log('Browserify: ' + msg);
gulp.start('lint');
});
}
b.add('./src/js/app.jsx');
return bundle(b);
}
gulp.task('lint', function() {
return gulp.src(['./src/js/**/*.jsx', './src/js/**/*.js', './src/js/**/**/*.js', './gulpfile.js', '!./src/js/bundle.js', '!**/coverage/**/*'])
.pipe(plumber({
errorHandler: onError
}))
.pipe(cache('lint'))
.pipe(eslint())
.pipe(eslint.failOnError());
});
gulp.task('jest', function() {
return gulp.src('')
.pipe(plumber({
errorHandler: onError
}))
.pipe(jest(meta.jest));
});
gulp.task('coverage', ['jest'], function() {
return gulp.src('./coverage/lcov.info')
.pipe(coveralls());
});
gulp.task('browserify', function() {
return compileScripts();
});
gulp.task('empty-dist-dir', function(cb) {
rimraf('./dist', cb);
});
gulp.task('process-for-prod', function(cb) {
var usem = gulp.src('./src/index.html')
.pipe(usemin({
less: [less(), minifyCss(), 'concat', rev()],
js: [uglify(), rev()]
}))
.pipe(gulp.dest('dist/'));
});
// Primary task
gulp.task('build', ['browserify', 'empty-dist-dir'], function() {
if (argv.watch) {
gulp.watch(['./src/**/__tests__/**/*.js'], ['test']);
}
gulp.start('process-for-prod');
});
gulp.task('test', ['lint', 'jest']);
gulp.task('default', ['test', 'build']);