( pathToWhereEmailMarkupShouldBeDumped: string, emailsDirectoryPath: string, options: ExportTemplatesOptions, )
| 87 | using the `render` function. |
| 88 | */ |
| 89 | export const exportTemplates = async ( |
| 90 | pathToWhereEmailMarkupShouldBeDumped: string, |
| 91 | emailsDirectoryPath: string, |
| 92 | options: ExportTemplatesOptions, |
| 93 | ) => { |
| 94 | let spinner: Spinner | undefined; |
| 95 | if (!options.silent) { |
| 96 | spinner = createSpinner('Preparing files...\n'); |
| 97 | spinner.start(); |
| 98 | registerSpinnerAutostopping(spinner); |
| 99 | } |
| 100 | |
| 101 | const emailsDirectoryMetadata = await getEmailsDirectoryMetadata( |
| 102 | path.resolve(process.cwd(), emailsDirectoryPath), |
| 103 | true, |
| 104 | ); |
| 105 | |
| 106 | if (typeof emailsDirectoryMetadata === 'undefined') { |
| 107 | if (spinner) { |
| 108 | stopSpinnerAndPersist(spinner, { |
| 109 | symbol: logSymbols.error, |
| 110 | text: `Could not find the directory at ${emailsDirectoryPath}`, |
| 111 | }); |
| 112 | } else { |
| 113 | console.error(`Could not find the directory at ${emailsDirectoryPath}`); |
| 114 | } |
| 115 | process.exit(1); |
| 116 | } |
| 117 | |
| 118 | if (fs.existsSync(pathToWhereEmailMarkupShouldBeDumped)) { |
| 119 | fs.rmSync(pathToWhereEmailMarkupShouldBeDumped, { recursive: true }); |
| 120 | } |
| 121 | |
| 122 | const allTemplates = getEmailTemplatesFromDirectory(emailsDirectoryMetadata); |
| 123 | |
| 124 | try { |
| 125 | for (let i = 0; i < allTemplates.length; i += BUILD_BATCH_SIZE) { |
| 126 | const batch = allTemplates.slice(i, i + BUILD_BATCH_SIZE); |
| 127 | await build({ |
| 128 | bundle: true, |
| 129 | entryPoints: batch, |
| 130 | external: ['css-tree'], |
| 131 | format: 'cjs', |
| 132 | jsx: 'automatic', |
| 133 | loader: { '.js': 'jsx' }, |
| 134 | logLevel: 'silent', |
| 135 | outExtension: { '.js': '.cjs' }, |
| 136 | outdir: pathToWhereEmailMarkupShouldBeDumped, |
| 137 | platform: 'node', |
| 138 | plugins: [inlineCssLoader(), renderingUtilitiesExporter(batch)], |
| 139 | write: true, |
| 140 | }); |
| 141 | await stop(); |
| 142 | } |
| 143 | } catch (exception) { |
| 144 | if (spinner) { |
| 145 | stopSpinnerAndPersist(spinner, { |
| 146 | symbol: logSymbols.error, |
no test coverage detected