@@ -118,9 +118,35 @@ export const featuresPrompt = async (): Promise<FEATURES[]> => {
118118 return features ;
119119} ;
120120
121- export const projectPrompt = async ( defaultProject ?: string ) => {
121+ export const userPrompt = async ( options : { } ) : Promise < Record < string , any > > => {
122122 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 ) ;
124150 const { projectId } = await autocomplete ( {
125151 type : 'autocomplete' ,
126152 name : 'projectId' ,
@@ -140,15 +166,15 @@ export const projectPrompt = async (defaultProject?: string) => {
140166 message : 'What would you like to call your project?' ,
141167 default : projectId ,
142168 } ) ;
143- return await firebaseTools . projects . create ( projectId , { displayName, nonInteractive : true } ) ;
169+ return await firebaseTools . projects . create ( projectId , { ... options , displayName, nonInteractive : true } ) ;
144170 }
145171 // tslint:disable-next-line:no-non-null-assertion
146172 return ( await projects ) . find ( it => it . projectId === projectId ) ! ;
147173} ;
148174
149- export const appPrompt = async ( { projectId : project } : FirebaseProject , defaultAppId : string | undefined ) => {
175+ export const appPrompt = async ( { projectId : project } : FirebaseProject , defaultAppId : string | undefined , options : { } ) => {
150176 const firebaseTools = await getFirebaseTools ( ) ;
151- const apps = firebaseTools . apps . list ( 'web' , { project } ) ;
177+ const apps = firebaseTools . apps . list ( 'web' , { ... options , project } ) ;
152178 const { appId } = await autocomplete ( {
153179 type : 'autocomplete' ,
154180 name : 'appId' ,
@@ -162,18 +188,15 @@ export const appPrompt = async ({ projectId: project }: FirebaseProject, default
162188 name : 'displayName' ,
163189 message : 'What would you like to call your app?' ,
164190 } ) ;
165- return await firebaseTools . apps . create ( 'web' , displayName , { nonInteractive : true , project } ) ;
191+ return await firebaseTools . apps . create ( 'web' , displayName , { ... options , nonInteractive : true , project } ) ;
166192 }
167193 // tslint:disable-next-line:no-non-null-assertion
168194 return ( await apps ) . find ( it => shortAppId ( it ) === appId ) ! ;
169195} ;
170196
171- export const sitePrompt = async ( { projectId : project } : FirebaseProject ) => {
197+ export const sitePrompt = async ( { projectId : project } : FirebaseProject , options : { } ) => {
172198 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 => {
177200 if ( it . sites . length === 0 ) {
178201 // newly created projects don't return their default site, stub one
179202 return [ {
@@ -199,24 +222,12 @@ export const sitePrompt = async ({ projectId: project }: FirebaseProject) => {
199222 name : 'subdomain' ,
200223 message : 'Please provide an unique, URL-friendly id for the site (<id>.web.app):' ,
201224 } ) ;
202- return await firebaseTools . hosting . sites . create ( subdomain , { nonInteractive : true , project } ) ;
225+ return await firebaseTools . hosting . sites . create ( subdomain , { ... options , nonInteractive : true , project } ) ;
203226 }
204227 // tslint:disable-next-line:no-non-null-assertion
205228 return ( await sites ) . find ( it => shortSiteName ( it ) === siteName ) ! ;
206229} ;
207230
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-
220231export const projectTypePrompt = async ( project : WorkspaceProject , name : string ) => {
221232 let prerender = false ;
222233 let nodeVersion : string | undefined ;
0 commit comments