UNPKG

@webtre/nestjs-mailer-react-adapter

Version:
55 lines (54 loc) 2.03 kB
var __defProp = Object.defineProperty; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; // src/react.adapter.tsx import path from "node:path"; import { pathToFileURL } from "node:url"; import { render } from "@react-email/render"; import { getModuleExport, load } from "locter"; import { jsx } from "react/jsx-runtime"; var ReactAdapter = class { constructor(config) { this.config = { pretty: false, plainText: false }; Object.assign(this.config, config); } compile(mail, callback, options) { const { context, template } = mail.data; const templateExt = path.extname(template) || ".js"; const templateName = path.basename(template, templateExt); const templateDir = path.isAbsolute(template) ? path.dirname(template) : path.join(options.template.dir, path.dirname(template)); const templatePath = path.join(templateDir, templateName + templateExt); const templatePathFileURL = pathToFileURL(templatePath).href; load(templatePathFileURL).then((tmplModule) => { const moduleDefault = getModuleExport( tmplModule, (key) => key === "default" ); const Comp = moduleDefault.value; return render(/* @__PURE__ */ jsx(Comp, __spreadValues({}, context)), this.config); }).then((html) => { mail.data.html = html; return callback(); }).catch(callback); } }; export { ReactAdapter }; //# sourceMappingURL=index.mjs.map