Skip to content

Commit

Permalink
feat(nx-cloud): display current token for connect-to-nx-cloud
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bcabanes committed Jan 12, 2023
1 parent b4dbdf6 commit 0c0dd1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/nx/src/command-line/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,6 +34,10 @@ export async function connectToNxCloudCommand(
if (isNxCloudUsed()) {
output.log({
title: 'This workspace is already connected to Nx Cloud.',
bodyLines: [
'Here is the token currently used for Nx CLoud:',
getNxCloudToken(),
],
});
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/nx/src/utils/nx-cloud-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 0c0dd1d

Please sign in to comment.