@@ -118,9 +118,35 @@ export const featuresPrompt = async (): Promise<FEATURES[]> => {
118
118
return features ;
119
119
} ;
120
120
121
- export const projectPrompt = async ( defaultProject ?: string ) => {
121
+ export const userPrompt = async ( options : { } ) : Promise < Record < string , any > > => {
122
122
const firebaseTools = await getFirebaseTools ( ) ;
123
- const projects = firebaseTools . projects . list ( { } ) ;
123
+ const users = await firebaseTools . login . list ( ) ;
124
+ if ( ! users || users . length === 0 ) {
125
+ await firebaseTools . login ( ) ; // first login isn't returning anything of value
126
+ const user = await firebaseTools . login ( options ) ;
127
+ return user ;
128
+ } else {
129
+ const defaultUser = await firebaseTools . login ( options ) ;
130
+ const choices = users . map ( ( { user} ) => ( { name : user . email , value : user } ) ) ;
131
+ const newChoice = { name : '[Login in with another account]' , value : NEW_OPTION } ;
132
+ const { user } = await inquirer . prompt ( {
133
+ type : 'list' ,
134
+ name : 'user' ,
135
+ choices : [ newChoice ] . concat ( choices as any ) , // TODO types
136
+ message : 'Which Firebase account would you like to use?' ,
137
+ default : choices . find ( it => it . value . email === defaultUser . email ) ?. value ,
138
+ } ) ;
139
+ if ( user === NEW_OPTION ) {
140
+ const { user } = await firebaseTools . login . add ( ) ;
141
+ return user ;
142
+ }
143
+ return user ;
144
+ }
145
+ } ;
146
+
147
+ export const projectPrompt = async ( defaultProject : string | undefined , options : { } ) => {
148
+ const firebaseTools = await getFirebaseTools ( ) ;
149
+ const projects = firebaseTools . projects . list ( options ) ;
124
150
const { projectId } = await autocomplete ( {
125
151
type : 'autocomplete' ,
126
152
name : 'projectId' ,
@@ -140,15 +166,15 @@ export const projectPrompt = async (defaultProject?: string) => {
140
166
message : 'What would you like to call your project?' ,
141
167
default : projectId ,
142
168
} ) ;
143
- return await firebaseTools . projects . create ( projectId , { displayName, nonInteractive : true } ) ;
169
+ return await firebaseTools . projects . create ( projectId , { ... options , displayName, nonInteractive : true } ) ;
144
170
}
145
171
// tslint:disable-next-line:no-non-null-assertion
146
172
return ( await projects ) . find ( it => it . projectId === projectId ) ! ;
147
173
} ;
148
174
149
- export const appPrompt = async ( { projectId : project } : FirebaseProject , defaultAppId : string | undefined ) => {
175
+ export const appPrompt = async ( { projectId : project } : FirebaseProject , defaultAppId : string | undefined , options : { } ) => {
150
176
const firebaseTools = await getFirebaseTools ( ) ;
151
- const apps = firebaseTools . apps . list ( 'web' , { project } ) ;
177
+ const apps = firebaseTools . apps . list ( 'web' , { ... options , project } ) ;
152
178
const { appId } = await autocomplete ( {
153
179
type : 'autocomplete' ,
154
180
name : 'appId' ,
@@ -162,18 +188,15 @@ export const appPrompt = async ({ projectId: project }: FirebaseProject, default
162
188
name : 'displayName' ,
163
189
message : 'What would you like to call your app?' ,
164
190
} ) ;
165
- return await firebaseTools . apps . create ( 'web' , displayName , { nonInteractive : true , project } ) ;
191
+ return await firebaseTools . apps . create ( 'web' , displayName , { ... options , nonInteractive : true , project } ) ;
166
192
}
167
193
// tslint:disable-next-line:no-non-null-assertion
168
194
return ( await apps ) . find ( it => shortAppId ( it ) === appId ) ! ;
169
195
} ;
170
196
171
- export const sitePrompt = async ( { projectId : project } : FirebaseProject ) => {
197
+ export const sitePrompt = async ( { projectId : project } : FirebaseProject , options : { } ) => {
172
198
const firebaseTools = await getFirebaseTools ( ) ;
173
- if ( ! firebaseTools . hosting . sites ) {
174
- return undefined ;
175
- }
176
- const sites = firebaseTools . hosting . sites . list ( { project } ) . then ( it => {
199
+ const sites = firebaseTools . hosting . sites . list ( { ...options , project } ) . then ( it => {
177
200
if ( it . sites . length === 0 ) {
178
201
// newly created projects don't return their default site, stub one
179
202
return [ {
@@ -199,24 +222,12 @@ export const sitePrompt = async ({ projectId: project }: FirebaseProject) => {
199
222
name : 'subdomain' ,
200
223
message : 'Please provide an unique, URL-friendly id for the site (<id>.web.app):' ,
201
224
} ) ;
202
- return await firebaseTools . hosting . sites . create ( subdomain , { nonInteractive : true , project } ) ;
225
+ return await firebaseTools . hosting . sites . create ( subdomain , { ... options , nonInteractive : true , project } ) ;
203
226
}
204
227
// tslint:disable-next-line:no-non-null-assertion
205
228
return ( await sites ) . find ( it => shortSiteName ( it ) === siteName ) ! ;
206
229
} ;
207
230
208
- export const prerenderPrompt = ( project : WorkspaceProject , prerender : boolean ) : Promise < { projectType : PROJECT_TYPE } > => {
209
- if ( isUniversalApp ( project ) ) {
210
- return inquirer . prompt ( {
211
- type : 'prompt' ,
212
- name : 'prerender' ,
213
- message : 'We detected an Angular Universal project. How would you like to render server-side content?' ,
214
- default : true
215
- } ) ;
216
- }
217
- return Promise . resolve ( { projectType : PROJECT_TYPE . Static } ) ;
218
- } ;
219
-
220
231
export const projectTypePrompt = async ( project : WorkspaceProject , name : string ) => {
221
232
let prerender = false ;
222
233
let nodeVersion : string | undefined ;
0 commit comments