1
1
import { Toolbox } from 'gluegun/build/types/domain/toolbox' ;
2
- import { confirm , isCancel , cancel , multiselect , select } from '@clack/prompts' ;
2
+ import { confirm , isCancel , cancel , multiselect , select , text } from '@clack/prompts' ;
3
3
4
4
import { defaultOptions } from '../constants' ;
5
5
import {
@@ -12,6 +12,7 @@ import {
12
12
StylingSelect
13
13
} from '../types' ;
14
14
import { getDefaultPackageManagerVersion } from './getPackageManager' ;
15
+ import { loadConfigs , saveConfig } from './configStorage' ;
15
16
16
17
const recommendedBunVersion = '1.0.14' ;
17
18
@@ -30,6 +31,47 @@ export async function runCLI(toolbox: Toolbox, projectName: string): Promise<Cli
30
31
31
32
// Clear default packages
32
33
cliResults . packages = [ ] ;
34
+
35
+ // Check whether the user has any saved create expo stack configurations
36
+ const savedConfigs = await loadConfigs ( ) ;
37
+
38
+ // If the user has saved configurations, ask if they would like to use them
39
+ if ( savedConfigs . length > 0 ) {
40
+ const useSavedConfig = await confirm ( {
41
+ message : 'Would you like to use a saved configuration?' ,
42
+ initialValue : false
43
+ } ) ;
44
+
45
+ if ( isCancel ( useSavedConfig ) ) {
46
+ cancel ( 'Cancelled... 👋' ) ;
47
+ return process . exit ( 0 ) ;
48
+ }
49
+
50
+ if ( useSavedConfig ) {
51
+ const savedConfigSelect = await select ( {
52
+ message : 'Which saved configuration would you like to use?' ,
53
+ options : savedConfigs . map ( ( config ) => ( { value : config . name , label : config . name } ) )
54
+ } ) ;
55
+
56
+ if ( isCancel ( savedConfigSelect ) ) {
57
+ cancel ( 'Cancelled... 👋' ) ;
58
+ return process . exit ( 0 ) ;
59
+ }
60
+
61
+ const selectedConfig = savedConfigs . find ( ( config ) => config . name === savedConfigSelect ) ;
62
+
63
+ if ( selectedConfig ) {
64
+ cliResults . packages = selectedConfig . cliResults . packages ;
65
+ cliResults . flags = selectedConfig . cliResults . flags ;
66
+ success ( `Using saved configuration: ${ selectedConfig . name } ` ) ;
67
+
68
+ return cliResults ;
69
+ } else {
70
+ warning ( 'Saved configuration not found, continuing with default configuration.' ) ;
71
+ }
72
+ }
73
+ }
74
+
33
75
// Ask about TypeScript
34
76
const shouldUseTypescript = await confirm ( {
35
77
message : 'Would you like to use TypeScript with this project?' ,
@@ -327,18 +369,31 @@ export async function runCLI(toolbox: Toolbox, projectName: string): Promise<Cli
327
369
} else {
328
370
success ( `No problem, skipping authentication for now.` ) ;
329
371
}
372
+ }
330
373
331
- const internationalizationSelect = await confirm ( {
332
- message : `What would you like to support internationalization?` ,
333
- initialValue : false
374
+ // Offer user ability to save configuration
375
+ const shouldSaveConfig = await confirm ( {
376
+ message : 'Would you like to save this configuration for future use?' ,
377
+ initialValue : false
378
+ } ) ;
379
+
380
+ if ( isCancel ( shouldSaveConfig ) ) {
381
+ cancel ( 'Cancelled... 👋' ) ;
382
+ return process . exit ( 0 ) ;
383
+ }
384
+
385
+ if ( shouldSaveConfig ) {
386
+ const name = await text ( {
387
+ message : 'What do you want to name this configuration?' ,
388
+ placeholder : 'Default'
334
389
} ) ;
335
390
336
- if ( internationalizationSelect ) {
337
- cliResults . packages . push ( { name : 'i18next' , type : 'internationalization' } ) ;
338
- success ( `You'll be using i18next for internationalization.` ) ;
339
- } else {
340
- success ( `No problem, skipping internationalization for now.` ) ;
391
+ if ( isCancel ( name ) ) {
392
+ cancel ( 'Cancelled... 👋' ) ;
393
+ return process . exit ( 0 ) ;
341
394
}
395
+
396
+ await saveConfig ( { name, cliResults } ) ;
342
397
}
343
398
344
399
return cliResults ;
0 commit comments