-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
65 lines (58 loc) · 1.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
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var karma = require('gulp-karma');
var sourcemaps = require('gulp-sourcemaps');
var babel = require('gulp-babel');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
// Lint Task
gulp.task('lint', function() {
return gulp.src(['src/*.js', '!src/*.test.js'])
.pipe(jshint({
multistr: true,
validthis: true,
evil: true,
esnext: true
}))
.pipe(jshint.reporter('default'));
});
// Test
gulp.task('test', function() {
// Be sure to return the stream
// NOTE: Using the fake './foobar' so as to run the files
// listed in karma.conf.js INSTEAD of what was passed to
// gulp.src !
return gulp.src('./foobar', { allowEmpty: true })
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
// Make sure failed tests cause gulp to exit non-zero
console.log(err);
this.emit('end'); //instead of erroring the stream, end it
});
});
// Concatenate & Transpile JS
gulp.task('scripts', function() {
return gulp.src(['src/*.js', '!src/*.test.js'])
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(concat('all.js'))
.pipe(gulp.dest('dist'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
});
// Watch Files For Changes
gulp.task('watch', function() {
gulp.watch('src/*.js', gulp.series('lint', 'scripts'));
});
// Default Task sans watch
gulp.task('build', gulp.series('lint', 'scripts', 'test'));
// Default Task
gulp.task('default', gulp.series('build', 'watch'));