-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
82 lines (71 loc) · 2.43 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
var source = require('vinyl-source-stream');
var streamify = require('gulp-streamify');
var browserify = require('browserify');
var uglify = require('gulp-uglify');
var gulp = require('gulp');
var karma = require('karma').server;
var watchify = require('watchify');
//default gulp task browserifies application js files in bundle and minifies js
gulp.task('default', function() {
var bundleStream = browserify('./todowhat/static/js/app.js').bundle()
bundleStream
.pipe(source('bundle.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest('./todowhat/static/'))
});
//this task watches for changes application js files and compiles them
gulp.task('watch', function(){
watch = true;
browserifySetup('./todowhat/static/js/app.js', 'bundle.js', './todowhat/static/');
});
//this task watches for changes application js files and compiles jasmine test specs
gulp.task('watch-compile-test', function(){
watch = true;
browserifySetup('./todowhat/static/tests/specs.js', 'testFile.js', './todowhat/static/tests/');
});
//this task just compiles jasmine test specs
gulp.task('nowatch-compile-test', function(){
watch = false;
browserifySetup('./todowhat/static/tests/specs.js', 'testFile.js', './todowhat/static/tests/');
});
//this task runs tests with karma after test specs have been bundled and again if changed
gulp.task('watch-test', ['watch-compile-test'], function (done) {
karma.start({
configFile: __dirname + '/todowhat/static/tests/my.conf.js',
action: 'watch'
}, done);
});
//this task runs tests with karma after test specs have been bundled
gulp.task('test', ['nowatch-compile-test'], function (done) {
karma.start({
configFile: __dirname + '/todowhat/static/tests/my.conf.js'
}, done);
});
function browserifySetup(inputFile, outputFile, outputPath){
//need to pass these three config options to browserify
var b = browserify({
cache: {},
packageCache: {},
fullPaths: true
});
//use watchify is watch flag set to true
if (watch) {
//wrap watchify around browserify
b = watchify(b);
//compile the files when there is a change saved
b.on('update', function(){
buildFiles(b, outputFile, outputPath);
});
}
b.add(inputFile);
buildFiles(b, outputFile, outputPath);
}
function buildFiles(b, outputFile, outputPath) {
b.bundle()
.on('error', function(err){
console.log(err.message);
this.end();
})
.pipe(source(outputFile))
.pipe(gulp.dest(outputPath));
}