nuxt-generation-emails 1.4.1 → 1.4.3
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.
- package/dist/cli/index.mjs +7 -4
- package/dist/module.json +1 -1
- package/dist/module.mjs +16 -5
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -199,13 +199,16 @@ function createEmailFiles(targetDir, emailName, emailPath) {
|
|
|
199
199
|
const vueFile = join(targetDir, `${emailName}.vue`);
|
|
200
200
|
const mjmlFile = join(targetDir, `${emailName}.mjml`);
|
|
201
201
|
checkFileExists(vueFile);
|
|
202
|
-
checkFileExists(mjmlFile);
|
|
203
202
|
const vueTemplate = generateVueTemplate(emailName, emailPath);
|
|
204
|
-
const mjmlTemplate = generateMjmlTemplate(emailName);
|
|
205
203
|
writeFileSync(vueFile, vueTemplate, "utf-8");
|
|
206
204
|
consola.success(`Created email template: ${vueFile}`);
|
|
207
|
-
|
|
208
|
-
|
|
205
|
+
if (!existsSync(mjmlFile)) {
|
|
206
|
+
const mjmlTemplate = generateMjmlTemplate(emailName);
|
|
207
|
+
writeFileSync(mjmlFile, mjmlTemplate, "utf-8");
|
|
208
|
+
consola.success(`Created MJML template: ${mjmlFile}`);
|
|
209
|
+
} else {
|
|
210
|
+
consola.info(`MJML template already exists: ${mjmlFile} \u2014 skipping`);
|
|
211
|
+
}
|
|
209
212
|
return {
|
|
210
213
|
emailPath,
|
|
211
214
|
vueFile,
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -144,6 +144,11 @@ ${templateClose}
|
|
|
144
144
|
`;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
function extractMjmlTemplateName(filePath) {
|
|
148
|
+
const source = fs.readFileSync(filePath, "utf-8");
|
|
149
|
+
const match = source.match(/useNgeTemplate\(\s*['"]([^'"]+)['"]\s*[,)]/);
|
|
150
|
+
return match ? match[1] ?? null : null;
|
|
151
|
+
}
|
|
147
152
|
function extractPropsFromSFC(filePath) {
|
|
148
153
|
const source = fs.readFileSync(filePath, "utf-8");
|
|
149
154
|
const { descriptor } = parse(source, { filename: filePath });
|
|
@@ -568,7 +573,8 @@ function addEmailPages(dirPath, pages, options, routePrefix = "") {
|
|
|
568
573
|
}
|
|
569
574
|
}
|
|
570
575
|
|
|
571
|
-
function generateApiRoute(emailName, emailPath, examplePayload = "{}") {
|
|
576
|
+
function generateApiRoute(emailName, emailPath, examplePayload = "{}", mjmlTemplatePath) {
|
|
577
|
+
const mjmlPath = mjmlTemplatePath ?? emailPath;
|
|
572
578
|
return `/* eslint-disable */
|
|
573
579
|
// This file is generated by nuxt-generation-emails. Do not modify it manually.
|
|
574
580
|
|
|
@@ -715,7 +721,7 @@ export default defineEventHandler(async (event) => {
|
|
|
715
721
|
try {
|
|
716
722
|
const { emailsDir } = useRuntimeConfig().nuxtGenEmails as { emailsDir: string }
|
|
717
723
|
registerMjmlPartials(emailsDir)
|
|
718
|
-
const mjmlSource = readFileSync(join(emailsDir, '${
|
|
724
|
+
const mjmlSource = readFileSync(join(emailsDir, '${mjmlPath}.mjml'), 'utf-8')
|
|
719
725
|
const compiledTemplate = Handlebars.compile(mjmlSource)
|
|
720
726
|
const mjmlString = compiledTemplate(templateData)
|
|
721
727
|
const { html, errors } = await mjml2html(mjmlString)
|
|
@@ -776,9 +782,14 @@ function generateServerRoutes(emailsDir, buildDir) {
|
|
|
776
782
|
} else if (entry.endsWith(".vue")) {
|
|
777
783
|
const emailName = entry.replace(".vue", "");
|
|
778
784
|
const emailPath = `${routePrefix}/${emailName}`.replace(/^\//, "");
|
|
779
|
-
const
|
|
785
|
+
const mjmlTemplateName = extractMjmlTemplateName(fullPath);
|
|
786
|
+
if (!mjmlTemplateName) {
|
|
787
|
+
console.warn(`[nuxt-generation-emails] Could not find useNgeTemplate() call in ${emailName}.vue \u2014 skipping API route.`);
|
|
788
|
+
continue;
|
|
789
|
+
}
|
|
790
|
+
const mjmlPath = join(emailsDir, `${mjmlTemplateName}.mjml`);
|
|
780
791
|
if (!fs.existsSync(mjmlPath)) {
|
|
781
|
-
console.warn(`[nuxt-generation-emails]
|
|
792
|
+
console.warn(`[nuxt-generation-emails] MJML template "${mjmlTemplateName}.mjml" referenced by ${emailName}.vue not found \u2014 skipping API route. Expected: ${mjmlPath}`);
|
|
782
793
|
continue;
|
|
783
794
|
}
|
|
784
795
|
const handlerDir = routePrefix ? join(handlersDir, routePrefix.replace(/^\//, "")) : handlersDir;
|
|
@@ -790,7 +801,7 @@ function generateServerRoutes(emailsDir, buildDir) {
|
|
|
790
801
|
const examplePayload = Object.keys(sanitized).length > 0 ? JSON.stringify(sanitized, null, 2) : "{}";
|
|
791
802
|
const handlerFileName = `${emailName}.ts`;
|
|
792
803
|
const handlerFilePath = join(handlerDir, handlerFileName);
|
|
793
|
-
const handlerContent = generateApiRoute(emailName, emailPath, examplePayload);
|
|
804
|
+
const handlerContent = generateApiRoute(emailName, emailPath, examplePayload, mjmlTemplateName);
|
|
794
805
|
fs.writeFileSync(handlerFilePath, handlerContent, "utf-8");
|
|
795
806
|
console.log(`[nuxt-generation-emails] Generated API handler: ${handlerFilePath}`);
|
|
796
807
|
handlers.push({
|
package/package.json
CHANGED