feat(core): remove prompt from nx connect command

This commit is contained in:
Miroslav Jonas 2024-01-09 14:57:17 +01:00 committed by Miroslav Jonaš
parent 20dcc97099
commit 67b5bd6c9f
7 changed files with 11 additions and 49 deletions

View File

@ -23,14 +23,6 @@ Type: `boolean`
Show help
### interactive
Type: `boolean`
Default: `true`
Prompt for confirmation
### version
Type: `boolean`

View File

@ -23,14 +23,6 @@ Type: `boolean`
Show help
### interactive
Type: `boolean`
Default: `true`
Prompt for confirmation
### version
Type: `boolean`

View File

@ -313,7 +313,6 @@ Merge your PR into the `main` branch when you're ready to move to the next secti
Reducing the number of tasks to run via [affected commands](/ci/features/affected) (as seen in the previous section) is helpful, but might not be enough. By default [Nx caches the results of tasks](/core-features/cache-task-results) on your local machine. But CI and local developer machines are still performing the same tasks on the same code - wasting time and money. The [Nx Cloud remote cache](/ci/features/remote-cache) can eliminate that waste for you.
```{% command="pnpm nx connect" %}
✔ Enable distributed caching to make your CI faster · Yes
$ nx g nx:connect-to-nx-cloud --quiet --no-interactive
> NX Distributed caching via Nx Cloud has been enabled

View File

@ -314,7 +314,6 @@ Merge your PR into the `main` branch when you're ready to move to the next secti
Reducing the number of tasks to run via [affected commands](/ci/features/affected) (as seen in the previous section) is helpful, but might not be enough. By default [Nx caches the results of tasks](/core-features/cache-task-results) on your local machine. But CI and local developer machines are still performing the same tasks on the same code - wasting time and money. The [Nx Cloud remote cache](/ci/features/remote-cache) can eliminate that waste for you.
```{% command="pnpm nx connect" %}
✔ Enable distributed caching to make your CI faster · Yes
> NX Distributed caching via Nx Cloud has been enabled

View File

@ -1,24 +1,13 @@
import { CommandModule } from 'yargs';
import { linkToNxDevAndExamples } from '../yargs-utils/documentation';
import type { ConnectToNxCloudOptions } from './connect-to-nx-cloud';
export const yargsConnectCommand: CommandModule<{}, ConnectToNxCloudOptions> = {
export const yargsConnectCommand: CommandModule = {
command: 'connect',
aliases: ['connect-to-nx-cloud'],
describe: `Connect workspace to Nx Cloud`,
builder: (yargs) =>
linkToNxDevAndExamples(
yargs.option('interactive', {
type: 'boolean',
description: 'Prompt for confirmation',
default: true,
}),
'connect-to-nx-cloud'
),
handler: async (options) => {
await (
await import('./connect-to-nx-cloud')
).connectToNxCloudCommand(options);
builder: (yargs) => linkToNxDevAndExamples(yargs, 'connect-to-nx-cloud'),
handler: async () => {
await (await import('./connect-to-nx-cloud')).connectToNxCloudCommand();
process.exit(0);
},
};

View File

@ -42,15 +42,7 @@ export async function connectToNxCloudIfExplicitlyAsked(
}
}
export interface ConnectToNxCloudOptions {
interactive: boolean;
promptOverride?: string;
}
export async function connectToNxCloudCommand({
promptOverride,
interactive,
}: ConnectToNxCloudOptions): Promise<boolean> {
export async function connectToNxCloudCommand(): Promise<boolean> {
const nxJson = readNxJson();
if (isNxCloudUsed(nxJson)) {
output.log({
@ -68,15 +60,13 @@ export async function connectToNxCloudCommand({
return false;
}
const res = interactive ? await connectToNxCloudPrompt(promptOverride) : true;
if (!res) return false;
runNxSync(`g nx:connect-to-nx-cloud --quiet --no-interactive`, {
stdio: [0, 1, 2],
});
return true;
}
async function connectToNxCloudPrompt(prompt?: string) {
export async function connectToNxCloudPrompt(prompt?: string) {
return await (
await import('enquirer')
)

View File

@ -49,6 +49,7 @@ import {
import { handleErrors } from '../../utils/params';
import {
connectToNxCloudCommand,
connectToNxCloudPrompt,
onlyDefaultRunnerIsUsed,
} from '../connect/connect-to-nx-cloud';
import { output } from '../../utils/output';
@ -1222,10 +1223,10 @@ async function generateMigrationsJsonAndUpdatePackageJson(
!isCI() &&
!isNxCloudUsed(originalNxJson)
) {
const useCloud = await connectToNxCloudCommand({
promptOverride: messages.getPromptMessage('nxCloudMigration'),
interactive: true,
});
const setNxCloud = await connectToNxCloudPrompt(
messages.getPromptMessage('nxCloudMigration')
);
const useCloud = setNxCloud ? await connectToNxCloudCommand() : false;
await recordStat({
command: 'migrate',
nxVersion,