Skip to content

Commit

Permalink
Support firebase dataconnect:sdk:generate --watch (#7719)
Browse files Browse the repository at this point in the history
* Support firebase dataconnect:sdk:generaate --watch

* Properly set --watch option.

---------

Co-authored-by: joehan <joehanley@google.com>
  • Loading branch information
rosalyntan and joehan authored Sep 24, 2024
1 parent be29bb9 commit 35d16be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/commands/dataconnect-sdk-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import { load } from "../dataconnect/load";
import { readFirebaseJson } from "../dataconnect/fileUtils";
import { logger } from "../logger";

type GenerateOptions = Options & { watch?: boolean };

export const command = new Command("dataconnect:sdk:generate")
.description("generates typed SDKs for your Data Connect connectors")
.action(async (options: Options) => {
.option(
"--watch",
"watch for changes to your connector GQL files and regenerate your SDKs when updates occur",
)
.action(async (options: GenerateOptions) => {
const projectId = needProjectId(options);

const services = readFirebaseJson(options.config);
Expand Down Expand Up @@ -39,6 +45,7 @@ export const command = new Command("dataconnect:sdk:generate")
const output = await DataConnectEmulator.generate({
configDir,
connectorId: conn.connectorYaml.connectorId,
watch: options.watch,
});
logger.info(output);
logger.info(`Generated SDKs for ${conn.connectorYaml.connectorId}`);
Expand Down
4 changes: 4 additions & 0 deletions src/emulator/dataconnectEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface DataConnectEmulatorArgs {
export interface DataConnectGenerateArgs {
configDir: string;
connectorId: string;
watch?: boolean;
}

export interface DataConnectBuildArgs {
Expand Down Expand Up @@ -184,6 +185,9 @@ export class DataConnectEmulator implements EmulatorInstance {
`--config_dir=${args.configDir}`,
`--connector_id=${args.connectorId}`,
];
if (args.watch) {
cmd.push("--watch");
}
const res = childProcess.spawnSync(commandInfo.binary, cmd, { encoding: "utf-8" });

logger.info(res.stderr);
Expand Down

0 comments on commit 35d16be

Please sign in to comment.