@@ -7,13 +7,13 @@ import { runTask } from 'src/utils/tasks.js';
7
7
import cloudflareConfigRaw from './hosting-config/_headers.txt?raw' ;
8
8
import netlifyConfigRaw from './hosting-config/netlify_toml.txt?raw' ;
9
9
import 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' ;
11
11
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' ) ;
14
14
15
15
if ( provider === undefined ) {
16
- provider = await prompts . select ( {
16
+ provider = ( await prompts . select ( {
17
17
message : 'Select hosting providers for automatic configuration:' ,
18
18
options : [
19
19
{ value : 'Vercel' , label : 'Vercel' } ,
@@ -22,36 +22,39 @@ export async function generateHostingConfig(dest: string, flags: { dryRun: boole
22
22
{ value : 'skip' , label : 'Skip hosting configuration' } ,
23
23
] ,
24
24
initialValue : DEFAULT_VALUES . provider ,
25
- } ) ;
25
+ } ) ) as string ;
26
26
}
27
27
28
28
if ( provider === 'skip' ) {
29
29
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.`
31
31
) ;
32
- return ;
32
+ return provider ;
33
33
}
34
34
35
35
prompts . log . info ( `${ chalk . blue ( 'Hosting Configuration' ) } Setting up configuration for ${ provider } ` ) ;
36
36
37
37
const resolvedDest = path . resolve ( dest ) ;
38
-
39
38
if ( ! fs . existsSync ( resolvedDest ) ) {
40
39
fs . mkdirSync ( resolvedDest , { recursive : true } ) ;
41
40
}
42
41
43
- let config ;
44
- let filename ;
42
+ let config : string | undefined ;
43
+ let filename : string | undefined ;
45
44
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 ;
55
58
}
56
59
57
60
if ( config && filename ) {
@@ -62,9 +65,11 @@ export async function generateHostingConfig(dest: string, flags: { dryRun: boole
62
65
task : async ( ) => {
63
66
const filepath = path . join ( resolvedDest , filename ) ;
64
67
fs . writeFileSync ( filepath , config ) ;
65
-
66
68
return `Added ${ filepath } ` ;
67
69
} ,
68
70
} ) ;
69
71
}
72
+
73
+ return provider ;
70
74
}
75
+
0 commit comments