zents
Version:
ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.
31 lines • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmailTemplateLoader = void 0;
const config_1 = require("../config/config");
const FS_1 = require("../filesystem/FS");
const path_1 = require("path");
const fs_1 = require("fs");
class EmailTemplateLoader {
async load() {
const emailTemplates = new Map();
const emailFilesPath = FS_1.fs.resolveZenPath('email');
if (!((await FS_1.fs.exists(emailFilesPath)) || config_1.config.email.engine === 'plain')) {
return emailTemplates;
}
const filePaths = await this.loadFiles(emailFilesPath);
for (const filePath of filePaths) {
const { name } = path_1.parse(filePath);
const content = await fs_1.promises.readFile(filePath, {
encoding: 'utf-8',
});
emailTemplates.set(name, content);
}
return emailTemplates;
}
async loadFiles(emailFilesPath) {
const fileExtension = config_1.config.email.engine === 'mjml' ? '.mjml' : `.${config_1.config.template.extension}`;
return (await FS_1.fs.readDir(emailFilesPath)).filter((filePath) => filePath.endsWith(fileExtension));
}
}
exports.EmailTemplateLoader = EmailTemplateLoader;
//# sourceMappingURL=EmailTemplateLoader.js.map