Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Added `firebase dataconnect:compile` command.
- Loads experiments earlier in CLI startup so they can be used earlier. (#9797)
- Fixed issue where Storage security rules is overwritten when running `firebase init storage`. (#8170)
75 changes: 75 additions & 0 deletions src/commands/dataconnect-compile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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, false);
}

// 2. Generate SDKs
await DataConnectEmulator.generate({
configDir,
account,
});

logLabeledSuccess(
"dataconnect",
`Successfully compiled Data Connect service: ${clc.bold(serviceInfo.dataConnectYaml.serviceId)}`,
);
}
});
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { CLIClient } from "../command";
import * as experiments from "../experiments";

type CommandRunner = ((...args: any[]) => Promise<any>) & { load: () => void };

Check warning on line 4 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 4 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

/**
* Loads all commands for our parser.
*/
export function load(client: CLIClient): CLIClient {
function loadCommand(name: string): CommandRunner {
const load = () => {

Check warning on line 11 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
const { command: cmd } = require(`./${name}`);

Check warning on line 12 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement

Check warning on line 12 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
cmd.register(client);

Check warning on line 13 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value

Check warning on line 13 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .register on an `any` value
return cmd.runner();

Check warning on line 14 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value

Check warning on line 14 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .runner on an `any` value

Check warning on line 14 in src/commands/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value
};

const runner = (async (...args: any[]) => {
Expand Down Expand Up @@ -254,6 +254,7 @@
client.dataconnect.sql.migrate = loadCommand("dataconnect-sql-migrate");
client.dataconnect.sql.grant = loadCommand("dataconnect-sql-grant");
client.dataconnect.sql.shell = loadCommand("dataconnect-sql-shell");
client.dataconnect.compile = loadCommand("dataconnect-compile");
client.dataconnect.sdk = {};
client.dataconnect.sdk.generate = loadCommand("dataconnect-sdk-generate");
client.target = loadCommand("target");
Expand Down
Loading