-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgulpfile.js
More file actions
93 lines (85 loc) · 3.2 KB
/
gulpfile.js
File metadata and controls
93 lines (85 loc) · 3.2 KB
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
/* jshint strict: false */
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var react = require('gulp-react');
var gulpJest = require('gulp-jest');
// var istanbul = require('gulp-istanbul'); //TODO: enable once Jest works with Istanbul
// var coveralls = require('gulp-coveralls'); //TODO: enable once Jest works with Istanbul
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var streamify = require('gulp-streamify');
var source = require('vinyl-source-stream'); // Used to stream bundle for further handling
var browserify = require('browserify');
var watchify = require('watchify');
var reactify = require('reactify');
// Run Linting with JSHint
// ==================================
gulp.task('lint', function () {
gulp.src(['./!(coverage|node_modules|bower_components)/**/!(build)/*.{js,jsx}'])
.pipe( react({harmony: true}) )
.pipe( jshint() )
.pipe( jshint.reporter( stylish ) );
});
// Run Jest Tests
// ==================================
gulp.task('jest', function () {
return gulp.src(['./client'])
.pipe(gulpJest({
unmockedModulePathPatterns: ['node_modules/react'],
// testDirectoryName: "__tests__", //__tests_ is the default
testPathIgnorePatterns: ['node_modules'],
moduleFileExtensions: [
'js',
'jsx',
'json'
]
}));
});
// TODO: once Jest works with Istanbul, setup code coverage
// Run Tests and Generate Coverage Data
// ====================================
// gulp.task('test', function (cb) {
// gulp.src(['requestHandler.js'])
// .pipe(istanbul()) // Instrument files
// .on('finish', function () {
// gulp.src(['spec.js'])
// .pipe(mocha()) // Run Tests
// .pipe(istanbul.writeReports()) // Creating the reports after tests runned
// .on('end', cb);
// });
// });
// TODO: once Jest works with Istanbul, setup code coverage
// Send Coverage Data to Coveralls
// ====================================
// gulp.task('coveralls', function(){
// return gulp.src('./coverage/lcov.info')
// .pipe(coveralls());
// });
// Watch & Build Client JS Bundle
// ====================================
gulp.task('browserify', function() {
var bundler = browserify({
entries: ['./client/app/app.jsx'], // Only need initial file, browserify finds the deps
transform: [reactify], // We want to convert JSX to normal javascript
debug: true, // Gives us sourcemapping
cache: {}, packageCache: {}, fullPaths: true // Requirement of watchify
});
var watcher = watchify(bundler);
return watcher
.on('update', function () { // When any files update
var updateStart = Date.now();
console.log('Updating!');
watcher.bundle() // Create new bundle that uses the cache for high performance
.pipe(source('bundle.js'))
.pipe(streamify(uglify()))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./client/app/build/'));
console.log('Updated!', (Date.now() - updateStart) + 'ms');
})
.bundle() // Create the initial bundle when starting the task
.pipe(source('bundle.js'))
.pipe(streamify(uglify()))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./client/app/build/'));
});