@@ -217,6 +217,32 @@ export async function updateMailTemplates() {
217
217
)
218
218
}
219
219
220
+ function extractParamsAndValue ( component : any ) : {
221
+ value : any
222
+ params : any [ ]
223
+ } {
224
+ switch ( component . declaration . type ) {
225
+ case 'FunctionDeclaration' :
226
+ return {
227
+ value : component . declaration ?. identifier ?. value ,
228
+ params : component . params ?? [ ] ,
229
+ }
230
+ case 'VariableDeclaration' :
231
+ if (
232
+ component . declaration . declarations [ 0 ] . init . type ===
233
+ 'ArrowFunctionExpression'
234
+ ) {
235
+ return {
236
+ params : component . declaration . declarations [ 0 ] . init . params ?? [ ] ,
237
+ value : component . declaration . declarations [ 0 ] . id . value ?? null ,
238
+ }
239
+ }
240
+ return { value : null , params : [ ] }
241
+ default :
242
+ return { value : null , params : [ ] }
243
+ }
244
+ }
245
+
220
246
function getMailTemplateComponents ( templateFilePath : string ) {
221
247
const ast = swc . parseFileSync ( templateFilePath , {
222
248
syntax : templateFilePath . endsWith ( '.js' ) ? 'ecmascript' : 'typescript' ,
@@ -230,8 +256,9 @@ function getMailTemplateComponents(templateFilePath: string) {
230
256
return node . type === 'ExportDeclaration'
231
257
} )
232
258
for ( let i = 0 ; i < exportedComponents . length ; i ++ ) {
259
+ const { params, value } = extractParamsAndValue ( exportedComponents [ i ] )
233
260
let propsTemplate = null
234
- const hasParams = exportedComponents [ i ] . declaration . params . length > 0
261
+ const hasParams = params . length > 0
235
262
if ( hasParams ) {
236
263
propsTemplate = 'Provide your props here as JSON'
237
264
try {
@@ -250,7 +277,7 @@ function getMailTemplateComponents(templateFilePath: string) {
250
277
}
251
278
}
252
279
components . push ( {
253
- name : exportedComponents [ i ] . declaration ?. identifier ?. value ?? 'Unknown' ,
280
+ name : value ?? 'Unknown' ,
254
281
propsTemplate,
255
282
} )
256
283
}
0 commit comments