Skip to content

Commit

Permalink
feat(core): add the "add" cli command (#20976)
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez authored Jan 17, 2024
1 parent 6141f44 commit 28438bb
Show file tree
Hide file tree
Showing 19 changed files with 542 additions and 64 deletions.
62 changes: 62 additions & 0 deletions docs/generated/cli/add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: 'add - CLI command'
description: 'Install a plugin and initialize it.'
---

# add

Install a plugin and initialize it.

## Usage

```shell
nx add <packageSpecifier>
```

Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`.

### Examples

Install the `@nx/react` package matching the installed version of the `nx` package and run its `@nx/react:init` generator:

```shell
nx add @nx/react
```

Install the latest version of the `non-core-nx-plugin` package and run its `non-core-nx-plugin:init` generator if available:

```shell
nx add non-core-nx-plugin
```

Install version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator:

```shell
nx add @nx/[email protected]
```

## Options

### help

Type: `boolean`

Show help

### packageSpecifier

Type: `string`

The package name and optional version (e.g. `@nx/react` or `@nx/react@latest`) to install and initialize. If the version is not specified it will install the same version as the `nx` package for Nx core plugins or the latest version for other packages

### verbose

Type: `boolean`

Prints additional information about the commands (e.g., stack traces)

### version

Type: `boolean`

Show version number
8 changes: 8 additions & 0 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -8332,6 +8332,14 @@
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "add",
"path": "/nx-api/nx/documents/add",
"id": "add",
"isExternal": false,
"children": [],
"disableCollapsible": false
}
],
"isExternal": false,
Expand Down
11 changes: 11 additions & 0 deletions docs/generated/manifests/nx-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,17 @@
"path": "/nx-api/nx/documents/release",
"tags": [],
"originalFilePath": "generated/cli/release"
},
"/nx-api/nx/documents/add": {
"id": "add",
"name": "add",
"description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
"file": "generated/packages/nx/documents/add",
"itemList": [],
"isExternal": false,
"path": "/nx-api/nx/documents/add",
"tags": [],
"originalFilePath": "generated/cli/add"
}
},
"root": "/packages/nx",
Expand Down
11 changes: 11 additions & 0 deletions docs/generated/packages-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,17 @@
"path": "nx/documents/release",
"tags": [],
"originalFilePath": "generated/cli/release"
},
{
"id": "add",
"name": "add",
"description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
"file": "generated/packages/nx/documents/add",
"itemList": [],
"isExternal": false,
"path": "nx/documents/add",
"tags": [],
"originalFilePath": "generated/cli/add"
}
],
"executors": [
Expand Down
62 changes: 62 additions & 0 deletions docs/generated/packages/nx/documents/add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: 'add - CLI command'
description: 'Install a plugin and initialize it.'
---

# add

Install a plugin and initialize it.

## Usage

```shell
nx add <packageSpecifier>
```

Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`.

### Examples

Install the `@nx/react` package matching the installed version of the `nx` package and run its `@nx/react:init` generator:

```shell
nx add @nx/react
```

Install the latest version of the `non-core-nx-plugin` package and run its `non-core-nx-plugin:init` generator if available:

```shell
nx add non-core-nx-plugin
```

Install version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator:

```shell
nx add @nx/[email protected]
```

## Options

### help

Type: `boolean`

Show help

### packageSpecifier

Type: `string`

The package name and optional version (e.g. `@nx/react` or `@nx/react@latest`) to install and initialize. If the version is not specified it will install the same version as the `nx` package for Nx core plugins or the latest version for other packages

### verbose

Type: `boolean`

Prints additional information about the commands (e.g., stack traces)

### version

Type: `boolean`

Show version number
5 changes: 5 additions & 0 deletions docs/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,11 @@
"name": "release",
"id": "release",
"file": "generated/cli/release"
},
{
"name": "add",
"id": "add",
"file": "generated/cli/add"
}
]
},
Expand Down
1 change: 1 addition & 0 deletions docs/shared/reference/sitemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@
- [show](/nx-api/nx/documents/show)
- [view-logs](/nx-api/nx/documents/view-logs)
- [release](/nx-api/nx/documents/release)
- [add](/nx-api/nx/documents/add)
- [executors](/nx-api/nx/executors)
- [noop](/nx-api/nx/executors/noop)
- [run-commands](/nx-api/nx/executors/run-commands)
Expand Down
35 changes: 1 addition & 34 deletions packages/nx/bin/init-local.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { performance } from 'perf_hooks';
import { execSync } from 'child_process';

import { getPackageManagerCommand } from '../src/utils/package-manager';
import { commandsObject } from '../src/command-line/nx-commands';
import { WorkspaceTypeAndRoot } from '../src/utils/find-workspace-root';
import { stripIndents } from '../src/utils/strip-indents';
Expand Down Expand Up @@ -144,14 +142,7 @@ function isKnownCommand(command: string) {

function shouldDelegateToAngularCLI() {
const command = process.argv[2];
const commands = [
'add',
'analytics',
'config',
'doc',
'update',
'completion',
];
const commands = ['analytics', 'config', 'doc', 'update', 'completion'];
return commands.indexOf(command) > -1;
}

Expand All @@ -177,30 +168,6 @@ function handleAngularCLIFallbacks(workspace: WorkspaceTypeAndRoot) {
`Running "ng update" can still be useful in some dev workflows, so we aren't planning to remove it.`
);
console.log(`If you need to use it, run "FORCE_NG_UPDATE=true ng update".`);
} else if (process.argv[2] === 'add') {
console.log('Ng add is not natively supported by Nx');
const pkg = process.argv[2] === 'add' ? process.argv[3] : process.argv[4];
if (!pkg) {
process.exit(1);
}

const pm = getPackageManagerCommand();
const cmd = `${pm.add} ${pkg} && ${pm.exec} nx g ${pkg}:ng-add`;
console.log(`Instead, we recommend running \`${cmd}\``);

import('enquirer').then((x) =>
x
.prompt<{ c: boolean }>({
name: 'c',
type: 'confirm',
message: 'Run this command?',
})
.then(({ c }) => {
if (c) {
execSync(cmd, { stdio: 'inherit' });
}
})
);
} else if (process.argv[2] === 'completion') {
if (!process.argv[3]) {
console.log(`"ng completion" is not natively supported by Nx.
Expand Down
6 changes: 6 additions & 0 deletions packages/nx/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
"version": "17.3.0-beta.3",
"description": "Explicitly opt-out of git operations in nx release",
"implementation": "./src/migrations/update-17-3-0/nx-release-git-operations-explicit-opt-out"
},
"17.3.0-update-nx-wrapper": {
"cli": "nx",
"version": "17.3.0-beta.6",
"description": "Updates the nx wrapper.",
"implementation": "./src/migrations/update-17-3-0/update-nxw"
}
}
}
3 changes: 2 additions & 1 deletion packages/nx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"tslib": "^2.3.0",
"yargs": "^17.6.2",
"yargs-parser": "21.1.1",
"node-machine-id": "1.1.12"
"node-machine-id": "1.1.12",
"ora": "5.3.0"
},
"peerDependencies": {
"@swc-node/register": "^1.6.7",
Expand Down
Loading

1 comment on commit 28438bb

@vercel
Copy link

@vercel vercel bot commented on 28438bb Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.