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' || : nxCloud === 'github' || (await determineIfGitHubWillBeUsed(nxCloud));
(await determineIfGitHubWillBeUsed(nxCloud));
Object.assign(argv, { Object.assign(argv, {
nxCloud, nxCloud,
useGitHub, useGitHub,
packageManager, packageManager,
defaultBase, 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,15 +56,6 @@ export async function connectToNxCloudCommand(
const nxJson = readNxJson(); const nxJson = readNxJson();
if (isNxCloudUsed(nxJson)) { 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 = const token =
process.env.NX_CLOUD_ACCESS_TOKEN || nxJson.nxCloudAccessToken; process.env.NX_CLOUD_ACCESS_TOKEN || nxJson.nxCloudAccessToken;
if (!token) { if (!token) {
@ -82,7 +73,7 @@ export async function connectToNxCloudCommand(
${connectCloudUrl}`, ${connectCloudUrl}`,
], ],
}); });
}
return false; return false;
} }

View File

@ -83,21 +83,6 @@ async function printSuccessMessage(
usesGithub?: boolean, usesGithub?: boolean,
directory?: string directory?: string
) { ) {
if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') {
let origin = 'https://nx.app';
try {
origin = new URL(url).origin;
} catch (e) {}
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`,
],
});
} else {
const connectCloudUrl = await shortenedCloudUrl( const connectCloudUrl = await shortenedCloudUrl(
installationSource, installationSource,
token, token,
@ -159,7 +144,6 @@ async function printSuccessMessage(
} }
} }
} }
}
interface ConnectToNxCloudOptions { interface ConnectToNxCloudOptions {
analytics?: boolean; analytics?: boolean;
@ -199,23 +183,6 @@ export async function connectToNxCloud(
return () => { return () => {
printCloudConnectionDisabledMessage(); 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(
getRootPackageName(tree),
schema.installationSource,
getNxInitDate()
);
addNxCloudOptionsToNxJson(tree, nxJson, r.token);
await formatChangedFilesWithPrettierIfAvailable(tree, {
silent: schema.hideFormatLogs,
});
return async () =>
await printSuccessMessage(r.url, r.token, schema.installationSource);
} else { } else {
const usesGithub = await repoUsesGithub(schema.github); const usesGithub = await repoUsesGithub(schema.github);
@ -246,9 +213,7 @@ export async function connectToNxCloud(
}); });
} }
const apiUrl = removeTrailingSlash( const apiUrl = removeTrailingSlash(
process.env.NX_CLOUD_API || process.env.NX_CLOUD_API || process.env.NRWL_API || `https://cloud.nx.app`
process.env.NRWL_API ||
`https://cloud.nx.app`
); );
return async () => return async () =>
await printSuccessMessage( await printSuccessMessage(
@ -260,7 +225,6 @@ export async function connectToNxCloud(
); );
} }
} }
}
function sleep(ms: number) { function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));