Skip to content

Commit e4bcf05

Browse files
aalejjoehan
andauthored
fix issue with init hosting prompts (#9404)
* fix issue with init hosting prompts * move initGitHub back into askQuestions --------- Co-authored-by: Joe Hanley <joehanley@google.com>
1 parent d0897a2 commit e4bcf05

File tree

3 files changed

+48
-46
lines changed

3 files changed

+48
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Added `functions.list_functions` as a MCP tool (#9369)
55
- Added AI Logic to `firebase init` CLI command and `firebase_init` MCP tool. (#9185)
66
- Improved error messages for Firebase AI Logic provisioning during 'firebase init' (#9377)
7+
- Fixed issue where 'init hosting' failed to prompt for the public directory and set up Hosting files (#9403)
78
- Added `appdistribution:testcases:export` and `appdistribution:testcases:import` (#9397)
89
- Updated to v2.16.0 of the Data Connect emulator, which includes internal improvements.
910
- Data Connect now allows executing a valid query / operation even if the other operations are invalid. (This toleration provides convenience on a best-effort basis. Some errors like invalid syntax can still cause the whole request to be rejected.)

src/init/features/hosting/github.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function initGitHub(setup: Setup): Promise<void> {
5757
return reject("Could not determine Project ID, can't set up GitHub workflow.", { exit: 1 });
5858
}
5959

60-
if (!setup.config.hosting) {
60+
if (!setup.config.hosting && !setup.featureInfo?.hosting) {
6161
return reject(
6262
`Didn't find a Hosting config in firebase.json. Run ${bold("firebase init hosting")} instead.`,
6363
);
@@ -132,7 +132,7 @@ export async function initGitHub(setup: Setup): Promise<void> {
132132

133133
// If the developer is using predeploy scripts in firebase.json,
134134
// remind them before they set up a script in their workflow file.
135-
if (!Array.isArray(setup.config.hosting) && setup.config.hosting.predeploy) {
135+
if (!Array.isArray(setup.config.hosting) && setup.config.hosting?.predeploy) {
136136
logBullet(`You have a predeploy script configured in firebase.json.`);
137137
}
138138

src/init/features/hosting/index.ts

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ export async function askQuestions(setup: Setup, config: Config, options: Option
6868
}
6969
}
7070

71+
let discoveredFramework = experiments.isEnabled("webframeworks")
72+
? await discover(config.projectDir, false)
73+
: undefined;
74+
7175
if (experiments.isEnabled("webframeworks")) {
72-
let discoveredFramework = experiments.isEnabled("webframeworks")
73-
? await discover(config.projectDir, false)
74-
: undefined;
7576
// First, if we're in a framework directory, ask to use that.
7677
if (
7778
discoveredFramework &&
@@ -90,54 +91,53 @@ export async function askQuestions(setup: Setup, config: Config, options: Option
9091
`Do you want to use a web framework? (${clc.bold("experimental")})`,
9192
);
9293
}
93-
// If they say yes, ask for source directory if its not already known
94-
if (setup.featureInfo.hosting.useWebFrameworks) {
95-
setup.featureInfo.hosting.source ??= await input({
96-
message: "What folder would you like to use for your web application's root directory?",
97-
default: "hosting",
98-
});
94+
}
9995

100-
discoveredFramework = await discover(
101-
join(config.projectDir, setup.featureInfo.hosting.source),
102-
);
96+
// If they say yes, ask for source directory if its not already known
97+
if (setup.featureInfo.hosting.useWebFrameworks) {
98+
setup.featureInfo.hosting.source ??= await input({
99+
message: "What folder would you like to use for your web application's root directory?",
100+
default: "hosting",
101+
});
103102

104-
if (discoveredFramework) {
105-
const name = WebFrameworks[discoveredFramework.framework].name;
106-
setup.featureInfo.hosting.useDiscoveredFramework ??= await confirm({
107-
message: `Detected an existing ${name} codebase in ${setup.featureInfo.hosting.source}, should we use this?`,
108-
default: true,
109-
});
110-
if (setup.featureInfo.hosting.useDiscoveredFramework)
111-
setup.featureInfo.hosting.webFramework = discoveredFramework.framework;
112-
}
103+
discoveredFramework = await discover(join(config.projectDir, setup.featureInfo.hosting.source));
113104

114-
// If it is not known already, ask what framework to use.
115-
const choices: { name: string; value: string }[] = [];
116-
for (const value in WebFrameworks) {
117-
if (WebFrameworks[value]) {
118-
const { name, init } = WebFrameworks[value];
119-
if (init) choices.push({ name, value });
120-
}
105+
if (discoveredFramework) {
106+
const name = WebFrameworks[discoveredFramework.framework].name;
107+
setup.featureInfo.hosting.useDiscoveredFramework ??= await confirm({
108+
message: `Detected an existing ${name} codebase in ${setup.featureInfo.hosting.source}, should we use this?`,
109+
default: true,
110+
});
111+
if (setup.featureInfo.hosting.useDiscoveredFramework)
112+
setup.featureInfo.hosting.webFramework = discoveredFramework.framework;
113+
}
114+
115+
// If it is not known already, ask what framework to use.
116+
const choices: { name: string; value: string }[] = [];
117+
for (const value in WebFrameworks) {
118+
if (WebFrameworks[value]) {
119+
const { name, init } = WebFrameworks[value];
120+
if (init) choices.push({ name, value });
121121
}
122+
}
122123

123-
const defaultChoice = choices.find(
124-
({ value }) => value === discoveredFramework?.framework,
125-
)?.value;
124+
const defaultChoice = choices.find(
125+
({ value }) => value === discoveredFramework?.framework,
126+
)?.value;
126127

127-
setup.featureInfo.hosting.webFramework ??= await select({
128-
message: "Please choose the framework:",
129-
default: defaultChoice,
130-
choices,
131-
});
128+
setup.featureInfo.hosting.webFramework ??= await select({
129+
message: "Please choose the framework:",
130+
default: defaultChoice,
131+
choices,
132+
});
132133

133-
setup.featureInfo.hosting.region =
134-
setup.featureInfo.hosting.region ||
135-
(await select({
136-
message: "In which region would you like to host server-side content, if applicable?",
137-
default: DEFAULT_REGION,
138-
choices: ALLOWED_SSR_REGIONS.filter((region) => region.recommended),
139-
}));
140-
}
134+
setup.featureInfo.hosting.region =
135+
setup.featureInfo.hosting.region ||
136+
(await select({
137+
message: "In which region would you like to host server-side content, if applicable?",
138+
default: DEFAULT_REGION,
139+
choices: ALLOWED_SSR_REGIONS.filter((region) => region.recommended),
140+
}));
141141
} else {
142142
logger.info();
143143
logger.info(
@@ -157,6 +157,7 @@ export async function askQuestions(setup: Setup, config: Config, options: Option
157157
"Configure as a single-page app (rewrite all urls to /index.html)?",
158158
);
159159
}
160+
160161
// GitHub Action set up is still structured as doSetup
161162
if (await confirm("Set up automatic builds and deploys with GitHub?")) {
162163
return initGitHub(setup);

0 commit comments

Comments
 (0)