-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
54 lines (48 loc) · 1.51 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
const fs = require('fs')
const path = require('path')
const gulp = require('gulp')
const watch = require('gulp-watch')
const exec = require('child_process').exec
const argv = require('yargs').argv
const verify = () => {
const tmpl = argv.tmpl && argv.tmpl.toString() || ''
if (!fs.existsSync(path.join(__dirname, 'templates', tmpl, 'index.mjml'))) {
console.log(`templates/${tmpl}/index.mjml not found`)
console.log('Usage: gulp watch|build --tmpl demo')
process.exit(1)
}
}
const compile = (cb) => {
exec(`TMPL=${argv.tmpl} ./node_modules/.bin/mjml ./templates/${argv.tmpl}/index.mjml -o ./templates/${argv.tmpl}/index.html`, (err, stdout, stderr) => {
console.log(stdout, stderr)
console.log('MJML compilation finished - ' + new Date().toTimeString().split(' ')[0])
cb && cb()
})
}
const thumbs = (cb) => {
console.log('Make Thumbs ...')
exec(`./node_modules/.bin/grunt makeThumbs:main:${argv.tmpl}`, (err, stdout, stderr) => {
console.log(stdout, stderr)
console.log('Make Thumbs finished - ' + new Date().toTimeString().split(' ')[0])
cb && cb()
})
}
gulp.task('build', (cb) => {
verify()
compile(() => {
thumbs(cb)
})
})
gulp.task('watch', () => {
verify()
compile()
return watch([
'lib/**',
'components/**.js',
`templates/${argv.tmpl}/index.mjml`,
`templates/${argv.tmpl}/postrender.js`,
], () => {
compile()
})
})
gulp.task('default', ['build'])