-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
85 lines (73 loc) · 1.76 KB
/
gulpfile.ts
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
import * as gulp from 'gulp'
import * as mjml from 'gulp-mjml'
import * as i18n from 'gulp-html-i18n'
import * as browserSync from 'browser-sync'
import * as minimist from 'minimist'
const argv = minimist(process.argv.slice(2))
const basePaths = {
translationSrc: './lang/',
templatesSrc: './src/templates/',
i18nTemplatesOutput: './build/i18n-emails/',
mjmlOutputDest: './build/emails/',
}
const paths = {
i18n: {
emailsSrc: basePaths.templatesSrc + '/**/*.mjml',
languagesSrc: basePaths.translationSrc,
dest: basePaths.i18nTemplatesOutput,
},
mjml: {
src: basePaths.i18nTemplatesOutput + '*.mjml',
dest: basePaths.mjmlOutputDest,
},
watch: [basePaths.templatesSrc, basePaths.translationSrc],
}
const generateLocalizedEmailTemplates = () => {
return gulp
.src(paths.i18n.emailsSrc)
.pipe(
i18n({
langDir: paths.i18n.languagesSrc,
})
)
.pipe(gulp.dest(paths.i18n.dest))
}
const buildMjmlToHtml = () => {
return gulp.src(paths.mjml.src).pipe(mjml()).pipe(gulp.dest(paths.mjml.dest))
}
/** Dev server */
const server = (done) => {
let watchDir = paths.mjml.dest
// $gulp --mjml
// will start watch for lokalised emails
if (argv.mjml) {
watchDir = paths.mjml.dest
}
const options = {
server: {
baseDir: watchDir,
directory: true,
},
port: '8000',
notify: false,
}
browserSync.init(options)
done()
}
const watch = () => {
gulp
.watch(paths.watch)
.on(
'change',
gulp.series(
generateLocalizedEmailTemplates,
buildMjmlToHtml,
browserSync.reload
)
)
}
gulp.task(
'build',
gulp.series(generateLocalizedEmailTemplates, buildMjmlToHtml)
)
gulp.task('default', gulp.series('build', gulp.parallel(server, watch)))