import mjml2html from "mjml"; import MailError from "../mail/MailError"; import NunjucksViewEngine from "./NunjucksViewEngine"; export default class MailViewEngine extends NunjucksViewEngine { public getExtension(): string { return 'mnjk'; } public async render( file: string, locals: Record, textOnly: boolean = false, ): Promise { locals.text = textOnly; const nunjucksResult = await super.render(file, locals); if (textOnly) return nunjucksResult; const mjmlResult = mjml2html(nunjucksResult, {}); if (mjmlResult.errors.length > 0) { throw new MailError(`Error while parsing mail template ${file}: ${JSON.stringify(mjmlResult.errors, null, 4)}`); } return mjmlResult.html; } }