-
Notifications
You must be signed in to change notification settings - Fork 27
/
gulpfile.js
119 lines (102 loc) · 2.27 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var path = require('path');
var _ = require('lodash');
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var protractor = require("gulp-protractor").protractor;
var Server = require('karma').Server;
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var modRewrite = require('connect-modrewrite');
var gulp = require('gulp');
var config = {
paths: {
scripts: ['./src/*.js']
}
};
// Build
gulp.task('build', function() {
return gulp.src(config.paths.scripts)
.pipe(uglify({
preserveComments: 'some'
}))
.pipe(gulp.dest('docs/'))
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest('dist/'));
});
// Lint
gulp.task('lint', function() {
return gulp.src(config.paths.scripts)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('test', ['lint'], function(done) {
var server = new Server({
configFile: path.resolve('karma.conf.js')
});
server.on('browser_error', function (browser, err) {
throw err;
});
server.on('run_complete', function (browsers, results) {
if (results.failed) {
throw new Error('Karma: Tests Failed');
}
done();
});
server.start();
});
gulp.task('test-e2e', ['serve-e2e'], function() {
return gulp.src(['./test/e2e/**/*.js'])
.pipe(protractor({
configFile: './protractor.conf.js'
}))
.on('error', function(e) {
browserSync.exit();
throw e;
})
.on('end', function(e) {
browserSync.exit();
});
});
// Watch
gulp.task('watch', function() {
gulp.watch(config.paths.scripts, ['lint']);
});
// Serve
gulp.task('serve', ['watch'], function() {
serve({
port: 3000
});
gulp.watch('*.html').on('change', browserSync.reload);
});
gulp.task('serve-e2e', function(done) {
serve({
notify: false,
logConnections: false,
logFileChanges: false,
open: false,
port: 3333
});
done();
});
function serve(config, done) {
var defaults = {
notify: false,
logConnections: true,
logFileChanges: true,
open: true,
port: 3000,
server: {
baseDir: ['./', './docs', './src'],
middleware: [
modRewrite([
'!\\.html|\\.js|\\.svg|\\.css|\\.png|\\.jpg|\\.woff|\\.woff2|\\.ttf|\\.csv /docs/index.html'
])
]
}
};
browserSync.init(_.extend({}, defaults, config));
}
gulp.task('default', ['serve']);