feat(nx-cloud): unhide new onboarding flow
This commit is contained in:
parent
d928558bc4
commit
92be32c1a8
@ -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);
|
||||
|
||||
@ -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
|
||||
);
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -83,80 +83,64 @@ async function printSuccessMessage(
|
||||
usesGithub?: boolean,
|
||||
directory?: string
|
||||
) {
|
||||
if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') {
|
||||
let origin = 'https://nx.app';
|
||||
const connectCloudUrl = await shortenedCloudUrl(
|
||||
installationSource,
|
||||
token,
|
||||
usesGithub
|
||||
);
|
||||
|
||||
if (installationSource === 'nx-connect' && usesGithub) {
|
||||
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`,
|
||||
],
|
||||
});
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user