-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nx-cloud): alias for login and logout (#27358)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> N/A ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> When running `npx nx login`, a file server should open and take you to Nx Cloud to create a new personal access token. When running `npx nx logout`, the user should be prompted with Nx Cloud URLs of instances that they can revoke personal access tokens to. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
- Loading branch information
Showing
17 changed files
with
308 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: 'login - CLI command' | ||
description: 'Login to Nx Cloud' | ||
--- | ||
|
||
# login | ||
|
||
Login to Nx Cloud | ||
|
||
## Usage | ||
|
||
```shell | ||
nx login [nxCloudUrl] | ||
``` | ||
|
||
Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`. | ||
|
||
## Options | ||
|
||
### help | ||
|
||
Type: `boolean` | ||
|
||
Show help | ||
|
||
### nxCloudUrl | ||
|
||
Type: `string` | ||
|
||
The Nx Cloud URL of the instance you are trying to connect to. If no positional argument is provided, this command will connect to https://cloud.nx.app. | ||
|
||
### verbose | ||
|
||
Type: `boolean` | ||
|
||
Prints additional information about the commands (e.g., stack traces) | ||
|
||
### version | ||
|
||
Type: `boolean` | ||
|
||
Show version number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: 'logout - CLI command' | ||
description: 'Logout from Nx Cloud' | ||
--- | ||
|
||
# logout | ||
|
||
Logout from Nx Cloud | ||
|
||
## Usage | ||
|
||
```shell | ||
nx logout | ||
``` | ||
|
||
Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`. | ||
|
||
## Options | ||
|
||
### help | ||
|
||
Type: `boolean` | ||
|
||
Show help | ||
|
||
### verbose | ||
|
||
Type: `boolean` | ||
|
||
Prints additional information about the commands (e.g., stack traces) | ||
|
||
### version | ||
|
||
Type: `boolean` | ||
|
||
Show version number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: 'login - CLI command' | ||
description: 'Login to Nx Cloud' | ||
--- | ||
|
||
# login | ||
|
||
Login to Nx Cloud | ||
|
||
## Usage | ||
|
||
```shell | ||
nx login [nxCloudUrl] | ||
``` | ||
|
||
Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`. | ||
|
||
## Options | ||
|
||
### help | ||
|
||
Type: `boolean` | ||
|
||
Show help | ||
|
||
### nxCloudUrl | ||
|
||
Type: `string` | ||
|
||
The Nx Cloud URL of the instance you are trying to connect to. If no positional argument is provided, this command will connect to https://cloud.nx.app. | ||
|
||
### verbose | ||
|
||
Type: `boolean` | ||
|
||
Prints additional information about the commands (e.g., stack traces) | ||
|
||
### version | ||
|
||
Type: `boolean` | ||
|
||
Show version number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: 'logout - CLI command' | ||
description: 'Logout from Nx Cloud' | ||
--- | ||
|
||
# logout | ||
|
||
Logout from Nx Cloud | ||
|
||
## Usage | ||
|
||
```shell | ||
nx logout | ||
``` | ||
|
||
Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`. | ||
|
||
## Options | ||
|
||
### help | ||
|
||
Type: `boolean` | ||
|
||
Show help | ||
|
||
### verbose | ||
|
||
Type: `boolean` | ||
|
||
Prints additional information about the commands (e.g., stack traces) | ||
|
||
### version | ||
|
||
Type: `boolean` | ||
|
||
Show version number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { CommandModule } from 'yargs'; | ||
import { withVerbose } from '../../command-line/yargs-utils/shared-options'; | ||
|
||
export const yargsLoginCommand: CommandModule = { | ||
command: 'login [nxCloudUrl]', | ||
describe: 'Login to Nx Cloud', | ||
builder: (yargs) => | ||
withVerbose( | ||
yargs.positional('nxCloudUrl', { | ||
describe: | ||
'The Nx Cloud URL of the instance you are trying to connect to. If no positional argument is provided, this command will connect to https://cloud.nx.app.', | ||
type: 'string', | ||
required: false, | ||
}) | ||
), | ||
handler: async (args: any) => { | ||
process.exit(await (await import('./login')).loginHandler(args)); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { verifyOrUpdateNxCloudClient } from '../../nx-cloud/update-manager'; | ||
import { getCloudOptions } from '../../nx-cloud/utilities/get-cloud-options'; | ||
import { handleErrors } from '../../utils/params'; | ||
|
||
export interface LoginArgs { | ||
nxCloudUrl?: string; | ||
verbose?: boolean; | ||
} | ||
|
||
export function loginHandler(args: LoginArgs): Promise<number> { | ||
if (args.nxCloudUrl) { | ||
process.env.NX_CLOUD_API = args.nxCloudUrl; | ||
} | ||
|
||
return handleErrors(args.verbose, async () => { | ||
const nxCloudClient = (await verifyOrUpdateNxCloudClient(getCloudOptions())) | ||
.nxCloudClient; | ||
await nxCloudClient.commands.login(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CommandModule } from 'yargs'; | ||
import { withVerbose } from '../../command-line/yargs-utils/shared-options'; | ||
|
||
export const yargsLogoutCommand: CommandModule = { | ||
command: 'logout', | ||
describe: 'Logout from Nx Cloud', | ||
builder: (yargs) => withVerbose(yargs), | ||
handler: async (args: any) => { | ||
process.exit(await (await import('./logout')).logoutHandler(args)); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { verifyOrUpdateNxCloudClient } from '../../nx-cloud/update-manager'; | ||
import { getCloudOptions } from '../../nx-cloud/utilities/get-cloud-options'; | ||
import { handleErrors } from '../../utils/params'; | ||
|
||
export interface LogoutArgs { | ||
verbose?: boolean; | ||
} | ||
|
||
export function logoutHandler(args: LogoutArgs): Promise<number> { | ||
return handleErrors(args.verbose, async () => { | ||
const nxCloudClient = (await verifyOrUpdateNxCloudClient(getCloudOptions())) | ||
.nxCloudClient; | ||
await nxCloudClient.commands.logout(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.