Enhance firebase init apphosting to support local source deploys#8479
Enhance firebase init apphosting to support local source deploys#8479blidd-google merged 8 commits intomasterfrom
firebase init apphosting to support local source deploys#8479Conversation
src/init/features/apphosting.ts
Outdated
|
|
||
| const webApp = await webApps.getOrCreateWebApp( | ||
| projectId, | ||
| "1:319766234289:web:318a6b73ce925a813bce90", |
There was a problem hiding this comment.
was this left in from debugging?
src/init/features/apphosting.ts
Outdated
| webApp?.id, | ||
| ); | ||
| createBackendSpinner.succeed(`Successfully created backend!\n\t${backend.name}\n`); | ||
| } else { |
There was a problem hiding this comment.
readability nit: would be great if we checked createOrLink === "link" first and by the time the reader gets to else we still have context on what we were "if-else"-ing
src/init/features/apphosting.ts
Outdated
| name: "rootDir", | ||
| type: "input", | ||
| default: "/", | ||
| message: "Specify your app's root directory", |
There was a problem hiding this comment.
I think it's worth specifying "relative to the current directory" or "relative to the firebase.json directory".
Otherwise user could give some ~/path/to/cwd which i believe would error because the absRootDir would not be valid.
src/init/features/apphosting.ts
Outdated
| const backendId = await promptOnce({ | ||
| name: "backendId", | ||
| type: "input", | ||
| message: "Provide a backend name:", |
There was a problem hiding this comment.
I think it would be a better UX if we called apphosting.listbackends and made the user choose from a known list.
There was a problem hiding this comment.
If it doesn't already exist in https://github.com/firebase/firebase-tools/blob/master/src/apphosting/backend.ts
i think it would be good to put such a helper function there and call it here.
There was a problem hiding this comment.
Hi, can you help me with my app hosting that I'm stuck with firebase CLI
src/init/features/apphosting.ts
Outdated
| null, | ||
| undefined, |
There was a problem hiding this comment.
nit: whenever we're putting in undefined / null where it's not clear based on variable name what parameter this is, could we add some inline comments like
/* serviceAccount = */ null,
/* repository = */ undefined,
annajowang
left a comment
There was a problem hiding this comment.
approval once some comments are addressed
src/init/features/apphosting.ts
Outdated
| async function promptExistingBackend(projectId: string): Promise<string> { | ||
| const { backends } = await listBackends(projectId, "-"); | ||
| const backendId = await promptOnce({ | ||
| type: "autocomplete", | ||
| name: "backendId", | ||
| message: "Which backend would you like to link?", | ||
| source: (_: any, input = ""): Promise<(inquirer.DistinctChoice | inquirer.Separator)[]> => { | ||
| return new Promise((resolve) => | ||
| resolve([ | ||
| ...fuzzy | ||
| .filter(input, backends, { | ||
| extract: (backend) => parseBackendName(backend.name).id, | ||
| }) | ||
| .map((result) => { | ||
| return { | ||
| name: parseBackendName(result.original.name).id, | ||
| value: parseBackendName(result.original.name).id, | ||
| }; | ||
| }), | ||
| ]), | ||
| ); | ||
| }, | ||
| }); | ||
| return backendId; | ||
| } |
There was a problem hiding this comment.
Can you put this function in https://github.com/firebase/firebase-tools/blob/master/src/apphosting/backend.ts
src/init/features/apphosting.ts
Outdated
| webApp?.id, | ||
| ); | ||
| createBackendSpinner.succeed(`Successfully created backend!\n\t${backend.name}\n`); | ||
| } else { |
There was a problem hiding this comment.
there is 0% chance that "createLink" is something other than "link" or "create". If we are pretty certain that something won't happen, it's not worth clouding the code to catch those cases. I would keep the code cleaner with just:
if (createOrLink === "link") {
backendConfig.backendId = await promptExistingBackend(projectId);
} else {
....
}
…8479) * expand init apphosting to modify firebase.json, optionally create backend * regen schema * minor fixes & use fuzzy search for backends
In order to support deploys from local source to App Hosting, the CLI needs a way to identify which backend to target with the local source code.
firebase init apphostingprovides an interactive flow to guide users through the process of either creating a new backend or linking an existing backend to a local app, then writes the configuration tofirebase.jsonunder a new section identified by keyapphosting.