Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/demo/emails/welcome emails/stripe-welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const baseUrl = 'https://jsx.email/assets/demo/';

export const TemplateName = 'Stripe Welcome';

export const StripeWelcomeEmail = () => (
export const Template = () => (
<Html>
<Head />
<Preview>You're now ready to make live transactions with Stripe!</Preview>
Expand Down
18 changes: 12 additions & 6 deletions packages/jsx-email/src/cli/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync } from 'node:fs';
import { mkdir, realpath, writeFile } from 'node:fs/promises';
import os from 'node:os';
import { basename, extname, join, resolve, win32, posix } from 'path';
import { dirname, basename, extname, join, resolve, win32, posix } from 'path';
import { pathToFileURL } from 'url';

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

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

await mkdir(out!, { recursive: true });

const buildProps = JSON.parse(props);
const component = componentExport(buildProps);
const writePath = join(out!, basename(path).replace(extname(path), extension));
const writePath = outputBasePath
? join(out!, path.replace(outputBasePath, '').replace(extname(path), extension))
: join(out!, basename(path).replace(extname(path), extension));

await mkdir(dirname(writePath), { recursive: true });

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

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

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

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

return globby([normalizePath(join(outDir, '*.js'))]);
return globby([normalizePath(join(outDir, '**/*.js'))]);
};

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

if (showStats) {
Expand Down