From 1e851ad0c926454a3c29581066cd6b2292022eb6 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Thu, 31 Jul 2025 15:46:23 +0200 Subject: [PATCH] feat: --profile environment option --- src/cli/env.loader.ts | 20 ++++++++++++++++---- src/constants/help.constants.ts | 5 ++++- src/help/login.help.ts | 4 ++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/cli/env.loader.ts b/src/cli/env.loader.ts index f2e1a272..da70e32a 100644 --- a/src/cli/env.loader.ts +++ b/src/cli/env.loader.ts @@ -6,6 +6,7 @@ export const loadEnv = (): JunoCliEnv => { const [_, ...args] = process.argv.slice(2); const mode = nextArg({args, option: '-m'}) ?? nextArg({args, option: '--mode'}); + const profile = nextArg({args, option: '-p'}) ?? nextArg({args, option: '--profile'}); const containerUrl = nextArg({args, option: '--container-url'}); const envContainerUrl = @@ -17,7 +18,7 @@ export const loadEnv = (): JunoCliEnv => { mode: mode ?? 'production', containerUrl: envContainerUrl, console: loadEnvConsole({args, mode}), - config: loadEnvConfig({mode}), + config: loadEnvConfig({mode, profile}), ci }; }; @@ -37,10 +38,21 @@ const loadEnvConsole = ({args, mode}: {args?: string[]; mode: string | undefined }; }; -const loadEnvConfig = ({mode}: {mode: string | undefined}): JunoCliConfig => { +const loadEnvConfig = ({ + mode, + profile +}: { + mode: string | undefined; + profile: string | undefined; +}): JunoCliConfig => { // Historically we used "juno" - without environment reference - for production. - // That is why we keep this approach for backwards compatibility. - const projectName = notEmptyString(mode) && mode !== 'production' ? `juno-${mode}` : 'juno'; + // That is why we keep this default approach for backwards compatibility. + const modeSuffix = + notEmptyString(mode) && (mode !== 'production' || notEmptyString(profile)) ? `-${mode}` : ''; + + const profileSuffix = notEmptyString(profile) ? `-${profile}` : ''; + + const projectName = `juno${profileSuffix}${modeSuffix}`; return { projectName, diff --git a/src/constants/help.constants.ts b/src/constants/help.constants.ts index a08842d5..2af54691 100644 --- a/src/constants/help.constants.ts +++ b/src/constants/help.constants.ts @@ -44,6 +44,7 @@ export const OPTION_KEEP_STAGED = `${yellow('-k, --keep-staged')} Keep stage export const OPTION_HASH = `${yellow('--hash')} The expected hash of all included changes (for verification).`; export const OPTION_HELP = `${yellow('-h, --help')} Output usage information.`; export const OPTION_MODE = `${yellow('-m, --mode')} Choose which environment to use (production, staging, development). Defaults to production if omitted.`; +export const OPTION_PROFILE = `${yellow('-p, --profile')} Specify an optional profile to use (e.g. personal, team). Useful when managing multiple Mission Controls.`; export const OPTION_SRC = `${yellow('-s, --src')} A path to a specific local gzipped WASM file to publish.`; export const OPTIONS_UPGRADE = `${yellow('--clear-chunks')} Clear any previously uploaded WASM chunks (applies if the WASM size is greater than 2MB). @@ -52,7 +53,9 @@ export const OPTIONS_UPGRADE = `${yellow('--clear-chunks')} Clear any pre export const OPTIONS_BUILD = `${yellow('-l, --lang')} Specify the language for building the serverless functions: ${magenta('rust')}, ${magenta('typescript')} or ${magenta('javascript')}. ${yellow('--cargo-path')} Path to the Rust manifest. ${yellow('--source-path')} Optional path to the TypeScript or JavaScript entry file.`; -export const OPTIONS_ENV = `${OPTION_MODE} +export const OPTIONS_CONFIG = `${OPTION_MODE} + ${OPTION_PROFILE}`; +export const OPTIONS_ENV = `${OPTIONS_CONFIG} ${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.`; diff --git a/src/help/login.help.ts b/src/help/login.help.ts index b108ccf7..b91ab485 100644 --- a/src/help/login.help.ts +++ b/src/help/login.help.ts @@ -1,5 +1,5 @@ import {cyan, green, yellow} from 'kleur'; -import {LOGIN_DESCRIPTION, OPTION_HELP, OPTION_MODE} from '../constants/help.constants'; +import {LOGIN_DESCRIPTION, OPTION_HELP, OPTIONS_CONFIG} from '../constants/help.constants'; import {helpOutput} from './common.help'; import {TITLE} from './help'; @@ -7,7 +7,7 @@ const usage = `Usage: ${green('juno')} ${cyan('login')} ${yellow('[options]')} Options: ${yellow('-b, --browser')} A particular browser to open. supported: chrome|firefox|edge. - ${OPTION_MODE} + ${OPTIONS_CONFIG} ${OPTION_HELP}`; const doc = `${LOGIN_DESCRIPTION}