@@ -15,12 +15,14 @@ import { trackCli } from "./tracking"
15
15
import crypto from "crypto"
16
16
import { reporter } from "./reporter"
17
17
import { setSiteMetadata } from "./site-metadata"
18
+ import { kebabify } from "./utils"
18
19
19
20
const sha256 = ( str : string ) : string =>
20
21
crypto . createHash ( `sha256` ) . update ( str ) . digest ( `hex` )
21
22
22
23
const md5 = ( str : string ) : string =>
23
24
crypto . createHash ( `md5` ) . update ( str ) . digest ( `hex` )
25
+
24
26
/**
25
27
* Hide string on windows (for emojis)
26
28
*/
@@ -67,14 +69,14 @@ export const validateProjectName = async (
67
69
68
70
// The enquirer types are not accurate
69
71
// eslint-disable-next-line @typescript-eslint/no-explicit-any
70
- export const questions : any = [
72
+ export const questions = ( initialFolderName : string ) : any => [
71
73
{
72
74
type : `textinput` ,
73
75
name : `project` ,
74
76
message : `What would you like to name the folder where your site will be created?` ,
75
77
hint : path . basename ( process . cwd ( ) ) ,
76
78
separator : `/` ,
77
- initial : `my-gatsby-site` ,
79
+ initial : initialFolderName ,
78
80
format : ( value : string ) : string => c . cyan ( value ) ,
79
81
validate : validateProjectName ,
80
82
} ,
@@ -101,6 +103,7 @@ export const questions: any = [
101
103
} ,
102
104
]
103
105
interface IAnswers {
106
+ name : string
104
107
project : string
105
108
styling ?: keyof typeof styles
106
109
cms ?: keyof typeof cmses
@@ -168,7 +171,15 @@ ${center(c.blueBright.bold.underline(`Welcome to Gatsby!`))}
168
171
169
172
enquirer . use ( plugin )
170
173
171
- const data = await enquirer . prompt ( questions )
174
+ const { name : siteName } = await enquirer . prompt ( {
175
+ type : `textinput` ,
176
+ name : `name` ,
177
+ message : `What would you like to call your site?` ,
178
+ initial : `My Gatsby Site` ,
179
+ format : ( value : string ) : string => c . cyan ( value ) ,
180
+ } as any )
181
+
182
+ const data = await enquirer . prompt ( questions ( kebabify ( siteName ) ) )
172
183
data . project = data . project . trim ( )
173
184
174
185
trackCli ( `CREATE_GATSBY_SELECT_OPTION` , {
@@ -298,7 +309,12 @@ ${c.bold(`Thanks! Here's what we'll now do:`)}
298
309
return
299
310
}
300
311
301
- await initStarter ( DEFAULT_STARTER , data . project , packages . map ( removeKey ) )
312
+ await initStarter (
313
+ DEFAULT_STARTER ,
314
+ data . project ,
315
+ packages . map ( removeKey ) ,
316
+ siteName
317
+ )
302
318
303
319
reporter . success ( `Created site in ${ c . green ( data . project ) } ` )
304
320
@@ -308,7 +324,7 @@ ${c.bold(`Thanks! Here's what we'll now do:`)}
308
324
reporter . info ( `${ w ( `🔌 ` ) } Setting-up plugins...` )
309
325
await installPlugins ( plugins , pluginConfig , fullPath , [ ] )
310
326
}
311
- await setSiteMetadata ( fullPath , `title` , data . project )
327
+ await setSiteMetadata ( fullPath , `title` , siteName )
312
328
313
329
await gitSetup ( data . project )
314
330
@@ -318,7 +334,7 @@ ${c.bold(`Thanks! Here's what we'll now do:`)}
318
334
reporter . info (
319
335
stripIndent `
320
336
${ w ( `🎉 ` ) } Your new Gatsby site ${ c . bold (
321
- data . project
337
+ siteName
322
338
) } has been successfully created
323
339
at ${ c . bold ( fullPath ) } .
324
340
`
0 commit comments