MCPcopy
hub / github.com/resend/react-email / exportTemplates

Function exportTemplates

packages/react-email/src/cli/commands/export.ts:89–266  ·  view source on GitHub ↗
(
  pathToWhereEmailMarkupShouldBeDumped: string,
  emailsDirectoryPath: string,
  options: ExportTemplatesOptions,
)

Source from the content-addressed store, hash-verified

87 using the `render` function.
88 */
89export 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,

Callers 2

index.tsFile · 0.85
export.spec.tsFile · 0.85

Calls 15

treeFunction · 0.90
buildFunction · 0.85
onMethod · 0.80
startMethod · 0.65
succeedMethod · 0.65
setTextMethod · 0.65
createSpinnerFunction · 0.50
stopSpinnerAndPersistFunction · 0.50
inlineCssLoaderFunction · 0.50

Tested by

no test coverage detected