MCPcopy
hub / github.com/angular/angularfire / userPrompt

Function userPrompt

src/schematics/setup/prompts.ts:93–125  ·  view source on GitHub ↗
(options: { projectRoot: string })

Source from the content-addressed store, hash-verified

91};
92
93export const userPrompt = async (options: { projectRoot: string }): Promise<Record<string, any>> => {
94 const firebaseTools = await getFirebaseTools();
95 let loginList = await firebaseTools.login.list();
96 if (!Array.isArray(loginList) || loginList.length === 0) {
97 spawnSync('firebase login', { shell: true, cwd: options.projectRoot, stdio: 'inherit' });
98 return await firebaseTools.login(options);
99 } else {
100 const defaultUser = await firebaseTools.login(options);
101 const choices = loginList.map(({user}) => ({ name: user.email, value: user }));
102 const newChoice = { name: '[Login in with another account]', value: NEW_OPTION };
103 const { user } = await inquirer.prompt({
104 type: 'list',
105 name: 'user',
106 choices: [newChoice].concat(choices as any), // TODO types
107 message: 'Which Firebase account would you like to use?',
108 default: choices.find(it => it.value.email === defaultUser.email)?.value,
109 }) as any;
110 if (user === NEW_OPTION) {
111 spawnSync('firebase login:add', { shell: true, cwd: options.projectRoot, stdio: 'inherit' });
112 loginList = await firebaseTools.login.list();
113 if (!Array.isArray(loginList)) {
114 throw new Error("firebase login:list did not respond as expected");
115 }
116 const priorEmails = choices.map(it => it.name);
117 const newLogin = loginList.find(it => !priorEmails.includes(it.user.email));
118 if (!newLogin) {
119 throw new Error("Did not find a new user.");
120 }
121 return newLogin.user;
122 }
123 return user;
124 }
125};
126
127export const projectPrompt = async (defaultProject: string|undefined, options: unknown) => {
128 const firebaseTools = await getFirebaseTools();

Callers 1

ngAddSetupProjectFunction · 0.90

Calls 2

getFirebaseToolsFunction · 0.90
listMethod · 0.65

Tested by

no test coverage detected