-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (47 loc) · 1.68 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fs = require('fs');
const path = require('path');
const mjml = require('mjml');
const createTemplate = require('./lib/create-template');
const createDirectory = require('./lib/create-directory');
const getFiles = require('./lib/get-files');
const includesPath = path.join(__dirname, 'mjml-includes');
const output = path.join(__dirname, 'output');
const mjmlOptions = {
beautify: true,
filePath: includesPath
};
createDirectory(output).then(async directory => {
try {
const generateSpeakerMarkup = await createTemplate(
'./templates/speaker-template.hbs'
);
const generateSponsorMarkup = await createTemplate(
'./templates/sponsor-template.hbs'
);
const generateEmailMarkup = await createTemplate(
'./templates/email-template.hbs'
);
const speakers = await getFiles('./speakers');
const sponsors = await getFiles('./sponsors');
const emails = await getFiles('./emails');
for (const email of Object.values(emails)) {
const { name } = path.parse(email.file);
const file = path.format({ name, ext: '.html' });
const destination = path.join(directory, file);
email.sponsor = generateSponsorMarkup(sponsors[email.sponsor]);
email.speakers = email.speakers.map(speaker => {
return generateSpeakerMarkup(speakers[speaker]);
});
const markup = generateEmailMarkup(email);
const { html, errors } = mjml(markup, mjmlOptions);
for (const error of errors) {
console.error(error);
}
fs.writeFile(destination, html, error => {
console.log(`Wrote HTML email fragement for ${name} in ${file}.`);
});
}
} catch (error) {
console.error(error);
}
});