-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
100 lines (81 loc) · 2.58 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
'use strict';
let gulp = require('gulp');
let jshint = require('gulp-jshint');
let watch = require('gulp-watch');
let watchify = require('watchify');
let browserify = require('browserify');
let source = require('vinyl-source-stream');
let buffer = require('vinyl-buffer');
let gutil = require('gulp-util');
let sourcemaps = require('gulp-sourcemaps');
let jasmine = require('gulp-jasmine');
let jasmineSpecReporter = require('jasmine-spec-reporter');
let handleError = function(task) {
return function(err) {
notify.onError({
message: task + ' failed, check the logs..',
sound: false
})(err);
gutil.log(gutil.colors.bgRed(task + ' error:'), gutil.colors.red(err));
};
};
/*
BROWSERIFY SECTION
Delete or comment out if you are not using Browserify
*/
let customOpts = {
entries: ['./js/main.js'],
debug: true
};
let opts = Object.assign({}, watchify.args, customOpts);
let bundler = watchify(browserify(opts));
bundler.on('update', bundle); // on any dep update, runs the bundler
bundler.on('log', gutil.log); // output build logs to terminal
function bundle() {
return bundler.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('bundle.js'))
// optional, remove if you don't need to buffer file contents
.pipe(buffer())
// optional, remove if you dont want sourcemaps
.pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file
// Add transformation tasks to the pipeline here.
.pipe(sourcemaps.write('./')) // writes .map file
.pipe(gulp.dest('./dist'));
}
gulp.task('browserify', bundle);
/*
JSHINT SECTION
Not optional. You should always be validating your JavaScript
*/
gulp.task('lint', function() {
return gulp.src(['./js/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.on('error', function() { });
});
/*
JASMINE SECTION
*/
gulp.task('specs', function() {
return gulp.src('./js/spec/*pec.js')
.pipe(jasmine({
reporter: new jasmineSpecReporter({
displayFailuresSummary: false,
}),
errorOnFail: false,
}));
});
/*
WATCH TASK SECTION
Detects when you make a change to any JavaScript file, and/or
SASS file and immediately runs the corresponding task.
*/
gulp.task('watch', function() {
// Run the link task when any JavaScript file changes
gulp.watch(['./js/**/*.js'], ['lint', 'specs']);
gutil.log(gutil.colors.bgGreen('Watching for changes...'));
});
// This task runs when you type `gulp` in the CLI
gulp.task('default', ['lint', 'specs', 'watch'], bundle);