@@ -13,6 +13,18 @@ const defaultSettings = {
13
13
userName : '\r' ,
14
14
} ;
15
15
16
+ const defaultProjectSettings = {
17
+ name : '\r' ,
18
+ envName : 'integtest' ,
19
+ editor : '\r' ,
20
+ frontendType : 'javascript' ,
21
+ framework : 'none' ,
22
+ srcDir : '\r' ,
23
+ distDir : '\r' ,
24
+ buildCmd : '\r' ,
25
+ startCmd : '\r' ,
26
+ } ;
27
+
16
28
export const amplifyRegions = [
17
29
'us-east-1' ,
18
30
'us-east-2' ,
@@ -34,8 +46,11 @@ export const amplifyRegions = [
34
46
'sa-east-1' ,
35
47
] ;
36
48
37
- const configurationOptions = [ 'project' , 'profile' , 'containers' ] ;
38
- const profileOptions = [ 'cancel' , 'update' , 'remove' ] ;
49
+ const configurationOptions = [ 'Project information' , 'AWS Profile setting' , 'Advanced: Container-based deployments' ] ;
50
+ const profileOptions = [ 'No' , 'Update AWS Profile' , 'Remove AWS Profile' ] ;
51
+ const authenticationOptions = [ 'AWS profile' , 'AWS access keys' ] ;
52
+ const javaScriptFrameworkList = [ 'none' , 'angular' , 'ember' , 'ionic' , 'react' , 'react-native' , 'vue' ] ;
53
+
39
54
40
55
const MANDATORY_PARAMS = [ 'accessKeyId' , 'secretAccessKey' , 'region' ] ;
41
56
@@ -77,18 +92,52 @@ export function amplifyConfigure(settings: AmplifyConfiguration): Promise<void>
77
92
} ) ;
78
93
}
79
94
80
- export function amplifyConfigureProject ( settings : { cwd : string ; enableContainers : boolean } ) : Promise < void > {
81
- const { enableContainers = false , cwd } = settings ;
95
+ export function amplifyConfigureProject ( settings : {
96
+ cwd : string ;
97
+ enableContainers ?: boolean ;
98
+ configLevel ?: string ;
99
+ profileOption ?: string ;
100
+ authenticationOption ?: string ;
101
+ region ?: string ;
102
+ } ) : Promise < void > {
103
+ const {
104
+ cwd,
105
+ enableContainers = false ,
106
+ profileOption = profileOptions [ 0 ] ,
107
+ authenticationOption,
108
+ configLevel = 'project' ,
109
+ region = defaultSettings . region ,
110
+ } = settings ;
82
111
83
112
return new Promise ( ( resolve , reject ) => {
84
113
const chain = spawn ( getCLIPath ( ) , [ 'configure' , 'project' ] , { cwd, stripColors : true } ) . wait ( 'Which setting do you want to configure?' ) ;
114
+
85
115
if ( enableContainers ) {
86
- singleSelect ( chain , 'containers' , configurationOptions ) ;
87
- chain . wait ( 'Do you want to enable container-based deployments?' ) . sendLine ( 'y' ) ;
116
+ singleSelect ( chain , configurationOptions [ 2 ] , configurationOptions ) ;
117
+ chain . wait ( 'Do you want to enable container-based deployments?' ) . sendConfirmYes ( ) ;
88
118
} else {
89
- singleSelect ( chain , 'profile' , configurationOptions ) ;
90
- chain . wait ( 'Do you want to update or remove the project level AWS profile?' ) ;
91
- singleSelect ( chain , profileOptions [ 0 ] , profileOptions ) ;
119
+ singleSelect ( chain , configurationOptions [ 1 ] , configurationOptions ) ;
120
+
121
+ if ( configLevel === 'project' ) {
122
+ chain . wait ( 'Do you want to update or remove the project level AWS profile?' ) ;
123
+ singleSelect ( chain , profileOption , profileOptions ) ;
124
+ } else {
125
+ chain . wait ( 'Do you want to set the project level configuration' ) . sendConfirmYes ( ) ;
126
+ }
127
+
128
+ if ( profileOption === profileOptions [ 1 ] || configLevel === 'general' ) {
129
+ chain . wait ( 'Select the authentication method you want to use:' ) ;
130
+ singleSelect ( chain , authenticationOption , authenticationOptions ) ;
131
+
132
+ if ( authenticationOption === authenticationOptions [ 0 ] ) {
133
+ chain . wait ( 'Please choose the profile you want to use' ) . sendCarriageReturn ( ) ; // Default profile
134
+ } else if ( authenticationOption === authenticationOptions [ 1 ] ) {
135
+ chain . wait ( 'accessKeyId:' ) . sendLine ( process . env . AWS_ACCESS_KEY_ID ) ;
136
+ chain . wait ( 'secretAccessKey:' ) . sendLine ( process . env . AWS_SECRET_ACCESS_KEY ) ;
137
+ chain . wait ( 'region:' ) ;
138
+ singleSelect ( chain , region , amplifyRegions ) ;
139
+ }
140
+ }
92
141
}
93
142
94
143
chain . wait ( 'Successfully made configuration changes to your project.' ) . run ( ( err : Error ) => {
@@ -100,3 +149,64 @@ export function amplifyConfigureProject(settings: { cwd: string; enableContainer
100
149
} ) ;
101
150
} ) ;
102
151
}
152
+
153
+ export function amplifyConfigureProjectInfo ( settings : {
154
+ cwd : string ,
155
+ frontendType : string ,
156
+ } ) : Promise < void > {
157
+ const {
158
+ cwd,
159
+ } = settings ;
160
+ const s = { ...defaultProjectSettings , ...settings } ;
161
+ return new Promise ( ( resolve , reject ) => {
162
+ const chain = spawn ( getCLIPath ( ) , [ 'configure' , 'project' ] , { cwd, stripColors : true } ) . wait ( 'Which setting do you want to configure?' ) ;
163
+ singleSelect ( chain , configurationOptions [ 0 ] , configurationOptions ) ;
164
+ chain
165
+ . wait ( 'Enter a name for the project' )
166
+ . sendLine ( s . name )
167
+ . wait ( 'Choose your default editor:' )
168
+ . sendLine ( s . editor )
169
+ . wait ( "Choose the type of app that you're building" )
170
+ . sendLine ( s . frontendType ) ;
171
+
172
+ switch ( s . frontendType ) {
173
+ case 'javascript' :
174
+ chain . wait ( 'What javascript framework are you using' ) ;
175
+ singleSelect ( chain , s . framework , javaScriptFrameworkList ) ;
176
+ chain
177
+ . wait ( 'Source Directory Path:' )
178
+ . sendLine ( s . srcDir )
179
+ . wait ( 'Distribution Directory Path:' )
180
+ . sendLine ( s . distDir )
181
+ . wait ( 'Build Command:' )
182
+ . sendLine ( s . buildCmd )
183
+ . wait ( 'Start Command:' )
184
+ . sendLine ( s . startCmd ) ;
185
+ break ;
186
+ case 'android' :
187
+ chain
188
+ . wait ( 'Where is your Res directory' )
189
+ . sendLine ( s . srcDir ) ;
190
+ break ;
191
+ case 'ios' :
192
+ break ;
193
+ case 'flutter' :
194
+ chain
195
+ . wait ( 'Where do you want to store your configuration file?' )
196
+ . sendLine ( s . srcDir ) ;
197
+ break ;
198
+ default :
199
+ throw new Error ( `Frontend type ${ s . frontendType } is not supported.` ) ;
200
+ }
201
+
202
+ chain
203
+ . wait ( 'Successfully made configuration changes to your project.' )
204
+ . run ( ( err : Error ) => {
205
+ if ( ! err ) {
206
+ resolve ( ) ;
207
+ } else {
208
+ reject ( err ) ;
209
+ }
210
+ } ) ;
211
+ } )
212
+ }
0 commit comments