Skip to content

Commit 6b1e98b

Browse files
committed
move the default value to actuate
1 parent 8e2f27d commit 6b1e98b

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

src/init/features/dataconnect/index.ts

+14-22
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export async function askQuestions(setup: Setup): Promise<void> {
9393
shouldProvisionCSQL: false,
9494
};
9595
// Query backend and pick up any existing services quickly.
96-
info = await promptForExistingServices(setup, info, hasBilling);
96+
info = await promptForExistingServices(setup, info);
9797

9898
const requiredConfigUnset =
9999
info.serviceId === "" ||
@@ -110,6 +110,7 @@ export async function askQuestions(setup: Setup): Promise<void> {
110110
default: true,
111111
}));
112112
if (shouldConfigureBackend) {
113+
// TODO: Prompt for app idea and use GiF backend to generate them.
113114
info = await promptForService(info);
114115
info = await promptForCloudSQL(setup, info);
115116

@@ -122,14 +123,6 @@ export async function askQuestions(setup: Setup): Promise<void> {
122123
default: true,
123124
}))
124125
);
125-
} else {
126-
// Ensure that the suggested name is DNS compatible
127-
const defaultServiceId = toDNSCompatibleId(basename(process.cwd()));
128-
info.serviceId = info.serviceId || defaultServiceId;
129-
info.cloudSqlInstanceId =
130-
info.cloudSqlInstanceId || `${info.serviceId.toLowerCase() || "app"}-fdc`;
131-
info.locationId = info.locationId || `us-central1`;
132-
info.cloudSqlDatabase = info.cloudSqlDatabase || `fdcdb`;
133126
}
134127
setup.featureInfo = setup.featureInfo || {};
135128
setup.featureInfo.dataconnect = info;
@@ -147,6 +140,14 @@ export async function actuate(setup: Setup, config: Config): Promise<void> {
147140
if (!info) {
148141
throw new Error("Data Connect feature RequiredInfo is not provided");
149142
}
143+
// Populate the default values of required fields.
144+
const defaultServiceId = toDNSCompatibleId(basename(process.cwd()));
145+
info.serviceId = info.serviceId || defaultServiceId;
146+
info.cloudSqlInstanceId =
147+
info.cloudSqlInstanceId || `${info.serviceId.toLowerCase() || "app"}-fdc`;
148+
info.locationId = info.locationId || `us-central1`;
149+
info.cloudSqlDatabase = info.cloudSqlDatabase || `fdcdb`;
150+
150151
await writeFiles(config, info);
151152

152153
if (setup.projectId && info.shouldProvisionCSQL) {
@@ -266,24 +267,15 @@ function subConnectorYamlValues(replacementValues: { connectorId: string }): str
266267
return replaced;
267268
}
268269

269-
async function promptForExistingServices(
270-
setup: Setup,
271-
info: RequiredInfo,
272-
isBillingEnabled: boolean,
273-
): Promise<RequiredInfo> {
274-
if (!setup.projectId || !isBillingEnabled) {
275-
// TODO(b/368609569): Don't gate this behind billing once backend billing fix is rolled out.
270+
async function promptForExistingServices(setup: Setup, info: RequiredInfo): Promise<RequiredInfo> {
271+
// Check for existing Firebase Data Connect services.
272+
if (!setup.projectId) {
276273
return info;
277274
}
278-
279-
// Check for existing Firebase Data Connect services.
280275
const existingServices = await listAllServices(setup.projectId);
281276
const existingServicesAndSchemas = await Promise.all(
282277
existingServices.map(async (s) => {
283-
return {
284-
service: s,
285-
schema: await getSchema(s.name),
286-
};
278+
return { service: s, schema: await getSchema(s.name) };
287279
}),
288280
);
289281
if (existingServicesAndSchemas.length) {

0 commit comments

Comments
 (0)