Skip to content

Commit 14ae689

Browse files
authored
fix(jsx-email): correct nested build output (#165)
1 parent a06095c commit 14ae689

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

apps/demo/emails/welcome emails/stripe-welcome.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const baseUrl = 'https://jsx.email/assets/demo/';
6969

7070
export const TemplateName = 'Stripe Welcome';
7171

72-
export const StripeWelcomeEmail = () => (
72+
export const Template = () => (
7373
<Html>
7474
<Head />
7575
<Preview>You're now ready to make live transactions with Stripe!</Preview>

packages/jsx-email/src/cli/commands/build.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { existsSync } from 'node:fs';
22
import { mkdir, realpath, writeFile } from 'node:fs/promises';
33
import os from 'node:os';
4-
import { basename, extname, join, resolve, win32, posix } from 'path';
4+
import { dirname, basename, extname, join, resolve, win32, posix } from 'path';
55
import { pathToFileURL } from 'url';
66

77
import chalk from 'chalk';
@@ -58,7 +58,8 @@ Builds a template and saves the result
5858
// Credit: https://github.com/rollup/plugins/blob/master/packages/pluginutils/src/normalizePath.ts#L5
5959
const normalizePath = (filename: string) => filename.split(win32.sep).join(posix.sep);
6060

61-
export const build = async (path: string, argv: BuildOptions) => {
61+
// FIXME: in v2 change the signature to an object
62+
export const build = async (path: string, argv: BuildOptions, outputBasePath?: string) => {
6263
const { out, plain, props = '{}', writeToFile = true } = argv;
6364
const platformPath = isWindows ? pathToFileURL(normalizePath(path)).toString() : path;
6465
const template = await import(platformPath);
@@ -96,9 +97,15 @@ export const build = async (path: string, argv: BuildOptions) => {
9697
process.exit(1);
9798
}
9899

100+
await mkdir(out!, { recursive: true });
101+
99102
const buildProps = JSON.parse(props);
100103
const component = componentExport(buildProps);
101-
const writePath = join(out!, basename(path).replace(extname(path), extension));
104+
const writePath = outputBasePath
105+
? join(out!, path.replace(outputBasePath, '').replace(extname(path), extension))
106+
: join(out!, basename(path).replace(extname(path), extension));
107+
108+
await mkdir(dirname(writePath), { recursive: true });
102109

103110
if (plain) {
104111
const plainText = await render(component, { plainText: plain });
@@ -108,7 +115,6 @@ export const build = async (path: string, argv: BuildOptions) => {
108115

109116
const html = await render(component, argv as any);
110117

111-
await mkdir(out!, { recursive: true });
112118
if (writeToFile) await writeFile(writePath, html, 'utf8');
113119

114120
return html;
@@ -125,7 +131,7 @@ const compile = async (files: string[], outDir: string) => {
125131
write: true
126132
});
127133

128-
return globby([normalizePath(join(outDir, '*.js'))]);
134+
return globby([normalizePath(join(outDir, '**/*.js'))]);
129135
};
130136

131137
export const buildTemplates = async (target: string, options: BuildOptionsInternal) => {
@@ -150,7 +156,7 @@ export const buildTemplates = async (target: string, options: BuildOptionsIntern
150156
compiledFiles.map(async (filePath, index) => {
151157
const result = {
152158
fileName: targetFiles[index],
153-
html: await build(filePath, { ...options, out: outputPath })
159+
html: await build(filePath, { ...options, out: outputPath }, esbuildOutPath)
154160
};
155161

156162
if (showStats) {

0 commit comments

Comments
 (0)