-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Adding dataconnect:compile command #9727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| - Removed MCP tools and prompts that required Gemini in Firebase terms of service. | ||
| - Fixes an issue where the `--only` flag was not always respected for `firebase mcp` | ||
| - Removed timeout when connecting to Cloud SQL. Hopefully, should mitigate issue #9314. (#9725) | ||
| - Added `firebase dataconnect:compile` command. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,81 @@ | ||||||
| import * as clc from "colorette"; | ||||||
|
|
||||||
| import { Command } from "../command"; | ||||||
| import { Options } from "../options"; | ||||||
| import { DataConnectEmulator } from "../emulator/dataconnectEmulator"; | ||||||
| import { getProjectId } from "../projectUtils"; | ||||||
| import { pickServices } from "../dataconnect/load"; | ||||||
| import { getProjectDefaultAccount } from "../auth"; | ||||||
| import { logLabeledSuccess } from "../utils"; | ||||||
| import { EmulatorHub } from "../emulator/hub"; | ||||||
| import { handleBuildErrors } from "../dataconnect/build"; | ||||||
| import { FirebaseError } from "../error"; | ||||||
|
|
||||||
| type CompileOptions = Options & { service?: string; location?: string }; | ||||||
|
|
||||||
| export const command = new Command("dataconnect:compile") | ||||||
| .description("compile your Data Connect schema and connector config and GQL files.") | ||||||
| .option( | ||||||
| "--service <serviceId>", | ||||||
| "the serviceId of the Data Connect service. If not provided, compiles all services.", | ||||||
| ) | ||||||
| .option( | ||||||
| "--location <location>", | ||||||
| "the location of the Data Connect service. Only needed if service ID is used in multiple locations.", | ||||||
| ) | ||||||
| .action(async (options: CompileOptions) => { | ||||||
| const projectId = getProjectId(options); | ||||||
|
|
||||||
| const config = options.config; | ||||||
| if (!config || !config.has("dataconnect")) { | ||||||
| throw new FirebaseError( | ||||||
| `No Data Connect project directory found. Please run ${clc.bold("firebase init dataconnect")} to set it up first.`, | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| const serviceInfos = await pickServices( | ||||||
| projectId || EmulatorHub.MISSING_PROJECT_PLACEHOLDER, | ||||||
| config, | ||||||
| options.service, | ||||||
| options.location, | ||||||
| ); | ||||||
|
|
||||||
| if (!serviceInfos.length) { | ||||||
| throw new FirebaseError("No Data Connect services found to compile."); | ||||||
| } | ||||||
|
|
||||||
| for (const serviceInfo of serviceInfos) { | ||||||
| const configDir = serviceInfo.sourceDirectory; | ||||||
| const account = getProjectDefaultAccount(options.projectRoot); | ||||||
|
|
||||||
| // 1. Build (Validate Schema/Connectors + Generate .dataconnect) | ||||||
| const buildArgs = { | ||||||
| configDir, | ||||||
| projectId, // Optional, passes to fdc build --project_id if present | ||||||
| account, | ||||||
| }; | ||||||
|
|
||||||
| const buildResult = await DataConnectEmulator.build(buildArgs); | ||||||
|
|
||||||
| if (buildResult?.errors?.length) { | ||||||
| await handleBuildErrors( | ||||||
| buildResult.errors, | ||||||
| options.nonInteractive, | ||||||
| options.force, | ||||||
| !!options.dryRun, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For clarity and to avoid potential confusion, it's better to pass
Suggested change
|
||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| // 2. Generate SDKs | ||||||
| // api-proposal says: "Generates or updates the local .dataconnect/ metadata folder and generated SDKs" | ||||||
| await DataConnectEmulator.generate({ | ||||||
| configDir, | ||||||
| account, | ||||||
| }); | ||||||
|
|
||||||
| logLabeledSuccess( | ||||||
| "dataconnect", | ||||||
| `Successfully compiled Data Connect service: ${clc.bold(serviceInfo.dataConnectYaml.serviceId)}`, | ||||||
| ); | ||||||
| } | ||||||
| }); | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command's description is slightly incomplete. In addition to compiling schema and connector files, the command also generates typed SDKs via
DataConnectEmulator.generate. To avoid user surprise and accurately reflect the command's full functionality, I recommend updating the description.