Skip to content

Commit 73f15eb

Browse files
mandariniFrozenPandaz
authored andcommitted
feat(nx-cloud): unhide new onboarding flow
(cherry picked from commit 92be32c)
1 parent 75b7fa1 commit 73f15eb

File tree

4 files changed

+113
-170
lines changed

4 files changed

+113
-170
lines changed

packages/create-nx-workspace/bin/create-nx-workspace.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -283,28 +283,18 @@ async function normalizeArgsMiddleware(
283283

284284
const packageManager = await determinePackageManager(argv);
285285
const defaultBase = await determineDefaultBase(argv);
286-
if (process.env.NX_NEW_CLOUD_ONBOARDING === 'true') {
287-
const nxCloud =
288-
argv.skipGit === true ? 'skip' : await determineNxCloud(argv);
289-
const useGitHub =
290-
nxCloud === 'skip'
291-
? undefined
292-
: nxCloud === 'github' ||
293-
(await determineIfGitHubWillBeUsed(nxCloud));
294-
Object.assign(argv, {
295-
nxCloud,
296-
useGitHub,
297-
packageManager,
298-
defaultBase,
299-
});
300-
} else {
301-
const nxCloud = await determineNxCloud(argv);
302-
Object.assign(argv, {
303-
nxCloud,
304-
packageManager,
305-
defaultBase,
306-
});
307-
}
286+
const nxCloud =
287+
argv.skipGit === true ? 'skip' : await determineNxCloud(argv);
288+
const useGitHub =
289+
nxCloud === 'skip'
290+
? undefined
291+
: nxCloud === 'github' || (await determineIfGitHubWillBeUsed(nxCloud));
292+
Object.assign(argv, {
293+
nxCloud,
294+
useGitHub,
295+
packageManager,
296+
defaultBase,
297+
});
308298
} catch (e) {
309299
console.error(e);
310300
process.exit(1);

packages/create-nx-workspace/src/utils/nx/nx-cloud.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ export async function setupNxCloud(
1616
try {
1717
const pmc = getPackageManagerCommand(packageManager);
1818
const res = await execAndWait(
19-
process.env.NX_NEW_CLOUD_ONBOARDING === 'true'
20-
? `${
21-
pmc.exec
22-
} nx g nx:connect-to-nx-cloud --installationSource=create-nx-workspace --directory=${directory} ${
23-
useGitHub ? '--github' : ''
24-
} --no-interactive`
25-
: `${pmc.exec} nx g nx:connect-to-nx-cloud --no-interactive --quiet`,
19+
`${
20+
pmc.exec
21+
} nx g nx:connect-to-nx-cloud --installationSource=create-nx-workspace --directory=${directory} ${
22+
useGitHub ? '--github' : ''
23+
} --no-interactive`,
2624
directory
2725
);
2826

packages/nx/src/command-line/connect/connect-to-nx-cloud.ts

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,24 @@ export async function connectToNxCloudCommand(
5656
const nxJson = readNxJson();
5757

5858
if (isNxCloudUsed(nxJson)) {
59-
if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') {
60-
output.log({
61-
title: '✔ This workspace already has Nx Cloud set up',
62-
bodyLines: [
63-
'If you have not done so already, connect your workspace to your Nx Cloud account:',
64-
`- Login at ${getNxCloudUrl(nxJson)} to connect your repository`,
65-
],
66-
});
67-
} else {
68-
const token =
69-
process.env.NX_CLOUD_ACCESS_TOKEN || nxJson.nxCloudAccessToken;
70-
if (!token) {
71-
throw new Error(
72-
`Unable to authenticate. Either define accessToken in nx.json or set the NX_CLOUD_ACCESS_TOKEN env variable.`
73-
);
74-
}
75-
const connectCloudUrl = await shortenedCloudUrl('nx-connect', token);
76-
output.log({
77-
title: '✔ This workspace already has Nx Cloud set up',
78-
bodyLines: [
79-
'If you have not done so already, connect your workspace to your Nx Cloud account:',
80-
`- Connect with Nx Cloud at:
59+
const token =
60+
process.env.NX_CLOUD_ACCESS_TOKEN || nxJson.nxCloudAccessToken;
61+
if (!token) {
62+
throw new Error(
63+
`Unable to authenticate. Either define accessToken in nx.json or set the NX_CLOUD_ACCESS_TOKEN env variable.`
64+
);
65+
}
66+
const connectCloudUrl = await shortenedCloudUrl('nx-connect', token);
67+
output.log({
68+
title: '✔ This workspace already has Nx Cloud set up',
69+
bodyLines: [
70+
'If you have not done so already, connect your workspace to your Nx Cloud account:',
71+
`- Connect with Nx Cloud at:
8172
8273
${connectCloudUrl}`,
83-
],
84-
});
85-
}
74+
],
75+
});
76+
8677
return false;
8778
}
8879

packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.ts

Lines changed: 80 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -83,80 +83,64 @@ async function printSuccessMessage(
8383
usesGithub?: boolean,
8484
directory?: string
8585
) {
86-
if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') {
87-
let origin = 'https://nx.app';
88-
try {
89-
origin = new URL(url).origin;
90-
} catch (e) {}
86+
const connectCloudUrl = await shortenedCloudUrl(
87+
installationSource,
88+
token,
89+
usesGithub
90+
);
9191

92-
output.note({
93-
title: `Your Nx Cloud workspace is public`,
94-
bodyLines: [
95-
`To restrict access, connect it to your Nx Cloud account:`,
96-
`- Push your changes`,
97-
`- Login at ${origin} to connect your repository`,
98-
],
99-
});
92+
if (installationSource === 'nx-connect' && usesGithub) {
93+
try {
94+
const cloudConnectSpinner = ora(
95+
`Opening Nx Cloud ${connectCloudUrl} in your browser to connect your workspace.`
96+
).start();
97+
await sleep(2000);
98+
open(connectCloudUrl);
99+
cloudConnectSpinner.succeed();
100+
} catch (e) {
101+
output.note({
102+
title: `Your Nx Cloud workspace is ready.`,
103+
bodyLines: [
104+
`To claim it, connect it to your Nx Cloud account:`,
105+
`- Go to the following URL to connect your workspace to Nx Cloud:`,
106+
'',
107+
`${connectCloudUrl}`,
108+
],
109+
});
110+
}
100111
} else {
101-
const connectCloudUrl = await shortenedCloudUrl(
102-
installationSource,
103-
token,
104-
usesGithub
105-
);
106-
107-
if (installationSource === 'nx-connect' && usesGithub) {
108-
try {
109-
const cloudConnectSpinner = ora(
110-
`Opening Nx Cloud ${connectCloudUrl} in your browser to connect your workspace.`
111-
).start();
112-
await sleep(2000);
113-
open(connectCloudUrl);
114-
cloudConnectSpinner.succeed();
115-
} catch (e) {
116-
output.note({
117-
title: `Your Nx Cloud workspace is ready.`,
118-
bodyLines: [
119-
`To claim it, connect it to your Nx Cloud account:`,
120-
`- Go to the following URL to connect your workspace to Nx Cloud:`,
121-
'',
122-
`${connectCloudUrl}`,
123-
],
124-
});
125-
}
126-
} else {
127-
if (installationSource === 'create-nx-workspace') {
128-
output.note({
129-
title: `Your Nx Cloud workspace is ready.`,
130-
bodyLines: [
131-
`To claim it, connect it to your Nx Cloud account:`,
132-
`- Push your repository to your git hosting provider.`,
133-
`- Go to the following URL to connect your workspace to Nx Cloud:`,
134-
'',
135-
`${connectCloudUrl}`,
136-
],
137-
});
138-
commitChanges(
139-
`feat(nx): Added Nx Cloud token to your nx.json
112+
if (installationSource === 'create-nx-workspace') {
113+
output.note({
114+
title: `Your Nx Cloud workspace is ready.`,
115+
bodyLines: [
116+
`To claim it, connect it to your Nx Cloud account:`,
117+
`- Push your repository to your git hosting provider.`,
118+
`- Go to the following URL to connect your workspace to Nx Cloud:`,
119+
'',
120+
`${connectCloudUrl}`,
121+
],
122+
});
123+
commitChanges(
124+
`feat(nx): Added Nx Cloud token to your nx.json
140125
141126
To connect your workspace to Nx Cloud, push your repository
142127
to your git hosting provider and go to the following URL:
143128
144129
${connectCloudUrl}`,
145-
directory
146-
);
147-
} else {
148-
output.note({
149-
title: `Your Nx Cloud workspace is ready.`,
150-
bodyLines: [
151-
`To claim it, connect it to your Nx Cloud account:`,
152-
`- Commit and push your changes.`,
153-
`- Create a pull request for the changes.`,
154-
`- Go to the following URL to connect your workspace to Nx Cloud:`,
155-
'',
156-
`${connectCloudUrl}`,
157-
],
158-
});
159-
}
130+
directory
131+
);
132+
} else {
133+
output.note({
134+
title: `Your Nx Cloud workspace is ready.`,
135+
bodyLines: [
136+
`To claim it, connect it to your Nx Cloud account:`,
137+
`- Commit and push your changes.`,
138+
`- Create a pull request for the changes.`,
139+
`- Go to the following URL to connect your workspace to Nx Cloud:`,
140+
'',
141+
`${connectCloudUrl}`,
142+
],
143+
});
160144
}
161145
}
162146
}
@@ -200,65 +184,45 @@ export async function connectToNxCloud(
200184
printCloudConnectionDisabledMessage();
201185
};
202186
} else {
203-
if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') {
204-
// TODO: Change to using loading light client when that is enabled by default
205-
const r = await createNxCloudWorkspace(
187+
const usesGithub = await repoUsesGithub(schema.github);
188+
189+
let responseFromCreateNxCloudWorkspace:
190+
| {
191+
token: string;
192+
url: string;
193+
}
194+
| undefined;
195+
196+
// do NOT create Nx Cloud token (createNxCloudWorkspace)
197+
// if user is using github and is running nx-connect
198+
if (!(usesGithub && schema.installationSource === 'nx-connect')) {
199+
responseFromCreateNxCloudWorkspace = await createNxCloudWorkspace(
206200
getRootPackageName(tree),
207201
schema.installationSource,
208202
getNxInitDate()
209203
);
210204

211-
addNxCloudOptionsToNxJson(tree, nxJson, r.token);
205+
addNxCloudOptionsToNxJson(
206+
tree,
207+
nxJson,
208+
responseFromCreateNxCloudWorkspace?.token
209+
);
212210

213211
await formatChangedFilesWithPrettierIfAvailable(tree, {
214212
silent: schema.hideFormatLogs,
215213
});
216-
217-
return async () =>
218-
await printSuccessMessage(r.url, r.token, schema.installationSource);
219-
} else {
220-
const usesGithub = await repoUsesGithub(schema.github);
221-
222-
let responseFromCreateNxCloudWorkspace:
223-
| {
224-
token: string;
225-
url: string;
226-
}
227-
| undefined;
228-
229-
// do NOT create Nx Cloud token (createNxCloudWorkspace)
230-
// if user is using github and is running nx-connect
231-
if (!(usesGithub && schema.installationSource === 'nx-connect')) {
232-
responseFromCreateNxCloudWorkspace = await createNxCloudWorkspace(
233-
getRootPackageName(tree),
234-
schema.installationSource,
235-
getNxInitDate()
236-
);
237-
238-
addNxCloudOptionsToNxJson(
239-
tree,
240-
nxJson,
241-
responseFromCreateNxCloudWorkspace?.token
242-
);
243-
244-
await formatChangedFilesWithPrettierIfAvailable(tree, {
245-
silent: schema.hideFormatLogs,
246-
});
247-
}
248-
const apiUrl = removeTrailingSlash(
249-
process.env.NX_CLOUD_API ||
250-
process.env.NRWL_API ||
251-
`https://cloud.nx.app`
252-
);
253-
return async () =>
254-
await printSuccessMessage(
255-
responseFromCreateNxCloudWorkspace?.url ?? apiUrl,
256-
responseFromCreateNxCloudWorkspace?.token,
257-
schema.installationSource,
258-
usesGithub,
259-
schema.directory
260-
);
261214
}
215+
const apiUrl = removeTrailingSlash(
216+
process.env.NX_CLOUD_API || process.env.NRWL_API || `https://cloud.nx.app`
217+
);
218+
return async () =>
219+
await printSuccessMessage(
220+
responseFromCreateNxCloudWorkspace?.url ?? apiUrl,
221+
responseFromCreateNxCloudWorkspace?.token,
222+
schema.installationSource,
223+
usesGithub,
224+
schema.directory
225+
);
262226
}
263227
}
264228

0 commit comments

Comments
 (0)