@@ -7,13 +7,13 @@ import { runTask } from 'src/utils/tasks.js';
77import cloudflareConfigRaw from './hosting-config/_headers.txt?raw' ;
88import netlifyConfigRaw from './hosting-config/netlify_toml.txt?raw' ;
99import vercelConfigRaw from './hosting-config/vercel.json?raw' ;
10- import { DEFAULT_VALUES , readFlag } from './options.js' ;
10+ import { DEFAULT_VALUES , readFlag , type CreateOptions } from './options.js' ;
1111
12- export async function generateHostingConfig ( dest : string , flags : { dryRun : boolean ; provider ?: string } ) {
13- let provider = readFlag ( flags , 'provider' as any ) ;
12+ export async function generateHostingConfig ( dest : string , flags : CreateOptions ) {
13+ let provider = readFlag ( flags , 'provider' ) ;
1414
1515 if ( provider === undefined ) {
16- provider = await prompts . select ( {
16+ provider = ( await prompts . select ( {
1717 message : 'Select hosting providers for automatic configuration:' ,
1818 options : [
1919 { value : 'Vercel' , label : 'Vercel' } ,
@@ -22,36 +22,39 @@ export async function generateHostingConfig(dest: string, flags: { dryRun: boole
2222 { value : 'skip' , label : 'Skip hosting configuration' } ,
2323 ] ,
2424 initialValue : DEFAULT_VALUES . provider ,
25- } ) ;
25+ } ) ) as string ;
2626 }
2727
2828 if ( provider === 'skip' ) {
2929 prompts . log . message (
30- `${ chalk . blue ( 'hosting provider config [skip]' ) } You can configure hosting provider settings manually later. For more information see https://tutorialkit.dev/guides/deployment/#headers-configuration` ,
30+ `${ chalk . blue ( 'hosting provider config [skip]' ) } You can configure hosting provider settings manually later.`
3131 ) ;
32- return ;
32+ return provider ;
3333 }
3434
3535 prompts . log . info ( `${ chalk . blue ( 'Hosting Configuration' ) } Setting up configuration for ${ provider } ` ) ;
3636
3737 const resolvedDest = path . resolve ( dest ) ;
38-
3938 if ( ! fs . existsSync ( resolvedDest ) ) {
4039 fs . mkdirSync ( resolvedDest , { recursive : true } ) ;
4140 }
4241
43- let config ;
44- let filename ;
42+ let config : string | undefined ;
43+ let filename : string | undefined ;
4544
46- if ( provider . includes ( 'Vercel' ) ) {
47- config = typeof vercelConfigRaw === 'string' ? vercelConfigRaw : JSON . stringify ( vercelConfigRaw , null , 2 ) ;
48- filename = 'vercel.json' ;
49- } else if ( provider . includes ( 'Netlify' ) ) {
50- config = netlifyConfigRaw ;
51- filename = 'netlify.toml' ;
52- } else if ( provider . includes ( 'Cloudflare' ) ) {
53- config = cloudflareConfigRaw ;
54- filename = '_headers' ;
45+ switch ( provider ) {
46+ case 'Vercel' :
47+ config = typeof vercelConfigRaw === 'string' ? vercelConfigRaw : JSON . stringify ( vercelConfigRaw , null , 2 ) ;
48+ filename = 'vercel.json' ;
49+ break ;
50+ case 'Netlify' :
51+ config = netlifyConfigRaw ;
52+ filename = 'netlify.toml' ;
53+ break ;
54+ case 'Cloudflare' :
55+ config = cloudflareConfigRaw ;
56+ filename = '_headers' ;
57+ break ;
5558 }
5659
5760 if ( config && filename ) {
@@ -62,9 +65,11 @@ export async function generateHostingConfig(dest: string, flags: { dryRun: boole
6265 task : async ( ) => {
6366 const filepath = path . join ( resolvedDest , filename ) ;
6467 fs . writeFileSync ( filepath , config ) ;
65-
6668 return `Added ${ filepath } ` ;
6769 } ,
6870 } ) ;
6971 }
72+
73+ return provider ;
7074}
75+
0 commit comments