@@ -50,6 +50,7 @@ function createTemplateFile(
50
50
templateDir : string ,
51
51
file : string ,
52
52
targetFileName ?: string ,
53
+ extraTemplateValues ?: Record < string , any > ,
53
54
) {
54
55
const templateValues = {
55
56
packageManager : options . packageManager ,
@@ -68,6 +69,7 @@ function createTemplateFile(
68
69
{ } ,
69
70
) ,
70
71
addOns : options . chosenAddOns ,
72
+ ...extraTemplateValues ,
71
73
}
72
74
73
75
const template = await readFile ( resolve ( templateDir , file ) , 'utf-8' )
@@ -300,11 +302,6 @@ export async function createApp(options: Required<Options>) {
300
302
301
303
// Setup the app component. There are four variations, typescript/javascript and tailwind/non-tailwind.
302
304
if ( options . mode === FILE_ROUTER ) {
303
- await templateFile (
304
- templateDirRouter ,
305
- './src/components/Header.tsx.ejs' ,
306
- './src/components/Header.tsx' ,
307
- )
308
305
await templateFile (
309
306
templateDirRouter ,
310
307
'./src/routes/__root.tsx.ejs' ,
@@ -330,19 +327,6 @@ export async function createApp(options: Required<Options>) {
330
327
}
331
328
}
332
329
333
- // Create the main entry point
334
- if ( ! isAddOnEnabled ( 'start' ) ) {
335
- if ( options . typescript ) {
336
- await templateFile ( templateDirRouter , './src/main.tsx.ejs' )
337
- } else {
338
- await templateFile (
339
- templateDirRouter ,
340
- './src/main.tsx.ejs' ,
341
- './src/main.jsx' ,
342
- )
343
- }
344
- }
345
-
346
330
// Setup the main, reportWebVitals and index.html files
347
331
if ( ! isAddOnEnabled ( 'start' ) && options . framework === 'react' ) {
348
332
if ( options . typescript ) {
@@ -426,6 +410,54 @@ export async function createApp(options: Required<Options>) {
426
410
}
427
411
}
428
412
413
+ const routes : Array < {
414
+ path : string
415
+ name : string
416
+ } > = [ ]
417
+ if ( existsSync ( resolve ( targetDir , 'src/routes' ) ) ) {
418
+ for ( const file of readdirSync ( resolve ( targetDir , 'src/routes' ) ) ) {
419
+ const name = file . replace ( / \. t s x ? | \. j s x ? / , '' )
420
+ routes . push ( {
421
+ path : `./routes/${ name } ` ,
422
+ name : name
423
+ . split ( '.' )
424
+ . map ( ( part ) => part . charAt ( 0 ) . toUpperCase ( ) + part . slice ( 1 ) )
425
+ . join ( '' ) ,
426
+ } )
427
+ }
428
+ }
429
+
430
+ // Create the main entry point
431
+ if ( ! isAddOnEnabled ( 'start' ) ) {
432
+ if ( options . typescript ) {
433
+ await templateFile (
434
+ templateDirRouter ,
435
+ './src/main.tsx.ejs' ,
436
+ './src/main.tsx' ,
437
+ {
438
+ routes,
439
+ } ,
440
+ )
441
+ } else {
442
+ await templateFile (
443
+ templateDirRouter ,
444
+ './src/main.jsx.ejs' ,
445
+ './src/main.jsx' ,
446
+ {
447
+ routes,
448
+ } ,
449
+ )
450
+ }
451
+ }
452
+
453
+ if ( routes . length > 0 ) {
454
+ await templateFile (
455
+ templateDirBase ,
456
+ './src/components/Header.tsx.ejs' ,
457
+ './src/components/Header.tsx' ,
458
+ )
459
+ }
460
+
429
461
const warnings : Array < string > = [ ]
430
462
for ( const addOn of options . chosenAddOns ) {
431
463
if ( addOn . warning ) {
0 commit comments