From 8cc90e5bfdde10b7759a1a2271f21338d90ab2eb Mon Sep 17 00:00:00 2001 From: Antonio Molner Domenech Date: Thu, 8 Aug 2024 21:08:41 +0100 Subject: [PATCH 1/2] Add support running local generators without token --- .../commands/generate/generateAPIWorkspace.ts | 5 +++- .../generate/generateAPIWorkspaces.ts | 26 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts b/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts index 7cdf69181da..464a20ebbda 100644 --- a/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts +++ b/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts @@ -34,7 +34,7 @@ export async function generateWorkspace({ version: string | undefined; groupName: string | undefined; shouldLogS3Url: boolean; - token: FernToken; + token: FernToken | undefined; useLocalDocker: boolean; keepDocker: boolean; absolutePathToPreview: AbsoluteFilePath | undefined; @@ -79,6 +79,9 @@ export async function generateWorkspace({ context }); } else { + if (!token) { + return context.failAndThrow("Please run fern login"); + } await runRemoteGenerationForAPIWorkspace({ projectConfig, organization, diff --git a/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts b/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts index c1e8c224d5a..f7894b46e7b 100644 --- a/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts +++ b/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts @@ -1,4 +1,4 @@ -import { createOrganizationIfDoesNotExist } from "@fern-api/auth"; +import { createOrganizationIfDoesNotExist, FernToken, FernUserToken } from "@fern-api/auth"; import { Values } from "@fern-api/core-utils"; import { join, RelativeFilePath } from "@fern-api/fs-utils"; import { askToLogin } from "@fern-api/login"; @@ -34,18 +34,22 @@ export async function generateAPIWorkspaces({ preview: boolean; mode: GenerationMode | undefined; }): Promise { - const token = await cliContext.runTask(async (context) => { - return askToLogin(context); - }); + let token: FernToken | undefined = undefined; - if (token.type === "user") { - await cliContext.runTask(async (context) => { - await createOrganizationIfDoesNotExist({ - organization: project.config.organization, - token, - context - }); + if (!useLocalDocker) { + const currentToken = await cliContext.runTask(async (context) => { + return askToLogin(context); }); + if (currentToken.type === "user") { + await cliContext.runTask(async (context) => { + await createOrganizationIfDoesNotExist({ + organization: project.config.organization, + token: currentToken, + context + }); + }); + } + token = currentToken; } cliContext.instrumentPostHogEvent({ From e63bd89a12e2af0a11e82c0e8e53c8ba437b2ed7 Mon Sep 17 00:00:00 2001 From: Antonio Molner Domenech Date: Thu, 8 Aug 2024 21:29:47 +0100 Subject: [PATCH 2/2] Add support for disabling telemetry --- packages/cli/posthog-manager/src/getPosthogManager.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/cli/posthog-manager/src/getPosthogManager.ts b/packages/cli/posthog-manager/src/getPosthogManager.ts index 4fa9af00976..34382095175 100644 --- a/packages/cli/posthog-manager/src/getPosthogManager.ts +++ b/packages/cli/posthog-manager/src/getPosthogManager.ts @@ -16,7 +16,8 @@ export async function getPosthogManager(): Promise { async function createPosthogManager(): Promise { try { const posthogApiKey = process.env.POSTHOG_API_KEY; - if (posthogApiKey == null) { + const disableTelemetry = process.env.FERN_DISABLE_TELEMETRY === "true"; + if (posthogApiKey == null || disableTelemetry) { return new NoopPosthogManager(); } const userToken = await getUserToken();