feat(nx-cloud): unhide new onboarding flow

This commit is contained in:
Katerina Skroumpelou 2024-06-21 15:06:23 +03:00 committed by Jason Jean
parent d928558bc4
commit 92be32c1a8
4 changed files with 113 additions and 170 deletions

View File

@ -283,28 +283,18 @@ async function normalizeArgsMiddleware(
const packageManager = await determinePackageManager(argv); const packageManager = await determinePackageManager(argv);
const defaultBase = await determineDefaultBase(argv); const defaultBase = await determineDefaultBase(argv);
if (process.env.NX_NEW_CLOUD_ONBOARDING === 'true') { const nxCloud =
const nxCloud = argv.skipGit === true ? 'skip' : await determineNxCloud(argv);
argv.skipGit === true ? 'skip' : await determineNxCloud(argv); const useGitHub =
const useGitHub = nxCloud === 'skip'
nxCloud === 'skip' ? undefined
? undefined : nxCloud === 'github' || (await determineIfGitHubWillBeUsed(nxCloud));
: nxCloud === 'github' || Object.assign(argv, {
(await determineIfGitHubWillBeUsed(nxCloud)); nxCloud,
Object.assign(argv, { useGitHub,
nxCloud, packageManager,
useGitHub, defaultBase,
packageManager, });
defaultBase,
});
} else {
const nxCloud = await determineNxCloud(argv);
Object.assign(argv, {
nxCloud,
packageManager,
defaultBase,
});
}
} catch (e) { } catch (e) {
console.error(e); console.error(e);
process.exit(1); process.exit(1);

View File

@ -16,13 +16,11 @@ export async function setupNxCloud(
try { try {
const pmc = getPackageManagerCommand(packageManager); const pmc = getPackageManagerCommand(packageManager);
const res = await execAndWait( const res = await execAndWait(
process.env.NX_NEW_CLOUD_ONBOARDING === 'true' `${
? `${ pmc.exec
pmc.exec } nx g nx:connect-to-nx-cloud --installationSource=create-nx-workspace --directory=${directory} ${
} nx g nx:connect-to-nx-cloud --installationSource=create-nx-workspace --directory=${directory} ${ useGitHub ? '--github' : ''
useGitHub ? '--github' : '' } --no-interactive`,
} --no-interactive`
: `${pmc.exec} nx g nx:connect-to-nx-cloud --no-interactive --quiet`,
directory directory
); );

View File

@ -56,33 +56,24 @@ export async function connectToNxCloudCommand(
const nxJson = readNxJson(); const nxJson = readNxJson();
if (isNxCloudUsed(nxJson)) { if (isNxCloudUsed(nxJson)) {
if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') { const token =
output.log({ process.env.NX_CLOUD_ACCESS_TOKEN || nxJson.nxCloudAccessToken;
title: '✔ This workspace already has Nx Cloud set up', if (!token) {
bodyLines: [ throw new Error(
'If you have not done so already, connect your workspace to your Nx Cloud account:', `Unable to authenticate. Either define accessToken in nx.json or set the NX_CLOUD_ACCESS_TOKEN env variable.`
`- Login at ${getNxCloudUrl(nxJson)} to connect your repository`, );
], }
}); const connectCloudUrl = await shortenedCloudUrl('nx-connect', token);
} else { output.log({
const token = title: '✔ This workspace already has Nx Cloud set up',
process.env.NX_CLOUD_ACCESS_TOKEN || nxJson.nxCloudAccessToken; bodyLines: [
if (!token) { 'If you have not done so already, connect your workspace to your Nx Cloud account:',
throw new Error( `- Connect with Nx Cloud at:
`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}`, ${connectCloudUrl}`,
], ],
}); });
}
return false; return false;
} }

View File

@ -83,80 +83,64 @@ async function printSuccessMessage(
usesGithub?: boolean, usesGithub?: boolean,
directory?: string directory?: string
) { ) {
if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') { const connectCloudUrl = await shortenedCloudUrl(
let origin = 'https://nx.app'; installationSource,
token,
usesGithub
);
if (installationSource === 'nx-connect' && usesGithub) {
try { try {
origin = new URL(url).origin; const cloudConnectSpinner = ora(
} catch (e) {} `Opening Nx Cloud ${connectCloudUrl} in your browser to connect your workspace.`
).start();
output.note({ await sleep(2000);
title: `Your Nx Cloud workspace is public`, open(connectCloudUrl);
bodyLines: [ cloudConnectSpinner.succeed();
`To restrict access, connect it to your Nx Cloud account:`, } catch (e) {
`- Push your changes`, output.note({
`- Login at ${origin} to connect your repository`, 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 { } else {
const connectCloudUrl = await shortenedCloudUrl( if (installationSource === 'create-nx-workspace') {
installationSource, output.note({
token, title: `Your Nx Cloud workspace is ready.`,
usesGithub bodyLines: [
); `To claim it, connect it to your Nx Cloud account:`,
`- Push your repository to your git hosting provider.`,
if (installationSource === 'nx-connect' && usesGithub) { `- Go to the following URL to connect your workspace to Nx Cloud:`,
try { '',
const cloudConnectSpinner = ora( `${connectCloudUrl}`,
`Opening Nx Cloud ${connectCloudUrl} in your browser to connect your workspace.` ],
).start(); });
await sleep(2000); commitChanges(
open(connectCloudUrl); `feat(nx): Added Nx Cloud token to your nx.json
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
To connect your workspace to Nx Cloud, push your repository To connect your workspace to Nx Cloud, push your repository
to your git hosting provider and go to the following URL: to your git hosting provider and go to the following URL:
${connectCloudUrl}`, ${connectCloudUrl}`,
directory directory
); );
} else { } else {
output.note({ output.note({
title: `Your Nx Cloud workspace is ready.`, title: `Your Nx Cloud workspace is ready.`,
bodyLines: [ bodyLines: [
`To claim it, connect it to your Nx Cloud account:`, `To claim it, connect it to your Nx Cloud account:`,
`- Commit and push your changes.`, `- Commit and push your changes.`,
`- Create a pull request for the changes.`, `- Create a pull request for the changes.`,
`- Go to the following URL to connect your workspace to Nx Cloud:`, `- Go to the following URL to connect your workspace to Nx Cloud:`,
'', '',
`${connectCloudUrl}`, `${connectCloudUrl}`,
], ],
}); });
}
} }
} }
} }
@ -200,65 +184,45 @@ export async function connectToNxCloud(
printCloudConnectionDisabledMessage(); printCloudConnectionDisabledMessage();
}; };
} else { } else {
if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') { const usesGithub = await repoUsesGithub(schema.github);
// TODO: Change to using loading light client when that is enabled by default
const r = await createNxCloudWorkspace( 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), getRootPackageName(tree),
schema.installationSource, schema.installationSource,
getNxInitDate() getNxInitDate()
); );
addNxCloudOptionsToNxJson(tree, nxJson, r.token); addNxCloudOptionsToNxJson(
tree,
nxJson,
responseFromCreateNxCloudWorkspace?.token
);
await formatChangedFilesWithPrettierIfAvailable(tree, { await formatChangedFilesWithPrettierIfAvailable(tree, {
silent: schema.hideFormatLogs, 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
);
} }
} }