Skip to content
This repository was archived by the owner on Jun 22, 2024. It is now read-only.

Commit 783f427

Browse files
authored
fix: emails not showing on playground when using layout (#29)
1 parent 639ad67 commit 783f427

File tree

2 files changed

+85
-73
lines changed

2 files changed

+85
-73
lines changed

src/module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface ModuleOptions {
4747
autoImport?: boolean
4848
useNuxtTailwind?: boolean
4949
tailwind?: VueEmailPluginOptions['tailwind']
50+
emailsDir?: string
5051
}
5152

5253
export default defineNuxtModule<ModuleOptions>({
@@ -67,6 +68,7 @@ export default defineNuxtModule<ModuleOptions>({
6768
autoImport: false,
6869
useNuxtTailwind: true,
6970
tailwind: undefined,
71+
emailsDir: '/emails',
7072
}
7173
},
7274
async setup(options, nuxt) {
@@ -78,7 +80,7 @@ export default defineNuxtModule<ModuleOptions>({
7880
options,
7981
)
8082

81-
let tempaltesDir = '/emails'
83+
let tempaltesDir = resolve(options.emailsDir) || resolve('/emails')
8284

8385
for (const layer of nuxt.options._layers) {
8486
const templatePath = join(layer.cwd, '/emails')
@@ -90,6 +92,8 @@ export default defineNuxtModule<ModuleOptions>({
9092
break
9193
}
9294

95+
nuxt.options.runtimeConfig.public.vueEmail.emailsDir = tempaltesDir
96+
9397
if (hasNuxtModule('@nuxtjs/tailwindcss') && options.useNuxtTailwind) {
9498
// @ts-expect-error runtime type
9599
nuxt.hook('tailwindcss:resolvedConfig', (resolvedConfig) => {

src/runtime/server/api/emails.get.ts

Lines changed: 80 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,7 @@ import { createComponentMetaCheckerByJsonConfig } from 'vue-component-meta'
44
import { destr } from 'destr'
55
import JSON5 from 'json5'
66
import type { Email } from '../../types/email'
7-
import { createError, defineEventHandler, useStorage } from '#imports'
8-
9-
const rootDir = process.cwd()
10-
const checker = createComponentMetaCheckerByJsonConfig(
11-
rootDir,
12-
{
13-
extends: `${rootDir}/tsconfig.json`,
14-
skipLibCheck: true,
15-
include: ['emails/**/*'],
16-
exclude: [],
17-
},
18-
{
19-
forceUseTs: true,
20-
printer: { newLine: 1 },
21-
},
22-
)
7+
import { createError, defineEventHandler, useRuntimeConfig, useStorage } from '#imports'
238

249
function stripeTypeScriptInternalTypesSchema(type: any): any {
2510
if (!type)
@@ -55,6 +40,21 @@ function stripeTypeScriptInternalTypesSchema(type: any): any {
5540
export default defineEventHandler(async () => {
5641
try {
5742
const nitroEmails = await useStorage('assets:emails').getKeys()
43+
const rootDir = useRuntimeConfig().public.vueEmail.emailsDir || process.cwd()
44+
45+
const checker = createComponentMetaCheckerByJsonConfig(
46+
rootDir,
47+
{
48+
extends: path.join(rootDir, '..', 'tsconfig.json'),
49+
skipLibCheck: true,
50+
include: ['./emails/**/*.vue'],
51+
exclude: [],
52+
},
53+
{
54+
forceUseTs: true,
55+
printer: { newLine: 1 },
56+
},
57+
)
5858

5959
const emails: Email[] = await Promise.all(
6060
nitroEmails.map(async (email) => {
@@ -64,85 +64,93 @@ export default defineEventHandler(async () => {
6464
const emailData = JSON.parse(data)
6565
const emailPath = path.join(
6666
rootDir,
67-
'emails',
6867
email.replaceAll(':', '/'),
6968
)
70-
const { props } = checker.getComponentMeta(emailPath)
71-
let emailProps = (props).filter(prop => !prop.global).sort((a, b) => {
72-
if (!a.required && b.required)
73-
return 1
7469

75-
if (a.required && !b.required)
76-
return -1
70+
let destructuredProps = []
7771

78-
if (a.type === 'boolean' && b.type !== 'boolean')
79-
return 1
72+
try {
73+
const { props } = checker.getComponentMeta(emailPath)
74+
let emailProps = (props).filter(prop => !prop.global).sort((a, b) => {
75+
if (!a.required && b.required)
76+
return 1
8077

81-
if (a.type !== 'boolean' && b.type === 'boolean')
82-
return -1
78+
if (a.required && !b.required)
79+
return -1
8380

84-
return 0
85-
})
86-
emailProps = emailProps.map(stripeTypeScriptInternalTypesSchema)
87-
const destructuredProps = emailProps.map((prop) => {
88-
const destructuredType = prop.type.split('|').map((type) => {
89-
type = type.trim()
90-
const value = prop.default
81+
if (a.type === 'boolean' && b.type !== 'boolean')
82+
return 1
9183

92-
if (type === 'string') {
93-
return {
94-
type: 'string',
95-
value: destr(value) ?? '',
84+
if (a.type !== 'boolean' && b.type === 'boolean')
85+
return -1
86+
87+
return 0
88+
})
89+
90+
emailProps = emailProps.map(stripeTypeScriptInternalTypesSchema)
91+
destructuredProps = emailProps.map((prop) => {
92+
const destructuredType = prop.type.split('|').map((type) => {
93+
type = type.trim()
94+
const value = prop.default
95+
96+
if (type === 'string') {
97+
return {
98+
type: 'string',
99+
value: destr(value) ?? '',
100+
}
96101
}
97-
}
98102

99-
if (type === 'number') {
100-
return {
101-
type: 'number',
102-
value: destr(value) || 0,
103+
if (type === 'number') {
104+
return {
105+
type: 'number',
106+
value: destr(value) || 0,
107+
}
103108
}
104-
}
105109

106-
if (type === 'boolean') {
107-
return {
108-
type: 'boolean',
109-
value: destr(value) || false,
110+
if (type === 'boolean') {
111+
return {
112+
type: 'boolean',
113+
value: destr(value) || false,
114+
}
110115
}
111-
}
112116

113-
if (type === 'object' || type.includes('Record') || type.includes('Record<')) {
114-
return {
115-
type: 'object',
116-
value: value ? JSON5.parse(value) : {},
117+
if (type === 'object' || type.includes('Record') || type.includes('Record<')) {
118+
return {
119+
type: 'object',
120+
value: value ? JSON5.parse(value) : {},
121+
}
117122
}
118-
}
119123

120-
if (type === 'array' || type.includes('[]') || type.includes('Array') || type.includes('Array<')) {
121-
return {
122-
type: 'array',
123-
value: value ? JSON5.parse(value) : [],
124+
if (type === 'array' || type.includes('[]') || type.includes('Array') || type.includes('Array<')) {
125+
return {
126+
type: 'array',
127+
value: value ? JSON5.parse(value) : [],
128+
}
129+
}
130+
131+
if (type === 'Date') {
132+
return {
133+
type: 'date',
134+
value: value ? eval(value) : new Date().toISOString(),
135+
}
124136
}
125-
}
126137

127-
if (type === 'Date') {
128138
return {
129-
type: 'date',
130-
value: value ? eval(value) : new Date().toISOString(),
139+
type: 'string',
140+
value: value ?? '',
131141
}
132-
}
142+
})
133143

134144
return {
135-
type: 'string',
136-
value: value ?? '',
145+
label: prop.name,
146+
type: destructuredType[0].type,
147+
value: destructuredType[0].value,
137148
}
138149
})
139-
140-
return {
141-
label: prop.name,
142-
type: destructuredType[0].type,
143-
value: destructuredType[0].value,
144-
}
145-
})
150+
}
151+
catch (error) {
152+
console.warn('Error destructuring props', error)
153+
}
146154

147155
const content = (await useStorage('assets:emails').getItem(
148156
email,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy