-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
104 lines (89 loc) · 2.35 KB
/
Copy pathgulpfile.js
File metadata and controls
104 lines (89 loc) · 2.35 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
94
95
96
97
98
99
100
101
102
103
104
// Register build and test automation tasks
'use strict';
// Include gulp
var gulp = require('gulp');
// Include plugins
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var istanbul = require('gulp-istanbul');
var mocha = require('gulp-mocha');
var bump = require('gulp-bump');
var karma = require('gulp-karma');
// Lint Task
gulp.task('lint', function() {
return gulp.src(['public/app/**/*.js', '!public/app/vendor/**/*.js',
'server/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
// Concatenate & Minify JS
gulp.task('scripts', function() {
return gulp.src('public/app/**/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('build'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('build'));
});
// Watch Files For Changes
gulp.task('watch', function() {
gulp.watch(['**/*.js', '!node_modules/**/*.js', '!public/app/vendor/**/*.js'],
['lint', 'scripts']);
});
// Testing
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
function karmaTest(action) {
return gulp.src('./foobar')
.pipe(karma({
configFile: 'karma.conf.js',
action: action
}))
.on('error', handleError)
.once('end', function() {
if (action === 'run') {
process.exit();
}
});
}
function serverTest(exitOnEnd) {
gulp.src(['./server/**/*.js', '!./server/test/**/*.js'])
.pipe(istanbul())
.on('end', function() {
gulp.src(['./server/test/**/*.spec.js'])
.pipe(mocha({ reporter: 'list' }))
.pipe(istanbul.writeReports())
.on('error', handleError)
.once('end', function () {
if (exitOnEnd) {
process.exit();
}
});
});
}
gulp.task('test', function() {
serverTest(false);
return karmaTest('run');
});
// Run server tests and output reports
gulp.task('test:server', function () {
serverTest(true);
});
// Run client tests and output reports
gulp.task('test:client', function () {
return karmaTest('run');
});
gulp.task('test:client_watch', function () {
return karmaTest('watch');
});
gulp.task('bump', function () {
gulp.src(['./package.json', './bower.json'])
.pipe(bump())
.pipe(gulp.dest('./'));
});
// Default Task
gulp.task('default', ['lint', 'scripts', 'watch', 'test:client_watch']);