-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.babel.js
85 lines (73 loc) · 1.85 KB
/
gulpfile.babel.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
'use strict';
import yaml from 'js-yaml';
import browser from 'browser-sync';
import rimraf from 'rimraf';
import fs from 'fs';
import gulp from 'gulp';
import mjmlGulp from 'gulp-mjml';
import mjml from 'mjml';
import nunjucks from 'gulp-nunjucks-render';
import data from 'gulp-data';
const PATHS = {
src: './src/{layouts,partials,templates}/**/*.mjml',
data: './src/data/data.yml',
layouts: './src/layouts/',
partials: './src/partials/',
templates: './src/templates/**/*.mjml',
mjml: {
src: './dist/mjml/**/*.mjml',
dist: './dist/mjml/',
},
dist: './dist/html/'
}
function load_data() {
let yml = fs.readFileSync(PATHS.data, 'utf8')
return yaml.load(yml);
}
export function clean(done) {
rimraf('./dist/*', done);
}
export function buildTemplates() {
return gulp.src(PATHS.templates)
.pipe(data(load_data))
.pipe(nunjucks({
path: [
PATHS.layouts,
PATHS.partials
],
envOptions: {
noCache: true
},
inheritExtension: true
}))
.pipe(gulp.dest(PATHS.mjml.dist));
}
export function buildMjml() {
const options = {
beautify: true,
minify: false
};
return gulp.src(PATHS.mjml.src)
.pipe(mjmlGulp(mjml, options))
.pipe(gulp.dest(PATHS.dist));
}
export function server(done) {
const options = {
server: {
baseDir: PATHS.dist,
directory: true
},
port: '8000',
notify: false
};
browser.init(options);
done();
}
export function watch() {
gulp.watch(PATHS.data).on('all', gulp.series(buildTemplates, buildMjml, browser.reload));
gulp.watch(PATHS.src).on('all', gulp.series(buildTemplates, buildMjml, browser.reload));
}
gulp.task('build',
gulp.series(clean, buildTemplates, buildMjml));
gulp.task('default',
gulp.series('build', gulp.parallel(server, watch)));