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

fix(misc): nx view-logs should open the nx-cloud link when connected … #17808

Merged
merged 1 commit into from
Sep 6, 2023
Merged
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
110 changes: 59 additions & 51 deletions packages/nx/src/command-line/connect/view-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,68 @@ import { output } from '../../utils/output';
import { runNxSync } from '../../utils/child-process';

export async function viewLogs(): Promise<number> {
const pmc = getPackageManagerCommand();
const cloudUsed = isNxCloudUsed() && false;
if (!cloudUsed) {
const installCloud = await (
await import('enquirer')
)
.prompt([
{
name: 'NxCloud',
message: `To view the logs, Nx needs to connect your workspace to Nx Cloud and upload the most recent run details.`,
type: 'autocomplete',
choices: [
{
name: 'Yes',
hint: 'Connect to Nx Cloud and upload the run details',
},
{
name: 'No',
},
],
initial: 'Yes' as any,
},
])
.then((a: { NxCloud: 'Yes' | 'No' }) => a.NxCloud === 'Yes');
const cloudUsed = isNxCloudUsed();
if (cloudUsed) {
output.error({
title: 'Your workspace is already connected to Nx Cloud',
bodyLines: [
`Refer to the output of the last command to find the Nx Cloud link to view the run details.`,
],
});
return 1;
}

const installCloud = await (
await import('enquirer')
)
.prompt([
{
name: 'NxCloud',
message: `To view the logs, Nx needs to connect your workspace to Nx Cloud and upload the most recent run details.`,
type: 'autocomplete',
choices: [
{
name: 'Yes',
hint: 'Connect to Nx Cloud and upload the run details',
},
{
name: 'No',
},
],
initial: 'Yes' as any,
},
])
.then((a: { NxCloud: 'Yes' | 'No' }) => a.NxCloud === 'Yes');

if (!installCloud) return;
if (!installCloud) return;

try {
output.log({
title: 'Installing nx-cloud',
});
execSync(`${pmc.addDev} nx-cloud@latest`, { stdio: 'ignore' });
} catch (e) {
output.log({
title: 'Installation failed',
});
console.log(e);
return 1;
}
const pmc = getPackageManagerCommand();
try {
output.log({
title: 'Installing nx-cloud',
});
execSync(`${pmc.addDev} nx-cloud@latest`, { stdio: 'ignore' });
} catch (e) {
output.log({
title: 'Installation failed',
});
console.log(e);
return 1;
}

try {
output.log({
title: 'Connecting to Nx Cloud',
});
runNxSync(`g nx-cloud:init --installation-source=view-logs`, {
stdio: 'ignore',
});
} catch (e) {
output.log({
title: 'Failed to connect to Nx Cloud',
});
console.log(e);
return 1;
}
try {
output.log({
title: 'Connecting to Nx Cloud',
});
runNxSync(`g nx-cloud:init --installation-source=view-logs`, {
stdio: 'ignore',
});
} catch (e) {
output.log({
title: 'Failed to connect to Nx Cloud',
});
console.log(e);
return 1;
}

execSync(`${pmc.exec} nx-cloud upload-and-show-run-details`, {
Expand Down