feat(nx-cloud): display current token for connect-to-nx-cloud (#14315)

This commit is contained in:
Benjamin Cabanes 2023-01-13 14:03:17 -05:00 committed by GitHub
parent 9ac1cf284a
commit 0db507394e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -2,7 +2,11 @@ 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,
getNxCloudUrl,
isNxCloudUsed,
} from '../utils/nx-cloud-utils';
export async function connectToNxCloudIfExplicitlyAsked(opts: {
[k: string]: any;
@ -33,7 +37,14 @@ export async function connectToNxCloudCommand(
): Promise<boolean> {
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:',
`${getNxCloudUrl()}'/orgs/workspace-setup?accessToken=${getNxCloudToken()}`,
],
});
return false;
}

View File

@ -6,3 +6,14 @@ export function isNxCloudUsed() {
(r) => r.runner == '@nrwl/nx-cloud'
);
}
export function getNxCloudUrl(): string {
const taskRunner = isNxCloudUsed();
if (!taskRunner) throw new Error('@nrwl/nx-cloud runner not find in nx.json');
return taskRunner.options.url || 'https://nx.app';
}
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;
}