diff --git a/packages/create-nx-workspace/bin/create-nx-workspace.ts b/packages/create-nx-workspace/bin/create-nx-workspace.ts index 0bf443ac58940..bc541f23699a7 100644 --- a/packages/create-nx-workspace/bin/create-nx-workspace.ts +++ b/packages/create-nx-workspace/bin/create-nx-workspace.ts @@ -283,28 +283,18 @@ async function normalizeArgsMiddleware( const packageManager = await determinePackageManager(argv); const defaultBase = await determineDefaultBase(argv); - if (process.env.NX_NEW_CLOUD_ONBOARDING === 'true') { - const nxCloud = - argv.skipGit === true ? 'skip' : await determineNxCloud(argv); - const useGitHub = - nxCloud === 'skip' - ? undefined - : nxCloud === 'github' || - (await determineIfGitHubWillBeUsed(nxCloud)); - Object.assign(argv, { - nxCloud, - useGitHub, - packageManager, - defaultBase, - }); - } else { - const nxCloud = await determineNxCloud(argv); - Object.assign(argv, { - nxCloud, - packageManager, - defaultBase, - }); - } + const nxCloud = + argv.skipGit === true ? 'skip' : await determineNxCloud(argv); + const useGitHub = + nxCloud === 'skip' + ? undefined + : nxCloud === 'github' || (await determineIfGitHubWillBeUsed(nxCloud)); + Object.assign(argv, { + nxCloud, + useGitHub, + packageManager, + defaultBase, + }); } catch (e) { console.error(e); process.exit(1); diff --git a/packages/create-nx-workspace/src/utils/nx/nx-cloud.ts b/packages/create-nx-workspace/src/utils/nx/nx-cloud.ts index a5178f6a0292e..c9a1f3b31252c 100644 --- a/packages/create-nx-workspace/src/utils/nx/nx-cloud.ts +++ b/packages/create-nx-workspace/src/utils/nx/nx-cloud.ts @@ -16,13 +16,11 @@ export async function setupNxCloud( try { const pmc = getPackageManagerCommand(packageManager); const res = await execAndWait( - process.env.NX_NEW_CLOUD_ONBOARDING === 'true' - ? `${ - pmc.exec - } nx g nx:connect-to-nx-cloud --installationSource=create-nx-workspace --directory=${directory} ${ - useGitHub ? '--github' : '' - } --no-interactive` - : `${pmc.exec} nx g nx:connect-to-nx-cloud --no-interactive --quiet`, + `${ + pmc.exec + } nx g nx:connect-to-nx-cloud --installationSource=create-nx-workspace --directory=${directory} ${ + useGitHub ? '--github' : '' + } --no-interactive`, directory ); diff --git a/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts b/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts index 722d2b642ae38..17f5a5378b558 100644 --- a/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts +++ b/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts @@ -56,33 +56,24 @@ export async function connectToNxCloudCommand( const nxJson = readNxJson(); if (isNxCloudUsed(nxJson)) { - if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') { - output.log({ - title: '✔ This workspace already has Nx Cloud set up', - bodyLines: [ - 'If you have not done so already, connect your workspace to your Nx Cloud account:', - `- Login at ${getNxCloudUrl(nxJson)} to connect your repository`, - ], - }); - } else { - const token = - process.env.NX_CLOUD_ACCESS_TOKEN || nxJson.nxCloudAccessToken; - if (!token) { - throw new Error( - `Unable to authenticate. Either define accessToken in nx.json or set the NX_CLOUD_ACCESS_TOKEN env variable.` - ); - } - const connectCloudUrl = await shortenedCloudUrl('nx-connect', token); - output.log({ - title: '✔ This workspace already has Nx Cloud set up', - bodyLines: [ - 'If you have not done so already, connect your workspace to your Nx Cloud account:', - `- Connect with Nx Cloud at: + const token = + process.env.NX_CLOUD_ACCESS_TOKEN || nxJson.nxCloudAccessToken; + if (!token) { + throw new Error( + `Unable to authenticate. Either define accessToken in nx.json or set the NX_CLOUD_ACCESS_TOKEN env variable.` + ); + } + const connectCloudUrl = await shortenedCloudUrl('nx-connect', token); + output.log({ + title: '✔ This workspace already has Nx Cloud set up', + bodyLines: [ + 'If you have not done so already, connect your workspace to your Nx Cloud account:', + `- Connect with Nx Cloud at: ${connectCloudUrl}`, - ], - }); - } + ], + }); + return false; } diff --git a/packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.ts b/packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.ts index 99772cfb4ec22..139a41f1f9e73 100644 --- a/packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.ts +++ b/packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.ts @@ -83,80 +83,64 @@ async function printSuccessMessage( usesGithub?: boolean, directory?: string ) { - if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') { - let origin = 'https://nx.app'; - try { - origin = new URL(url).origin; - } catch (e) {} + const connectCloudUrl = await shortenedCloudUrl( + installationSource, + token, + usesGithub + ); - output.note({ - title: `Your Nx Cloud workspace is public`, - bodyLines: [ - `To restrict access, connect it to your Nx Cloud account:`, - `- Push your changes`, - `- Login at ${origin} to connect your repository`, - ], - }); + if (installationSource === 'nx-connect' && usesGithub) { + try { + const cloudConnectSpinner = ora( + `Opening Nx Cloud ${connectCloudUrl} in your browser to connect your workspace.` + ).start(); + await sleep(2000); + open(connectCloudUrl); + cloudConnectSpinner.succeed(); + } catch (e) { + output.note({ + title: `Your Nx Cloud workspace is ready.`, + bodyLines: [ + `To claim it, connect it to your Nx Cloud account:`, + `- Go to the following URL to connect your workspace to Nx Cloud:`, + '', + `${connectCloudUrl}`, + ], + }); + } } else { - const connectCloudUrl = await shortenedCloudUrl( - installationSource, - token, - usesGithub - ); - - if (installationSource === 'nx-connect' && usesGithub) { - try { - const cloudConnectSpinner = ora( - `Opening Nx Cloud ${connectCloudUrl} in your browser to connect your workspace.` - ).start(); - await sleep(2000); - open(connectCloudUrl); - cloudConnectSpinner.succeed(); - } catch (e) { - output.note({ - title: `Your Nx Cloud workspace is ready.`, - bodyLines: [ - `To claim it, connect it to your Nx Cloud account:`, - `- Go to the following URL to connect your workspace to Nx Cloud:`, - '', - `${connectCloudUrl}`, - ], - }); - } - } else { - if (installationSource === 'create-nx-workspace') { - output.note({ - title: `Your Nx Cloud workspace is ready.`, - bodyLines: [ - `To claim it, connect it to your Nx Cloud account:`, - `- Push your repository to your git hosting provider.`, - `- Go to the following URL to connect your workspace to Nx Cloud:`, - '', - `${connectCloudUrl}`, - ], - }); - commitChanges( - `feat(nx): Added Nx Cloud token to your nx.json + if (installationSource === 'create-nx-workspace') { + output.note({ + title: `Your Nx Cloud workspace is ready.`, + bodyLines: [ + `To claim it, connect it to your Nx Cloud account:`, + `- Push your repository to your git hosting provider.`, + `- Go to the following URL to connect your workspace to Nx Cloud:`, + '', + `${connectCloudUrl}`, + ], + }); + commitChanges( + `feat(nx): Added Nx Cloud token to your nx.json To connect your workspace to Nx Cloud, push your repository to your git hosting provider and go to the following URL: ${connectCloudUrl}`, - directory - ); - } else { - output.note({ - title: `Your Nx Cloud workspace is ready.`, - bodyLines: [ - `To claim it, connect it to your Nx Cloud account:`, - `- Commit and push your changes.`, - `- Create a pull request for the changes.`, - `- Go to the following URL to connect your workspace to Nx Cloud:`, - '', - `${connectCloudUrl}`, - ], - }); - } + directory + ); + } else { + output.note({ + title: `Your Nx Cloud workspace is ready.`, + bodyLines: [ + `To claim it, connect it to your Nx Cloud account:`, + `- Commit and push your changes.`, + `- Create a pull request for the changes.`, + `- Go to the following URL to connect your workspace to Nx Cloud:`, + '', + `${connectCloudUrl}`, + ], + }); } } } @@ -200,65 +184,45 @@ export async function connectToNxCloud( printCloudConnectionDisabledMessage(); }; } else { - if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') { - // TODO: Change to using loading light client when that is enabled by default - const r = await createNxCloudWorkspace( + const usesGithub = await repoUsesGithub(schema.github); + + let responseFromCreateNxCloudWorkspace: + | { + token: string; + url: string; + } + | undefined; + + // do NOT create Nx Cloud token (createNxCloudWorkspace) + // if user is using github and is running nx-connect + if (!(usesGithub && schema.installationSource === 'nx-connect')) { + responseFromCreateNxCloudWorkspace = await createNxCloudWorkspace( getRootPackageName(tree), schema.installationSource, getNxInitDate() ); - addNxCloudOptionsToNxJson(tree, nxJson, r.token); + addNxCloudOptionsToNxJson( + tree, + nxJson, + responseFromCreateNxCloudWorkspace?.token + ); await formatChangedFilesWithPrettierIfAvailable(tree, { silent: schema.hideFormatLogs, }); - - return async () => - await printSuccessMessage(r.url, r.token, schema.installationSource); - } else { - const usesGithub = await repoUsesGithub(schema.github); - - let responseFromCreateNxCloudWorkspace: - | { - token: string; - url: string; - } - | undefined; - - // do NOT create Nx Cloud token (createNxCloudWorkspace) - // if user is using github and is running nx-connect - if (!(usesGithub && schema.installationSource === 'nx-connect')) { - responseFromCreateNxCloudWorkspace = await createNxCloudWorkspace( - getRootPackageName(tree), - schema.installationSource, - getNxInitDate() - ); - - addNxCloudOptionsToNxJson( - tree, - nxJson, - responseFromCreateNxCloudWorkspace?.token - ); - - await formatChangedFilesWithPrettierIfAvailable(tree, { - silent: schema.hideFormatLogs, - }); - } - const apiUrl = removeTrailingSlash( - process.env.NX_CLOUD_API || - process.env.NRWL_API || - `https://cloud.nx.app` - ); - return async () => - await printSuccessMessage( - responseFromCreateNxCloudWorkspace?.url ?? apiUrl, - responseFromCreateNxCloudWorkspace?.token, - schema.installationSource, - usesGithub, - schema.directory - ); } + const apiUrl = removeTrailingSlash( + process.env.NX_CLOUD_API || process.env.NRWL_API || `https://cloud.nx.app` + ); + return async () => + await printSuccessMessage( + responseFromCreateNxCloudWorkspace?.url ?? apiUrl, + responseFromCreateNxCloudWorkspace?.token, + schema.installationSource, + usesGithub, + schema.directory + ); } }