diff --git a/.env.development b/.env.development index a960cac6..6fe15d0d 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1 @@ -JUNO_URL=http://localhost:5173 CLI_PROJECT_NAME=juno-dev \ No newline at end of file diff --git a/.env.production b/.env.production index eb7761f4..43b605ea 100644 --- a/.env.production +++ b/.env.production @@ -1,2 +1 @@ -JUNO_URL=https://console.juno.build CLI_PROJECT_NAME=juno \ No newline at end of file diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 2fe3ac86..d148c1dc 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -1,4 +1,3 @@ -export const AUTH_URL = `${process.env.JUNO_URL}/cli`; export const CLI_PROJECT_NAME = process.env.CLI_PROJECT_NAME ?? 'juno'; export const CLI_SETTINGS_NAME = `${CLI_PROJECT_NAME}-cli-settings`; export const REDIRECT_URL = 'http://localhost:{port}'; diff --git a/src/constants/help.constants.ts b/src/constants/help.constants.ts index dbb80b54..31474872 100644 --- a/src/constants/help.constants.ts +++ b/src/constants/help.constants.ts @@ -48,6 +48,7 @@ export const OPTIONS_UPGRADE = `${yellow('--clear-chunks')} Clear any pre ${yellow('--no-snapshot')} Skip creating a snapshot before upgrading. ${yellow('-r, --reset')} Reset to the initial state.`; export const OPTIONS_HELP = `${yellow('-m, --mode')} Set env mode. For example production or a custom string. Default is production. - ${yellow('--container-url')} Override a custom container URL. If not provided, defaults to production or the local container in development mode.`; + ${yellow('--container-url')} Override a custom container URL. If not provided, defaults to production or the local container in development mode. + ${yellow('--console-url')} Specify a custom URL to access the developer Console.`; export const NOTE_KEEP_STAGED = `The option ${yellow('--keep-staged')} only applies when ${yellow('--no-apply')} is NOT used (i.e. the change is applied immediately).`; diff --git a/src/env.ts b/src/env.ts index 92928bf2..dbff70d2 100644 --- a/src/env.ts +++ b/src/env.ts @@ -3,6 +3,7 @@ import type {JunoConfigEnv} from '@junobuild/config'; export type JunoCliEnv = JunoConfigEnv & { containerUrl: string | undefined; + authUrl: string; }; const loadEnv = (): JunoCliEnv => { @@ -10,10 +11,17 @@ const loadEnv = (): JunoCliEnv => { const mode = nextArg({args, option: '-m'}) ?? nextArg({args, option: '--mode'}); const containerUrl = nextArg({args, option: '--container-url'}); + const consoleUrl = nextArg({args, option: '--console-url'}); + + const envContainerUrl = + containerUrl ?? (mode === 'development' ? 'http://127.0.0.1:5987' : undefined); + const envConsoleUrl = + consoleUrl ?? (mode === 'development' ? 'http://localhost:5866' : 'https://console.juno.build'); return { mode: mode ?? 'production', - containerUrl: containerUrl ?? (mode === 'development' ? 'http://127.0.0.1:5987' : undefined) + containerUrl: envContainerUrl, + authUrl: `${envConsoleUrl}/cli` }; }; diff --git a/src/utils/auth.utils.ts b/src/utils/auth.utils.ts index 273a0c32..dd25f625 100644 --- a/src/utils/auth.utils.ts +++ b/src/utils/auth.utils.ts @@ -1,4 +1,5 @@ -import {AUTH_URL, REDIRECT_URL} from '../constants/constants'; +import {REDIRECT_URL} from '../constants/constants'; +import {ENV} from '../env'; export const authUrl = ({ port, @@ -11,7 +12,7 @@ export const authUrl = ({ }): string => { const callbackUrl = authCallbackUrl({port, nonce}); - const authUrl = new URL(AUTH_URL); + const authUrl = new URL(ENV.authUrl); authUrl.searchParams.set('redirect_uri', encodeURIComponent(callbackUrl)); authUrl.searchParams.set('principal', principal);