From b342a10c2b7d97d508770196c395a66490b1dd6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Wed, 3 Jan 2024 16:12:05 +0100 Subject: [PATCH] cleanup(core): address pr feedback --- docs/generated/cli/add.md | 10 ++++++-- docs/generated/packages/nx/documents/add.md | 10 ++++++-- packages/nx/src/command-line/add/add.ts | 24 ++++++++++++------- .../nx/src/command-line/add/command-object.ts | 13 +++++++--- packages/nx/src/command-line/examples.ts | 2 +- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/docs/generated/cli/add.md b/docs/generated/cli/add.md index d87fe0369aa447..a9ad3a5eb666c5 100644 --- a/docs/generated/cli/add.md +++ b/docs/generated/cli/add.md @@ -23,7 +23,7 @@ Install the latest version of the `@nx/react` package and run its `@nx/react:ini nx add @nx/react ``` -Install the version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator: +Install version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator: ```shell nx add @nx/react@17.0.0 @@ -41,7 +41,13 @@ Show help Type: `string` -The name of an installed plugin to query +The package name and optional version (e.g. `@nx/react` or `@nx/react@latest`) to install and initialize + +### verbose + +Type: `boolean` + +Prints additional information about the commands (e.g., stack traces) ### version diff --git a/docs/generated/packages/nx/documents/add.md b/docs/generated/packages/nx/documents/add.md index d87fe0369aa447..a9ad3a5eb666c5 100644 --- a/docs/generated/packages/nx/documents/add.md +++ b/docs/generated/packages/nx/documents/add.md @@ -23,7 +23,7 @@ Install the latest version of the `@nx/react` package and run its `@nx/react:ini nx add @nx/react ``` -Install the version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator: +Install version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator: ```shell nx add @nx/react@17.0.0 @@ -41,7 +41,13 @@ Show help Type: `string` -The name of an installed plugin to query +The package name and optional version (e.g. `@nx/react` or `@nx/react@latest`) to install and initialize + +### verbose + +Type: `boolean` + +Prints additional information about the commands (e.g., stack traces) ### version diff --git a/packages/nx/src/command-line/add/add.ts b/packages/nx/src/command-line/add/add.ts index 1f817c556d5f2a..3574cb92a32f89 100644 --- a/packages/nx/src/command-line/add/add.ts +++ b/packages/nx/src/command-line/add/add.ts @@ -8,21 +8,29 @@ import { getPackageManagerCommand, type PackageManagerCommands, } from '../../utils/package-manager'; +import { handleErrors } from '../../utils/params'; import { getPluginCapabilities } from '../../utils/plugins'; import { workspaceRoot } from '../../utils/workspace-root'; import type { AddOptions } from './command-object'; -export async function addHandler(args: AddOptions): Promise { - output.addNewline(); +export function addHandler(args: AddOptions): Promise { + if (args.verbose) { + process.env.NX_VERBOSE_LOGGING = 'true'; + } + const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true'; + + return handleErrors(isVerbose, async () => { + output.addNewline(); - const pmc = getPackageManagerCommand(); - const [pkgName, version] = parsePackageSpecifier(args.packageSpecifier); + const pmc = getPackageManagerCommand(); + const [pkgName, version] = parsePackageSpecifier(args.packageSpecifier); - await installPackage(pkgName, version, pmc); - await initializePlugin(pkgName, pmc); + await installPackage(pkgName, version, pmc); + await initializePlugin(pkgName, pmc); - output.success({ - title: `Package ${pkgName} added successfully.`, + output.success({ + title: `Package ${pkgName} added successfully.`, + }); }); } diff --git a/packages/nx/src/command-line/add/command-object.ts b/packages/nx/src/command-line/add/command-object.ts index 0d1e2ec5d73cfb..48314b72a95243 100644 --- a/packages/nx/src/command-line/add/command-object.ts +++ b/packages/nx/src/command-line/add/command-object.ts @@ -2,6 +2,7 @@ import { CommandModule } from 'yargs'; export interface AddOptions { packageSpecifier: string; + verbose?: boolean; } export const yargsAddCommand: CommandModule< @@ -14,7 +15,13 @@ export const yargsAddCommand: CommandModule< yargs .positional('packageSpecifier', { type: 'string', - description: 'The name of an installed plugin to query', + description: + 'The package name and optional version (e.g. `@nx/react` or `@nx/react@latest`) to install and initialize', + }) + .option('verbose', { + type: 'boolean', + description: + 'Prints additional information about the commands (e.g., stack traces)', }) .example( '$0 add @nx/react', @@ -22,7 +29,7 @@ export const yargsAddCommand: CommandModule< ) .example( '$0 add @nx/react@17.0.0', - 'Install the version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator' - ), + 'Install version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator' + ) as any, handler: (args) => import('./add').then((m) => m.addHandler(args)), }; diff --git a/packages/nx/src/command-line/examples.ts b/packages/nx/src/command-line/examples.ts index 4ddcee361cb9db..e20a2f39e9d4c2 100644 --- a/packages/nx/src/command-line/examples.ts +++ b/packages/nx/src/command-line/examples.ts @@ -398,7 +398,7 @@ export const examples: Record = { { command: 'add @nx/react@17.0.0', description: - 'Install the version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator', + 'Install version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator', }, ], };