forked from davidrosenberg/ml2015
/
gulpfile.js
49 lines (41 loc) · 1.18 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
'use strict';
const templater = require('./build/templater.js');
const fs = require('fs');
const gulp = require('gulp');
const gutil = require('gulp-util');
const gulpStylus = require('gulp-stylus');
const STYLUS = 'styles/*.styl';
const TEMPLATES = '**/*.hbs';
const MAIN_TEMPLATE = 'index.hbs';
const DATA = 'data/*.yml';
const OUTPUT_HTML = 'index.html';
const OUTPUT_STYLES = 'styles/';
gulp.task('template', () => {
try {
templater(MAIN_TEMPLATE, OUTPUT_HTML)
} catch (e) {
// Delete the index.html file to make it clear that the templating failed
deleteIfExists(OUTPUT_HTML);
gutil.log(gutil.colors.red(`Deleting ${OUTPUT_HTML} since templating failed`));
throw e;
}
});
gulp.task('stylus', () =>
gulp.src(STYLUS)
.pipe(gulpStylus())
.pipe(gulp.dest(OUTPUT_STYLES))
);
gulp.task('build', ['template', 'stylus']);
gulp.task('watch', ['template', 'stylus'], () => {
gulp.watch([TEMPLATES, DATA], ['template']);
gulp.watch(STYLUS, ['stylus'])
});
function deleteIfExists(filename) {
try {
fs.unlinkSync(filename);
} catch (e) {
if (e.code !== 'ENOENT') {
throw e;
}
}
}