my-typescript-library-rahul52us 1.4.3 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,15 +16,20 @@ const handlebars_1 = __importDefault(require("handlebars"));
16
16
  const mjml_1 = __importDefault(require("mjml"));
17
17
  const fs_1 = __importDefault(require("fs"));
18
18
  const path_1 = __importDefault(require("path"));
19
+ // Ensure __dirname works (CommonJS)
20
+ const templatesDir = path_1.default.join(__dirname, '../email-templates');
19
21
  function compileEmailTemplate({ fileName, data }) {
20
22
  return __awaiter(this, void 0, void 0, function* () {
21
- const templatePath = path_1.default.resolve('src/email-templates', fileName);
22
- // Read the MJML template
23
- const mjMail = yield fs_1.default.promises.readFile(templatePath, 'utf8');
24
- // Compile with Handlebars
25
- const template = handlebars_1.default.compile(mjMail)(data);
26
- // Convert MJML to HTML
27
- return (0, mjml_1.default)(template).html.toString();
23
+ try {
24
+ const templatePath = path_1.default.join(templatesDir, fileName);
25
+ const mjMail = yield fs_1.default.promises.readFile(templatePath, 'utf8');
26
+ const template = handlebars_1.default.compile(mjMail)(data);
27
+ return (0, mjml_1.default)(template).html.toString();
28
+ }
29
+ catch (error) {
30
+ console.error(`Error reading template: ${error.message}`);
31
+ throw new Error(`Template file "${fileName}" not found in ${templatesDir}`);
32
+ }
28
33
  });
29
34
  }
30
35
  exports.default = compileEmailTemplate;
@@ -1 +1 @@
1
- {"version":3,"file":"compile-email-template.js","sourceRoot":"","sources":["../../src/helpers/compile-email-template.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,4DAAoC;AACpC,gDAA6B;AAC7B,4CAAoB;AACpB,gDAAwB;AAoBxB,SAA8B,oBAAoB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAS;;QAC1E,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;QAEnE,yBAAyB;QACzB,MAAM,MAAM,GAAG,MAAM,YAA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
2
2
  "name": "my-typescript-library-rahul52us",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "A reusable TypeScript utility library.",
5
5
  "main": "dist/server.js",
6
6
  "types": "dist/types/server.d.ts",
@@ -3,6 +3,9 @@ import mjml2html from 'mjml';
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
5
 
6
+ // Ensure __dirname works (CommonJS)
7
+ const templatesDir = path.join(__dirname, '../email-templates');
8
+
6
9
  type Props = {
7
10
  fileName: string;
8
11
  data: {
@@ -22,14 +25,13 @@ type Props = {
22
25
  };
23
26
 
24
27
  export default async function compileEmailTemplate({ fileName, data }: Props): Promise<string> {
25
- const templatePath = path.resolve('src/email-templates', fileName);
26
-
27
- // Read the MJML template
28
- const mjMail = await fs.promises.readFile(templatePath, 'utf8');
29
-
30
- // Compile with Handlebars
31
- const template = handlebars.compile(mjMail)(data);
32
-
33
- // Convert MJML to HTML
34
- return mjml2html(template).html.toString();
28
+ try {
29
+ const templatePath = path.join(templatesDir, fileName);
30
+ const mjMail = await fs.promises.readFile(templatePath, 'utf8');
31
+ const template = handlebars.compile(mjMail)(data);
32
+ return mjml2html(template).html.toString();
33
+ } catch (error: any) {
34
+ console.error(`Error reading template: ${error.message}`);
35
+ throw new Error(`Template file "${fileName}" not found in ${templatesDir}`);
36
+ }
35
37
  }