Skip to content

Commit

Permalink
Merge pull request #2698 from hashicorp/fix-watch-telemetry
Browse files Browse the repository at this point in the history
fix(cli): fix watch telemetry
  • Loading branch information
ansgarm authored Mar 8, 2023
2 parents 01b3c04 + 5934c1d commit 304ef28
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
10 changes: 8 additions & 2 deletions packages/@cdktf/cli-core/src/lib/cdktf-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MPL-2.0
import { AbortController, AbortSignal } from "node-abort-controller"; // polyfill until we update to node 16
import { Errors, ensureAllSettledBeforeThrowing, logger } from "@cdktf/commons";
import { SynthesizedStack, SynthStack } from "./synth-stack";
import { SynthesizedStack, SynthOrigin, SynthStack } from "./synth-stack";
import { printAnnotations } from "./synth";
import {
CdktfStack,
Expand Down Expand Up @@ -120,6 +120,7 @@ export type CdktfProjectOptions = {
onUpdate: (update: ProjectUpdate) => void;
onLog?: (log: LogMessage) => void;
workingDirectory?: string;
synthOrigin?: SynthOrigin;
};
export class CdktfProject {
public stacks?: SynthesizedStack[];
Expand All @@ -131,6 +132,7 @@ export class CdktfProject {
private onUpdate: (update: ProjectUpdate) => void;
private onLog?: (log: LogMessage) => void;
private abortSignal: AbortSignal;
private synthOrigin?: SynthOrigin;

// Set during deploy / destroy
public stacksToRun: CdktfStack[] = [];
Expand All @@ -146,6 +148,7 @@ export class CdktfProject {
onUpdate,
onLog,
workingDirectory = process.cwd(),
synthOrigin,
}: CdktfProjectOptions) {
this.synthCommand = synthCommand;
this.outDir = outDir;
Expand All @@ -154,6 +157,7 @@ export class CdktfProject {
this.onLog = onLog;
const ac = new AbortController();
this.abortSignal = ac.signal;
this.synthOrigin = synthOrigin;

this.hardAbort = ac.abort.bind(ac);
this.ioHandler = new CdktfProjectIOHandler();
Expand Down Expand Up @@ -338,7 +342,9 @@ export class CdktfProject {
this.abortSignal,
this.synthCommand,
this.outDir,
this.workingDirectory
this.workingDirectory,
false,
this.synthOrigin
);

printAnnotations(stacks);
Expand Down
2 changes: 1 addition & 1 deletion packages/@cdktf/cli-core/src/lib/synth-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface ManifestJson {
stacks: StackManifest[];
}

type SynthOrigin = "watch";
export type SynthOrigin = "watch";

export class SynthStack {
public static async synth(
Expand Down
5 changes: 4 additions & 1 deletion packages/@cdktf/cli-core/src/lib/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "./cdktf-project";
import * as fs from "fs";
import * as chokidar from "chokidar";
import { logger, Errors } from "@cdktf/commons";
import { logger, Errors, sendTelemetry } from "@cdktf/commons";
import { CdktfStack } from "./cdktf-stack";

// In this very first iteration we will find out which files to watch by asking the user to provide the files
Expand Down Expand Up @@ -109,6 +109,7 @@ export async function watch(
async function run() {
logger.debug("Running cdktf deploy");
const project = new CdktfProject({
synthOrigin: "watch",
...projectOptions,
onLog: (log) => {
if (projectOptions.onLog) {
Expand Down Expand Up @@ -172,4 +173,6 @@ export async function watch(
watcher.on("all", onFileChange);
// initially run once
onFileChange();

await sendTelemetry("watch", { event: "start" });
}
2 changes: 1 addition & 1 deletion tools/generate-function-bindings/scripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* SPDX-License-Identifier: MPL-2.0
*/

export const FUNCTIONS_METADATA_FILE = "functions.json";
export const FUNCTIONS_METADATA_FILE = "functions.json";
2 changes: 1 addition & 1 deletion tools/generate-function-bindings/scripts/fetch-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ async function fetchMetadata() {
await fs.writeFile(out, prettier.format(json, { parser: "json" }));
}

fetchMetadata();
fetchMetadata();

0 comments on commit 304ef28

Please sign in to comment.