From d145e2576746408d0c3142793afe3f2bcb89b226 Mon Sep 17 00:00:00 2001 From: Ben <3447705+bcabanes@users.noreply.github.com> Date: Thu, 12 Jan 2023 12:11:26 -0500 Subject: [PATCH] feat(nx-cloud): display current token for connect-to-nx-cloud It displays the current token used by the runner when a workspace is already connected to Nx Cloud. This will allow developers to not have to go find the access token them selve when they manually want to claim a workspace. --- packages/nx/src/command-line/connect.ts | 12 ++++++++++-- packages/nx/src/utils/nx-cloud-utils.ts | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/nx/src/command-line/connect.ts b/packages/nx/src/command-line/connect.ts index 8dae10475cf3f0..1a62da6658ef73 100644 --- a/packages/nx/src/command-line/connect.ts +++ b/packages/nx/src/command-line/connect.ts @@ -2,7 +2,7 @@ import { output } from '../utils/output'; import { getPackageManagerCommand } from '../utils/package-manager'; import { execSync } from 'child_process'; import { readNxJson } from '../config/configuration'; -import { isNxCloudUsed } from '../utils/nx-cloud-utils'; +import { getNxCloudToken, isNxCloudUsed } from '../utils/nx-cloud-utils'; export async function connectToNxCloudIfExplicitlyAsked(opts: { [k: string]: any; @@ -33,7 +33,15 @@ export async function connectToNxCloudCommand( ): Promise { if (isNxCloudUsed()) { output.log({ - title: 'This workspace is already connected to Nx Cloud.', + title: '✅ This workspace is already connected to Nx Cloud.', + bodyLines: [ + 'This means your workspace can use computation caching, distributed task execution, and show you run analytics.', + 'Go to https://nx.app to learn more.', + ' ', + 'If you have not done so already, please claim this workspace:', + 'https://cloud.nx.app/orgs/workspace-setup?accessToken=' + + getNxCloudToken(), + ], }); return false; } diff --git a/packages/nx/src/utils/nx-cloud-utils.ts b/packages/nx/src/utils/nx-cloud-utils.ts index 8544f544699a15..5e6e0da5e4c677 100644 --- a/packages/nx/src/utils/nx-cloud-utils.ts +++ b/packages/nx/src/utils/nx-cloud-utils.ts @@ -6,3 +6,9 @@ export function isNxCloudUsed() { (r) => r.runner == '@nrwl/nx-cloud' ); } + +export function getNxCloudToken(): string { + const taskRunner = isNxCloudUsed(); + if (!taskRunner) throw new Error('@nrwl/nx-cloud runner not find in nx.json'); + return taskRunner.options.accessToken; +}