@@ -338,10 +338,30 @@ function verifyFlags(flags: CreateOptions) {
338
338
}
339
339
}
340
340
341
- function generateHostingConfig ( dest : string , providers : string [ ] ) {
341
+ async function generateHostingConfig ( dest : string , providers : string [ ] ) {
342
+ const resolvedDest = path . resolve ( dest ) ;
343
+
344
+ if ( ! fs . existsSync ( resolvedDest ) ) {
345
+ console . log ( `Directory does not exist. Creating directory: ${ resolvedDest } ` ) ;
346
+ fs . mkdirSync ( resolvedDest , { recursive : true } ) ;
347
+ } else {
348
+ console . log ( `Directory already exists: ${ resolvedDest } ` ) ;
349
+ }
350
+
351
+ const templateDir = path . resolve ( __dirname , '_template' ) ;
352
+ console . log ( 'Looking for template directory at:' , templateDir ) ;
353
+
354
+ if ( ! fs . existsSync ( templateDir ) ) {
355
+ console . error ( 'Template directory does not exist at:' , templateDir ) ;
356
+ } else {
357
+ console . log ( 'Template directory found at:' , templateDir ) ;
358
+ }
359
+
342
360
if ( providers . includes ( 'Vercel' ) ) {
361
+ const vercelConfigPath = path . join ( resolvedDest , 'vercel.json' ) ;
362
+ console . log ( 'Vercel config file will be written to:' , vercelConfigPath ) ;
343
363
fs . writeFileSync (
344
- path . join ( dest , 'vercel.json' ) ,
364
+ vercelConfigPath ,
345
365
JSON . stringify (
346
366
{
347
367
headers : [ { source : '/(.*)' , headers : [ { key : 'Access-Control-Allow-Origin' , value : '*' } ] } ] ,
@@ -353,24 +373,40 @@ function generateHostingConfig(dest: string, providers: string[]) {
353
373
}
354
374
355
375
if ( providers . includes ( 'Netlify' ) ) {
376
+ const netlifyConfigPath = path . join ( resolvedDest , 'netlify.toml' ) ;
377
+ console . log ( 'Netlify config file will be written to:' , netlifyConfigPath ) ;
356
378
fs . writeFileSync (
357
- path . join ( dest , 'netlify.toml' ) ,
379
+ netlifyConfigPath ,
358
380
`[build]
359
381
publish = "build"
360
382
command = "npm run build"
361
383
362
- [[headers]]
384
+ [[headers]]
363
385
for = "/*"
364
386
[headers.values]
365
- Access-Control-Allow-Origin = "*"` ,
387
+ Access-Control-Allow-Origin = "*"` ,
366
388
) ;
367
389
}
368
390
369
391
if ( providers . includes ( 'Cloudflare' ) ) {
392
+ const cloudflareConfigPath = path . join ( resolvedDest , '_headers' ) ;
393
+ console . log ( 'Cloudflare config file will be written to:' , cloudflareConfigPath ) ;
370
394
fs . writeFileSync (
371
- path . join ( dest , '_headers' ) ,
395
+ cloudflareConfigPath ,
372
396
`/*
373
397
Access-Control-Allow-Origin: *` ,
374
398
) ;
375
399
}
400
+
401
+ if ( fs . existsSync ( templateDir ) ) {
402
+ const gitignoreTemplatePath = path . join ( templateDir , '.gitignore' ) ;
403
+
404
+ if ( fs . existsSync ( gitignoreTemplatePath ) ) {
405
+ const gitignoreDestPath = path . join ( resolvedDest , '.gitignore' ) ;
406
+ console . log ( 'Copying .gitignore to:' , gitignoreDestPath ) ;
407
+ fs . copyFileSync ( gitignoreTemplatePath , gitignoreDestPath ) ;
408
+ } else {
409
+ console . warn ( 'No .gitignore file found in template directory, skipping copy.' ) ;
410
+ }
411
+ }
376
412
}
0 commit comments