-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
42 lines (36 loc) · 1.06 KB
/
index.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
const Promise = require('bluebird')
const config = require('./lib/config')
const logger = require('./lib/logger')
const utils = require('./lib/utils')
const Build = require('./lib/build')
const FileSaver = require('./lib/file-saver')
const templateInfo = utils.requireAndInit('templateInfo')
async function buildEmails(templates) {
try {
const buildPromises = templates.map(template => new Build(template).go())
await Promise.all(buildPromises)
logger.info('Emails compiled and saved.')
} catch (err) {
logger.error(err)
}
}
function compileDirectory(templatesPath, options = {}) {
if (options.doctype) {
config.setDoctype(options.doctype)
}
if (options.whitelistSelectors) {
config.setWhitelistSelectors(options.whitelistSelectors)
}
return templateInfo
.getTplPaths(templatesPath)
.then(buildEmails)
.catch(err => {
logger.error(err)
})
}
function compileEmail(tpl, context) {
FileSaver.disable()
return new Build(tpl, context).go()
}
compileDirectory.compileEmail = compileEmail
module.exports = compileDirectory