-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
230 lines (197 loc) · 5.19 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/* eslint-disable */
'use strict';
/* global process */
var babel = require('babelify');
require('babel-register');
var browserSync = require('browser-sync');
var del = require('del');
var gulp = require('gulp');
var gulpMocha = require('gulp-mocha');
var gutil = require('gulp-util');
var nunjucksRender = require('gulp-nunjucks-render');
var runSequence = require('run-sequence');
var sass = require('gulp-sass');
var selenium = require('selenium-standalone');
var webdriver = require('gulp-webdriver');
var eslint = require('gulp-eslint');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
// Instances
var devBrowserSync = browserSync.create();
var testingBrowserSync = browserSync.create();
var seleniumServer;
// Source code generation
/////////////////////////
function imagesTask() {
return gulp
.src([
'app/images/**/*+(png|jpg|jpeg|gif|svg)',
'node_modules/leaflet/dist/images/**/*'
])
.pipe(gulp.dest('build/images'));
}
gulp.task('compile:images', imagesTask);
function fontsTask() {
return gulp
.src('node_modules/font-awesome/fonts/**/*')
.pipe(gulp.dest('build/fonts'));
}
gulp.task('compile:fonts', fontsTask);
function sassTask() {
return gulp
.src('app/scss/**/*.scss')
.pipe(sass({includePaths: ['node_modules']}))
.pipe(gulp.dest('build/css'));
}
gulp.task('compile:sass', sassTask);
function compileJsTask() {
var bundler =
browserify(
'./app/es/app.es',
{debug: true}
).transform(babel);
function rebundle() {
return bundler
.bundle()
.on('error', function(err) { gutil.log(err); this.emit('end'); })
.pipe(source('build.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./build/js'));
}
return rebundle();
}
gulp.task('compile:js', compileJsTask);
function nunjucksTask() {
return gulp
.src('app/pages/**/*.+(html)')
.pipe(
nunjucksRender({
path: ['app/templates']
})
)
.pipe(gulp.dest('build'));
}
gulp.task('compile:html', nunjucksTask);
gulp.task('compile', ['compile:html', 'compile:js', 'compile:sass', 'compile:images', 'compile:fonts']);
// Linting
//////////
function eslintTask() {
return gulp.src(['**/*.es'])
.pipe(eslint())
.pipe(eslint.format());
}
gulp.task('lint', eslintTask);
// Development web server
/////////////////////////
function browserSyncTask( done ) {
devBrowserSync.init({
server: {
baseDir: 'build'
},
host: '0.0.0.0',
browser: ['chromium-browser']
});
done();
}
gulp.task('browserSync', browserSyncTask);
function watchTask( done ) {
gulp.watch('app/scss/**/*.scss', ['compile:sass']);
gulp.watch('app/es/**/*.es', ['compile:js']);
gulp.watch('app/templates/**/*', ['compile:html']);
gulp.watch('app/pages/**/*', ['compile:html']);
gulp.watch('app/images/**/*', ['compile:images']);
gulp.watch('build/**/*', devBrowserSync.reload);
done();
}
gulp.task('watch', ['browserSync', 'compile'], watchTask);
// Unit testing
///////////////
function testUnitTask() {
return gulp
.src(['test/unit/**/*.+(js|es)'])
.pipe(gulpMocha({
timeout: 5000,
compilers: [
'js:babel-core/register',
'es:babel-core/register'
]
}));
}
gulp.task('test:unit', testUnitTask);
// End-to-end testing in web server
///////////////////////////////////
function nunjucksFixturesTask() {
return gulp
.src('test/fixtures/pages/**/*.+(html)')
.pipe(
nunjucksRender({
path: ['app/templates']
})
)
.pipe(gulp.dest('build'));
}
gulp.task('compile:fixtures', nunjucksFixturesTask);
function testingBrowserSyncTask( done ) {
testingBrowserSync.init({
server: {
baseDir: 'build'
},
port: 9000,
browser: 'chromium-browser'
});
done();
}
gulp.task('testingBrowserSync', testingBrowserSyncTask);
gulp.task('test:server',
['compile:js', 'compile:sass', 'compile:images', 'compile:fixtures', 'compile:fonts'],
testingBrowserSyncTask );
function seleniumStandaloneTask(done) {
selenium.install( {
logger: gutil.log
}, function() {
selenium.start( function( err, child ) {
if (err) {
return done(err);
}
else {
seleniumServer = child;
return done();
}
} );
});
}
gulp.task( 'test:selenium', seleniumStandaloneTask );
function functionalTestTask() {
return gulp
.src('wdio.conf.js')
.pipe(webdriver())
.on('error', function() {
seleniumServer.kill();
process.exit(1);
});
}
gulp.task('test:functional', ['test:server', 'test:selenium'], functionalTestTask );
gulp.task('test:functional-and-cleanup', ['test:functional'], function() {
testingBrowserSync.cleanup();
seleniumServer.kill();
} );
gulp.task('test', ['test:unit', 'test:functional-and-cleanup'] );
// Distribution
///////////////
function cleanBuildTask() {
return del.sync('build');
}
gulp.task('build:clean', cleanBuildTask);
function buildTask(callback) {
runSequence(
'build:clean',
'compile',
callback
);
}
gulp.task('build', buildTask);
gulp.task('default', buildTask);