(templatePath: string)
| 168 | const dir = path.dirname(templatePath); |
| 169 | const contentPath = path.join(dir, "content.hbs"); |
| 170 | const variablesPath = path.join(dir, "variables.json"); |
| 171 | |
| 172 | const dummyData: Record<string, unknown> = fs.existsSync(variablesPath) |
| 173 | ? generateDummyData(variablesPath) |
| 174 | : {}; |
| 175 | |
| 176 | let content = ""; |
| 177 | |
| 178 | if (fs.existsSync(contentPath)) { |
| 179 | const contentSource = fs.readFileSync(contentPath, "utf8"); |
| 180 | const contentTemplate = Handlebars.compile(contentSource); |
| 181 | |
| 182 | content = contentTemplate(dummyData); |
| 183 | } |
| 184 | |
| 185 | const html = template({ ...dummyData, content }); |
| 186 | |
| 187 | const relativePath = path.relative(TEMPLATES_DIR, templatePath); |
| 188 | const outputDir = path.dirname(relativePath); |
| 189 | const templateName = path.basename(relativePath, ".hbs"); |
| 190 | const outputPath = path.join(PREVIEW_DIR, outputDir, templateName + ".html"); |
| 191 | |
| 192 | const previewWrapper = `<!DOCTYPE html> |
| 193 | <html lang="en"> |
| 194 | <head> |
| 195 | <meta charset="UTF-8"> |
| 196 | <title>${templateName} - Email Preview</title> |
| 197 | <style> |
| 198 | body { margin: 0; padding: 20px; background: #1a1a1a; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; } |
| 199 | .preview-header { max-width: 1200px; margin: 0 auto 20px; background: #2D2D2D; border: 1px solid #404040; border-radius: 8px; padding: 16px 20px; color: #E8E8E8; font-size: 18px; font-weight: 600; } |
| 200 | .email-wrapper { max-width: 1200px; margin: 0 auto; } |
| 201 | </style> |
| 202 | </head> |
| 203 | <body> |
| 204 | <div class="preview-header">${templateName.replace(/-/g, " ").replace(/\b\w/g, (initial) => initial.toUpperCase())}</div> |
| 205 | <div class="email-wrapper">${html}</div> |
| 206 | </body> |
| 207 | </html>`; |
| 208 | |
| 209 | fs.ensureDirSync(path.dirname(outputPath)); |
| 210 | fs.writeFileSync(outputPath, previewWrapper, "utf8"); |
| 211 | |
| 212 | const pathRel = path |
| 213 | .join(outputDir, templateName + ".html") |
| 214 | .replace(/\\/g, "/"); |
| 215 | |
| 216 | return { |
| 217 | name: templateName, |
| 218 | category: outputDir.split(path.sep)[0] ?? "", |
| 219 | pathRel, |
| 220 | }; |
| 221 | }; |
| 222 | |
| 223 | const generateIndex = (templates: ITemplateMetadata[]): void => { |
| 224 | const categories: Record<string, ITemplateMetadata[]> = {}; |
| 225 | |
| 226 | for (const template of templates) { |
| 227 | const bucket = categories[template.category] ?? []; |
nothing calls this directly
no test coverage detected