-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgulpfile.js
67 lines (53 loc) · 1.83 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
'use strict';
var gulp = require( 'gulp' );
var year = require('optimist').argv.year || process.env.YEAR;
var eventFile = './src/events/' + year + '.json';
var connect = require( 'gulp-connect' );
var concat = require( 'gulp-concat' );
var nano = require('gulp-cssnano' );
var handlebars = require( 'gulp-compile-handlebars' );
var rename = require( 'gulp-rename' );
var files = [ 'index.html', './assets/css/styles.css' ];
var handlebarsFiles = [ './views/**/*', eventFile ];
var _ = require('lodash');
var options = {
batch: ['./src/views/partials' ],
};
function getEventData() {
var eventData = require(eventFile);
eventData.speakers = _.chain(eventData.schedule)
.map(function getSpeakers(event) { return event.speaker; })
.compact()
.sortBy('priority')
.value();
if (!eventData.schedule.every(function (s) { return s.time })) {
delete eventData.schedule;
}
return eventData;
}
gulp.task( 'hbs', function () {
return gulp.src('src/views/index.hbs')
.pipe(handlebars(getEventData(), options))
.pipe(rename('index.html'))
.pipe(gulp.dest('./'));
});
gulp.task( 'css', function () {
return gulp.src('src/css/**/*')
.pipe(concat('styles.css'))
.pipe(nano())
.pipe(gulp.dest('./assets/css'));
});
gulp.task( 'files', function() {
gulp.src( files ).pipe( connect.reload() );
});
// Watch files
gulp.task( 'watch', function() {
gulp.watch( files, gulp.series('files'));
gulp.watch( handlebarsFiles, gulp.series('hbs'));
gulp.watch( './src/css/**/*', gulp.series('hbs'));
});
gulp.task( 'connect', function() {
connect.server({ livereload: true });
});
gulp.task('build', gulp.parallel('hbs', 'css'))
gulp.task('default', gulp.parallel('build', 'connect', 'watch'))