@@ -8,7 +8,7 @@ import { Setup } from "../..";
88import { provisionCloudSql } from "../../../dataconnect/provisionCloudSql" ;
99import { checkFreeTrialInstanceUsed , upgradeInstructions } from "../../../dataconnect/freeTrial" ;
1010import * as cloudsql from "../../../gcp/cloudsql/cloudsqladmin" ;
11- import { ensureApis , ensureSparkApis } from "../../../dataconnect/ensureApis" ;
11+ import { ensureApis , ensureGIFApis , ensureSparkApis } from "../../../dataconnect/ensureApis" ;
1212import {
1313 listLocations ,
1414 listAllServices ,
@@ -19,10 +19,12 @@ import { Schema, Service, File, Platform } from "../../../dataconnect/types";
1919import { parseCloudSQLInstanceName , parseServiceName } from "../../../dataconnect/names" ;
2020import { logger } from "../../../logger" ;
2121import { readTemplateSync } from "../../../templates" ;
22- import { logBullet , logWarning , envOverride } from "../../../utils" ;
22+ import { logBullet , logWarning , envOverride , promiseWithSpinner } from "../../../utils" ;
2323import { isBillingEnabled } from "../../../gcp/cloudbilling" ;
2424import * as sdk from "./sdk" ;
2525import { getPlatformFromFolder } from "../../../dataconnect/fileUtils" ;
26+ import { extractCodeBlock , generateSchema } from "../../../gemini/fdcExperience" ;
27+ import { configstore } from "../../../configstore" ;
2628
2729const DATACONNECT_YAML_TEMPLATE = readTemplateSync ( "init/dataconnect/dataconnect.yaml" ) ;
2830const CONNECTOR_YAML_TEMPLATE = readTemplateSync ( "init/dataconnect/connector.yaml" ) ;
@@ -103,8 +105,7 @@ export async function askQuestions(setup: Setup): Promise<void> {
103105 default : true ,
104106 } ) ) ;
105107 if ( shouldConfigureBackend ) {
106- // TODO: Prompt for app idea and use GiF backend to generate them.
107- info = await promptForService ( info ) ;
108+ info = await promptForSchema ( setup , info ) ;
108109 info = await promptForCloudSQL ( setup , info ) ;
109110
110111 info . shouldProvisionCSQL = ! ! (
@@ -444,12 +445,38 @@ async function promptForCloudSQL(setup: Setup, info: RequiredInfo): Promise<Requ
444445 return info ;
445446}
446447
447- async function promptForService ( info : RequiredInfo ) : Promise < RequiredInfo > {
448+ async function promptForSchema ( setup : Setup , info : RequiredInfo ) : Promise < RequiredInfo > {
448449 if ( info . serviceId === "" ) {
449450 info . serviceId = await input ( {
450451 message : "What ID would you like to use for this service?" ,
451452 default : basename ( process . cwd ( ) ) ,
452453 } ) ;
454+ if ( setup . projectId ) {
455+ if ( ! configstore . get ( "gemini" ) ) {
456+ logBullet (
457+ "Learn more about Gemini in Firebase and how it uses your data: https://firebase.google.com/docs/gemini-in-firebase#how-gemini-in-firebase-uses-your-data" ,
458+ ) ;
459+ }
460+ if (
461+ await confirm ( {
462+ message : `Do you want Gemini in Firebase to help generate a schema for your service?` ,
463+ default : false ,
464+ } )
465+ ) {
466+ configstore . set ( "gemini" , true ) ;
467+ await ensureGIFApis ( setup . projectId ) ;
468+ const prompt = await input ( {
469+ message : "Describe the app you are building:" ,
470+ default : "movie rating app" ,
471+ } ) ;
472+ const schema = await promiseWithSpinner (
473+ ( ) => generateSchema ( prompt , setup . projectId ! ) ,
474+ "Generating the Data Connect Schema..." ,
475+ ) ;
476+ info . schemaGql = [ { path : "schema.gql" , content : extractCodeBlock ( schema ) } ] ;
477+ info . connectors = [ emptyConnector ] ;
478+ }
479+ }
453480 }
454481 return info ;
455482}
0 commit comments