Skip to content

Commit

Permalink
chore: repsect dev or prod mode when setting up cloud runner
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Dec 28, 2022
1 parent 47b882c commit c2139f6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
29 changes: 29 additions & 0 deletions libs/vscode/nx-cloud-view/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export type CloudConfig = {
authConfig: {
clientId: string;
audience: string;
domain: string;
};
endpoint: string;
appUrl: string;
};

export const stagingConfig = {
authConfig: {
clientId: '11Zte67xGtfrGQhRVlz9zM8Fq0LvZYwe',
audience: 'https://api.staging.nrwl.io/',
domain: 'https://auth.staging.nx.app/login',
},
endpoint: 'https://staging.nx.app/api',
appUrl: 'http://staging.nx.app',
};

export const prodConfig = {
authConfig: {
clientId: 'm6PYBsCK1t2DTKnbE30n029C22fqtTMm',
audience: 'https://api.nrwl.io/',
domain: 'https://nrwl.auth0.com/login',
},
endpoint: 'https://cloud.nx.app/api',
appUrl: 'https://cloud.nx.app',
};
27 changes: 5 additions & 22 deletions libs/vscode/nx-cloud-view/src/lib/init-nx-cloud-onboarding-view.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
import { getNxCloudRunnerUrl } from '@nx-console/vscode/nx-workspace';
import { commands, ExtensionContext, window } from 'vscode';
import { NxCloudAuthenticationProvider } from './auth/nx-cloud-authentication-provider';
import { prodConfig, stagingConfig } from './config';
import { REFRESH_COMMAND } from './nx-cloud-service/commands';
import { NxCloudService } from './nx-cloud-service/nx-cloud-service';
import { NxCloudWebviewProvider } from './nx-cloud-webview-provider';

const authStagingConfig = {
clientId: '11Zte67xGtfrGQhRVlz9zM8Fq0LvZYwe',
audience: 'https://api.staging.nrwl.io/',
domain: 'https://auth.staging.nx.app/login',
};

const authProdConfig = {
clientId: 'm6PYBsCK1t2DTKnbE30n029C22fqtTMm',
audience: 'https://api.nrwl.io/',
domain: 'https://nrwl.auth0.com/login',
};

const apiStagingEndpoint = 'https://staging.nx.app/api';
const apiProdEndpoint = 'https://cloud.nx.app/api';

const stagingUrl = 'http://staging.nx.app';
const prodUrl = 'https://cloud.nx.app';

export async function initNxCloudOnboardingView(
context: ExtensionContext,
production: boolean
) {
const mode = await determineProdOrDevMode(production);

const nxCloudService = new NxCloudService(
mode === 'dev' ? apiStagingEndpoint : apiProdEndpoint
mode === 'dev' ? stagingConfig : prodConfig
);
const nxCloudWebviewProvider = new NxCloudWebviewProvider(
context.extensionUri,
Expand All @@ -40,7 +23,7 @@ export async function initNxCloudOnboardingView(

const nxCloudAuthenticationProvider = new NxCloudAuthenticationProvider(
context,
mode === 'dev' ? authStagingConfig : authProdConfig
mode === 'dev' ? stagingConfig.authConfig : prodConfig.authConfig
);

context.subscriptions.push(
Expand All @@ -63,10 +46,10 @@ async function determineProdOrDevMode(
): Promise<'prod' | 'dev'> {
const nxCloudRunnerUrl = await getNxCloudRunnerUrl();

if (nxCloudRunnerUrl === stagingUrl) {
if (nxCloudRunnerUrl === stagingConfig.appUrl) {
return 'dev';
}
if (nxCloudRunnerUrl === prodUrl) {
if (nxCloudRunnerUrl === prodConfig.appUrl) {
return 'prod';
}
return productionEnv ? 'prod' : 'dev';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
tasks,
window,
} from 'vscode';
import type { CloudConfig } from '../config';
import {
CLAIM_COMMAND,
INSPECT_RUN_COMMAND,
Expand Down Expand Up @@ -100,9 +101,9 @@ export type WebviewState = Pick<
export class NxCloudService extends StateBaseService<InternalState> {
private nxCloudApiService: NxCloudApiService;

constructor(endpoint: string) {
constructor(private config: CloudConfig) {
super(initialInternalState);
this.nxCloudApiService = new NxCloudApiService(endpoint);
this.nxCloudApiService = new NxCloudApiService(config.endpoint);

this.listenForNxJsonChanges();
this.listenForWorkspaceDetails();
Expand Down Expand Up @@ -212,6 +213,8 @@ export class NxCloudService extends StateBaseService<InternalState> {
'latest'
);

const env = { ...process.env, NX_CLOUD_API: this.config.appUrl };

window.withProgress(
{
location: ProgressLocation.Notification,
Expand All @@ -232,7 +235,7 @@ export class NxCloudService extends StateBaseService<InternalState> {
`${
getPackageManagerCommand().exec
} nx g @nrwl/nx-cloud:init`,
{ cwd: getWorkspacePath() }
{ cwd: getWorkspacePath(), env }
).then(() => resolve(true));
})
.catch((e) => {
Expand All @@ -257,7 +260,7 @@ export class NxCloudService extends StateBaseService<InternalState> {
? 'connect'
: 'connect-to-nx-cloud',
],
{ cwd: getWorkspacePath(), shell: true }
{ cwd: getWorkspacePath(), env, shell: true }
);

commandProcess.stdout.setEncoding('utf8');
Expand Down

0 comments on commit c2139f6

Please sign in to comment.