Skip to content

Commit

Permalink
feat(nx-cloud): unhide new onboarding flow
Browse files Browse the repository at this point in the history
(cherry picked from commit 92be32c)
  • Loading branch information
mandarini authored and FrozenPandaz committed Jun 26, 2024
1 parent 75b7fa1 commit 73f15eb
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 170 deletions.
34 changes: 12 additions & 22 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 5 additions & 7 deletions packages/create-nx-workspace/src/utils/nx/nx-cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
41 changes: 16 additions & 25 deletions packages/nx/src/command-line/connect/connect-to-nx-cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
],
});
}
}
}
Expand Down Expand Up @@ -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
);
}
}

Expand Down

0 comments on commit 73f15eb

Please sign in to comment.