1
- import { version } from '../package.json' ;
2
- import validateNpmPackage from 'validate-npm-package-name' ;
3
1
import githubUsername from 'github-username' ;
2
+ import validateNpmPackage from 'validate-npm-package-name' ;
4
3
import type yargs from 'yargs' ;
5
- import type { PromptObject } from './utils/prompts' ;
4
+ import { version } from '../package.json' ;
5
+ import type { Question } from './utils/prompt' ;
6
6
import { spawn } from './utils/spawn' ;
7
7
8
8
export type ArgName =
@@ -111,14 +111,6 @@ const TYPE_CHOICES: {
111
111
} ,
112
112
] ;
113
113
114
- export type Question = Omit <
115
- PromptObject < keyof Answers > ,
116
- 'validate' | 'name'
117
- > & {
118
- validate ?: ( value : string ) => boolean | string ;
119
- name : keyof Answers ;
120
- } ;
121
-
122
114
export const acceptedArgs : Record < ArgName , yargs . Options > = {
123
115
slug : {
124
116
description : 'Name of the npm package' ,
@@ -180,20 +172,18 @@ export type Answers = {
180
172
authorUrl : string ;
181
173
repoUrl : string ;
182
174
languages : ProjectLanguages ;
183
- type ? : ProjectType ;
184
- example ? : ExampleApp ;
175
+ type : ProjectType ;
176
+ example : ExampleApp ;
185
177
reactNativeVersion ?: string ;
186
178
local ?: boolean ;
187
179
} ;
188
180
189
181
export async function createQuestions ( {
190
182
basename,
191
183
local,
192
- argv,
193
184
} : {
194
185
basename : string ;
195
186
local : boolean ;
196
- argv : Args ;
197
187
} ) {
198
188
let name , email ;
199
189
@@ -204,7 +194,7 @@ export async function createQuestions({
204
194
// Ignore error
205
195
}
206
196
207
- const initialQuestions : Question [ ] = [
197
+ const questions : Question < keyof Answers > [ ] = [
208
198
{
209
199
type : 'text' ,
210
200
name : 'slug' ,
@@ -295,7 +285,7 @@ export async function createQuestions({
295
285
] ;
296
286
297
287
if ( ! local ) {
298
- initialQuestions . push ( {
288
+ questions . push ( {
299
289
type : 'select' ,
300
290
name : 'example' ,
301
291
message : 'What type of example app do you want to create?' ,
@@ -313,48 +303,7 @@ export async function createQuestions({
313
303
} ) ;
314
304
}
315
305
316
- const singleChoiceAnswers : Partial < Answers > = { } ;
317
- const finalQuestions : Question [ ] = [ ] ;
318
-
319
- for ( const question of initialQuestions ) {
320
- // Skip questions which are passed as parameter and pass validation
321
- const argValue = argv [ question . name ] ;
322
- if ( argValue && question . validate ?.( argValue ) !== false ) {
323
- continue ;
324
- }
325
-
326
- // Don't prompt questions with a single choice
327
- if ( Array . isArray ( question . choices ) && question . choices . length === 1 ) {
328
- const onlyChoice = question . choices [ 0 ] ! ;
329
- singleChoiceAnswers [ question . name ] = onlyChoice . value ;
330
-
331
- continue ;
332
- }
333
-
334
- const { type, choices } = question ;
335
-
336
- // Don't prompt dynamic questions with a single choice
337
- if ( type === 'select' && typeof choices === 'function' ) {
338
- question . type = ( prev , values , prompt ) => {
339
- const dynamicChoices = choices ( prev , { ...argv , ...values } , prompt ) ;
340
-
341
- if ( dynamicChoices && dynamicChoices . length === 1 ) {
342
- const onlyChoice = dynamicChoices [ 0 ] ! ;
343
- singleChoiceAnswers [ question . name ] = onlyChoice . value ;
344
- return null ;
345
- }
346
-
347
- return type ;
348
- } ;
349
- }
350
-
351
- finalQuestions . push ( question ) ;
352
- }
353
-
354
- return {
355
- questions : finalQuestions ,
356
- singleChoiceAnswers,
357
- } ;
306
+ return questions ;
358
307
}
359
308
360
309
export function createMetadata ( answers : Answers ) {
0 commit comments