Skip to content
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

Add support for anonymous usage of the generate CLI #4239

Merged
merged 2 commits into from
Aug 9, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,6 +79,9 @@ export async function generateWorkspace({
context
});
} else {
if (!token) {
return context.failAndThrow("Please run fern login");
}
await runRemoteGenerationForAPIWorkspace({
projectConfig,
organization,
Expand Down
26 changes: 15 additions & 11 deletions packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -34,18 +34,22 @@ export async function generateAPIWorkspaces({
preview: boolean;
mode: GenerationMode | undefined;
}): Promise<void> {
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({
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/posthog-manager/src/getPosthogManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export async function getPosthogManager(): Promise<PosthogManager> {
async function createPosthogManager(): Promise<PosthogManager> {
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();
Expand Down
Loading