chore(nx-cloud): add feature flag to nx login (#27698)
<!-- 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 --> - nx login and logout aliases point toward nx-cloud login and logout - when you connect a new workspace, by default nxCloudId will be added to your nx.json ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> - removed documentation and references to nx login and logout aliases - when you connect a new workspace, by default nxCloudAccessToken will be added to your nx.json ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
72e3e89999
commit
3b0fd38066
@ -1,25 +0,0 @@
|
|||||||
---
|
|
||||||
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
|
|
||||||
|
|
||||||
| Option | Type | Description |
|
|
||||||
| -------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
||||||
| `--help` | boolean | Show help |
|
|
||||||
| `--nxCloudUrl` | 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` | boolean | Prints additional information about the commands (e.g., stack traces) |
|
|
||||||
| `--version` | boolean | Show version number |
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
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
|
|
||||||
|
|
||||||
| Option | Type | Description |
|
|
||||||
| ----------- | ------- | --------------------------------------------------------------------- |
|
|
||||||
| `--help` | boolean | Show help |
|
|
||||||
| `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces) |
|
|
||||||
| `--version` | boolean | Show version number |
|
|
||||||
@ -8712,22 +8712,6 @@
|
|||||||
"isExternal": false,
|
"isExternal": false,
|
||||||
"children": [],
|
"children": [],
|
||||||
"disableCollapsible": false
|
"disableCollapsible": false
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "login",
|
|
||||||
"path": "/nx-api/nx/documents/login",
|
|
||||||
"id": "login",
|
|
||||||
"isExternal": false,
|
|
||||||
"children": [],
|
|
||||||
"disableCollapsible": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "logout",
|
|
||||||
"path": "/nx-api/nx/documents/logout",
|
|
||||||
"id": "logout",
|
|
||||||
"isExternal": false,
|
|
||||||
"children": [],
|
|
||||||
"disableCollapsible": false
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"isExternal": false,
|
"isExternal": false,
|
||||||
|
|||||||
@ -1967,28 +1967,6 @@
|
|||||||
"path": "/nx-api/nx/documents/add",
|
"path": "/nx-api/nx/documents/add",
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"originalFilePath": "generated/cli/add"
|
"originalFilePath": "generated/cli/add"
|
||||||
},
|
|
||||||
"/nx-api/nx/documents/login": {
|
|
||||||
"id": "login",
|
|
||||||
"name": "login",
|
|
||||||
"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/login",
|
|
||||||
"itemList": [],
|
|
||||||
"isExternal": false,
|
|
||||||
"path": "/nx-api/nx/documents/login",
|
|
||||||
"tags": [],
|
|
||||||
"originalFilePath": "generated/cli/login"
|
|
||||||
},
|
|
||||||
"/nx-api/nx/documents/logout": {
|
|
||||||
"id": "logout",
|
|
||||||
"name": "logout",
|
|
||||||
"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/logout",
|
|
||||||
"itemList": [],
|
|
||||||
"isExternal": false,
|
|
||||||
"path": "/nx-api/nx/documents/logout",
|
|
||||||
"tags": [],
|
|
||||||
"originalFilePath": "generated/cli/logout"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "/packages/nx",
|
"root": "/packages/nx",
|
||||||
|
|||||||
@ -1946,28 +1946,6 @@
|
|||||||
"path": "nx/documents/add",
|
"path": "nx/documents/add",
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"originalFilePath": "generated/cli/add"
|
"originalFilePath": "generated/cli/add"
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "login",
|
|
||||||
"name": "login",
|
|
||||||
"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/login",
|
|
||||||
"itemList": [],
|
|
||||||
"isExternal": false,
|
|
||||||
"path": "nx/documents/login",
|
|
||||||
"tags": [],
|
|
||||||
"originalFilePath": "generated/cli/login"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "logout",
|
|
||||||
"name": "logout",
|
|
||||||
"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/logout",
|
|
||||||
"itemList": [],
|
|
||||||
"isExternal": false,
|
|
||||||
"path": "nx/documents/logout",
|
|
||||||
"tags": [],
|
|
||||||
"originalFilePath": "generated/cli/logout"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"executors": [
|
"executors": [
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
---
|
|
||||||
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
|
|
||||||
|
|
||||||
| Option | Type | Description |
|
|
||||||
| -------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
||||||
| `--help` | boolean | Show help |
|
|
||||||
| `--nxCloudUrl` | 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` | boolean | Prints additional information about the commands (e.g., stack traces) |
|
|
||||||
| `--version` | boolean | Show version number |
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
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
|
|
||||||
|
|
||||||
| Option | Type | Description |
|
|
||||||
| ----------- | ------- | --------------------------------------------------------------------- |
|
|
||||||
| `--help` | boolean | Show help |
|
|
||||||
| `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces) |
|
|
||||||
| `--version` | boolean | Show version number |
|
|
||||||
@ -2110,16 +2110,6 @@
|
|||||||
"name": "add",
|
"name": "add",
|
||||||
"id": "add",
|
"id": "add",
|
||||||
"file": "generated/cli/add"
|
"file": "generated/cli/add"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "login",
|
|
||||||
"id": "login",
|
|
||||||
"file": "generated/cli/login"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "logout",
|
|
||||||
"id": "logout",
|
|
||||||
"file": "generated/cli/logout"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -559,8 +559,6 @@
|
|||||||
- [view-logs](/nx-api/nx/documents/view-logs)
|
- [view-logs](/nx-api/nx/documents/view-logs)
|
||||||
- [release](/nx-api/nx/documents/release)
|
- [release](/nx-api/nx/documents/release)
|
||||||
- [add](/nx-api/nx/documents/add)
|
- [add](/nx-api/nx/documents/add)
|
||||||
- [login](/nx-api/nx/documents/login)
|
|
||||||
- [logout](/nx-api/nx/documents/logout)
|
|
||||||
- [executors](/nx-api/nx/executors)
|
- [executors](/nx-api/nx/executors)
|
||||||
- [noop](/nx-api/nx/executors/noop)
|
- [noop](/nx-api/nx/executors/noop)
|
||||||
- [run-commands](/nx-api/nx/executors/run-commands)
|
- [run-commands](/nx-api/nx/executors/run-commands)
|
||||||
|
|||||||
@ -21,7 +21,7 @@ describe('connect-to-nx-cloud', () => {
|
|||||||
expect(
|
expect(
|
||||||
withEnvironmentVariables(
|
withEnvironmentVariables(
|
||||||
{
|
{
|
||||||
NX_CLOUD_ACCESS_TOKEN: null,
|
NX_ENABLE_LOGIN: null,
|
||||||
},
|
},
|
||||||
() =>
|
() =>
|
||||||
onlyDefaultRunnerIsUsed({
|
onlyDefaultRunnerIsUsed({
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { withVerbose } from '../../command-line/yargs-utils/shared-options';
|
|||||||
|
|
||||||
export const yargsLoginCommand: CommandModule = {
|
export const yargsLoginCommand: CommandModule = {
|
||||||
command: 'login [nxCloudUrl]',
|
command: 'login [nxCloudUrl]',
|
||||||
describe: 'Login to Nx Cloud',
|
describe: false,
|
||||||
builder: (yargs) =>
|
builder: (yargs) =>
|
||||||
withVerbose(
|
withVerbose(
|
||||||
yargs.positional('nxCloudUrl', {
|
yargs.positional('nxCloudUrl', {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { withVerbose } from '../../command-line/yargs-utils/shared-options';
|
|||||||
|
|
||||||
export const yargsLogoutCommand: CommandModule = {
|
export const yargsLogoutCommand: CommandModule = {
|
||||||
command: 'logout',
|
command: 'logout',
|
||||||
describe: 'Logout from Nx Cloud',
|
describe: false,
|
||||||
builder: (yargs) => withVerbose(yargs),
|
builder: (yargs) => withVerbose(yargs),
|
||||||
handler: async (args: any) => {
|
handler: async (args: any) => {
|
||||||
process.exit(await (await import('./logout')).logoutHandler(args));
|
process.exit(await (await import('./logout')).logoutHandler(args));
|
||||||
|
|||||||
@ -48,6 +48,28 @@ function getNxInitDate(): string | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createNxCloudWorkspaceV1(
|
||||||
|
workspaceName: string,
|
||||||
|
installationSource: string,
|
||||||
|
nxInitDate: string | null
|
||||||
|
): Promise<{ token: string; url: string }> {
|
||||||
|
const apiUrl = getCloudUrl();
|
||||||
|
const response = await require('axios').post(
|
||||||
|
`${apiUrl}/nx-cloud/create-org-and-workspace`,
|
||||||
|
{
|
||||||
|
workspaceName,
|
||||||
|
installationSource,
|
||||||
|
nxInitDate,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.data.message) {
|
||||||
|
throw new Error(response.data.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
async function createNxCloudWorkspaceV2(
|
async function createNxCloudWorkspaceV2(
|
||||||
workspaceName: string,
|
workspaceName: string,
|
||||||
installationSource: string,
|
installationSource: string,
|
||||||
@ -103,6 +125,29 @@ export interface ConnectToNxCloudOptions {
|
|||||||
generateToken?: boolean;
|
generateToken?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addNxCloudOptionsToNxJson(
|
||||||
|
tree: Tree,
|
||||||
|
token: string,
|
||||||
|
directory: string = ''
|
||||||
|
) {
|
||||||
|
const nxJsonPath = join(directory, 'nx.json');
|
||||||
|
if (tree.exists(nxJsonPath)) {
|
||||||
|
updateJson<NxJsonConfiguration>(
|
||||||
|
tree,
|
||||||
|
join(directory, 'nx.json'),
|
||||||
|
(nxJson) => {
|
||||||
|
const overrideUrl = process.env.NX_CLOUD_API || process.env.NRWL_API;
|
||||||
|
if (overrideUrl) {
|
||||||
|
nxJson.nxCloudUrl = overrideUrl;
|
||||||
|
}
|
||||||
|
nxJson.nxCloudAccessToken = token;
|
||||||
|
|
||||||
|
return nxJson;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function addNxCloudIdToNxJson(
|
function addNxCloudIdToNxJson(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
nxCloudId: string,
|
nxCloudId: string,
|
||||||
@ -140,6 +185,12 @@ export async function connectToNxCloud(
|
|||||||
const isGitHubDetected =
|
const isGitHubDetected =
|
||||||
schema.github ?? (await repoUsesGithub(schema.github));
|
schema.github ?? (await repoUsesGithub(schema.github));
|
||||||
|
|
||||||
|
let responseFromCreateNxCloudWorkspaceV1:
|
||||||
|
| {
|
||||||
|
token: string;
|
||||||
|
}
|
||||||
|
| undefined;
|
||||||
|
|
||||||
let responseFromCreateNxCloudWorkspaceV2:
|
let responseFromCreateNxCloudWorkspaceV2:
|
||||||
| {
|
| {
|
||||||
nxCloudId: string;
|
nxCloudId: string;
|
||||||
@ -157,6 +208,7 @@ export async function connectToNxCloud(
|
|||||||
)
|
)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
if (process.env.NX_ENABLE_LOGIN === 'true') {
|
||||||
responseFromCreateNxCloudWorkspaceV2 = await createNxCloudWorkspaceV2(
|
responseFromCreateNxCloudWorkspaceV2 = await createNxCloudWorkspaceV2(
|
||||||
getRootPackageName(tree),
|
getRootPackageName(tree),
|
||||||
schema.installationSource,
|
schema.installationSource,
|
||||||
@ -173,6 +225,24 @@ export async function connectToNxCloud(
|
|||||||
silent: schema.hideFormatLogs,
|
silent: schema.hideFormatLogs,
|
||||||
});
|
});
|
||||||
return responseFromCreateNxCloudWorkspaceV2.nxCloudId;
|
return responseFromCreateNxCloudWorkspaceV2.nxCloudId;
|
||||||
|
} else {
|
||||||
|
responseFromCreateNxCloudWorkspaceV1 = await createNxCloudWorkspaceV1(
|
||||||
|
getRootPackageName(tree),
|
||||||
|
schema.installationSource,
|
||||||
|
getNxInitDate()
|
||||||
|
);
|
||||||
|
|
||||||
|
addNxCloudOptionsToNxJson(
|
||||||
|
tree,
|
||||||
|
responseFromCreateNxCloudWorkspaceV1?.token,
|
||||||
|
schema.directory
|
||||||
|
);
|
||||||
|
|
||||||
|
await formatChangedFilesWithPrettierIfAvailable(tree, {
|
||||||
|
silent: schema.hideFormatLogs,
|
||||||
|
});
|
||||||
|
return responseFromCreateNxCloudWorkspaceV1.token;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function connectToNxCloudGenerator(
|
async function connectToNxCloudGenerator(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user