11import type StarlightPluginGenerator from '../index.js'
22import type { Configuration } from '../index.js'
33
4- import { validateEmoji , validateName , validateNonEmptyString } from './validator.js'
4+ import { validateEmoji , validateLayer , validateName , validateNonEmptyString } from './validator.js'
55
66export async function promptForName ( generator : StarlightPluginGenerator ) {
77 const name = generator . options . name
@@ -15,16 +15,38 @@ export async function promptForName(generator: StarlightPluginGenerator) {
1515 type : 'input' ,
1616 name : 'name' ,
1717 message : 'What is the name of your Starlight plugin?' ,
18- default : ` starlight-plugin-name` ,
18+ default : ' starlight-plugin-name' ,
1919 validate : validateName ,
2020 } )
2121
2222 generator . configuration . name = answers . name
2323}
2424
25+ export async function promptForTheme ( generator : StarlightPluginGenerator ) {
26+ const theme = generator . options . theme
27+
28+ if ( theme !== undefined ) {
29+ generator . configuration . theme = theme
30+ return
31+ }
32+
33+ const answers = await generator . prompt < { theme : boolean } > ( {
34+ type : 'list' ,
35+ name : 'theme' ,
36+ message : 'Is your plugin a theme?' ,
37+ choices : [
38+ { name : 'Yes' , value : true } ,
39+ { name : 'No' , value : false } ,
40+ ] ,
41+ default : false ,
42+ } )
43+
44+ generator . configuration . theme = answers . theme
45+ }
46+
2547export async function promptForText (
2648 generator : StarlightPluginGenerator ,
27- key : keyof Configuration ,
49+ key : TextConfigurationKeys ,
2850 message : string ,
2951 defaultValue : string ,
3052) {
@@ -65,3 +87,28 @@ export async function promptForEmoji(generator: StarlightPluginGenerator) {
6587
6688 generator . configuration . emoji = answers . emoji
6789}
90+
91+ export async function promptForLayer ( generator : StarlightPluginGenerator ) {
92+ const layer = generator . options . layer
93+
94+ if ( layer && validateLayer ( layer ) === true ) {
95+ generator . configuration . layer = layer
96+ return
97+ }
98+
99+ const answers = await generator . prompt < { layer : string } > ( {
100+ type : 'input' ,
101+ name : 'layer' ,
102+ message : 'What is the name of your theme CSS cascade layer?' ,
103+ default : `my-theme` ,
104+ validate : validateLayer ,
105+ } )
106+
107+ generator . configuration . layer = answers . layer
108+ }
109+
110+ type TextConfigurationKeys = NonNullable <
111+ {
112+ [ K in keyof Configuration ] : Configuration [ K ] extends string | undefined ? K : never
113+ } [ keyof Configuration ]
114+ >
0 commit comments