Skip to content

Commit

Permalink
cleanup(core): address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Jan 12, 2024
1 parent 804220e commit b342a10
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
10 changes: 8 additions & 2 deletions docs/generated/cli/add.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand All @@ -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

Expand Down
10 changes: 8 additions & 2 deletions docs/generated/packages/nx/documents/add.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand All @@ -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

Expand Down
24 changes: 16 additions & 8 deletions packages/nx/src/command-line/add/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
output.addNewline();
export function addHandler(args: AddOptions): Promise<void> {
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.`,
});
});
}

Expand Down
13 changes: 10 additions & 3 deletions packages/nx/src/command-line/add/command-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CommandModule } from 'yargs';

export interface AddOptions {
packageSpecifier: string;
verbose?: boolean;
}

export const yargsAddCommand: CommandModule<
Expand All @@ -14,15 +15,21 @@ 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',
'Install the latest version of the `@nx/react` package and run its `@nx/react:init` generator'
)
.example(
'$0 add @nx/[email protected]',
'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)),
};
2 changes: 1 addition & 1 deletion packages/nx/src/command-line/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export const examples: Record<string, Example[]> = {
{
command: 'add @nx/[email protected]',
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',
},
],
};

0 comments on commit b342a10

Please sign in to comment.