From 558bbdedd4dfa327bbf4b9ea79593834a68c10fc Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 14 Jan 2025 11:44:21 -0800 Subject: [PATCH] use_platform env --- core/control-plane/env.ts | 15 +++++++++++---- core/control-plane/flags.ts | 10 +++++++++- core/util/paths.ts | 7 +++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/core/control-plane/env.ts b/core/control-plane/env.ts index 596fa5fce..16adf0990 100644 --- a/core/control-plane/env.ts +++ b/core/control-plane/env.ts @@ -1,3 +1,4 @@ +import { readUsePlatform } from "../util/paths"; import { usePlatform } from "./flags"; interface ControlPlaneEnv { @@ -52,11 +53,17 @@ const LOCAL_ENV: ControlPlaneEnv = { APP_URL: "http://localhost:3000/", }; -export const controlPlaneEnv = - process.env.CONTROL_PLANE_ENV === "local" +function getControlPlaneEnv(): ControlPlaneEnv { + const usePlatformFileEnv = readUsePlatform(); + const env = usePlatformFileEnv || process.env.CONTROL_PLANE_ENV; + + return env === "local" ? LOCAL_ENV - : process.env.CONTROL_PLANE_ENV === "staging" + : env === "staging" ? STAGING_ENV - : process.env.CONTROL_PLANE_ENV === "test" || usePlatform() + : env === "test" || usePlatform() ? TEST_ENV : PRODUCTION_ENV; +} + +export const controlPlaneEnv = getControlPlaneEnv(); diff --git a/core/control-plane/flags.ts b/core/control-plane/flags.ts index fdb656e15..7b8ff6799 100644 --- a/core/control-plane/flags.ts +++ b/core/control-plane/flags.ts @@ -1,5 +1,13 @@ -import { usePlatformPathExists } from "../util/paths"; +import { readUsePlatform, usePlatformPathExists } from "../util/paths"; export function usePlatform(): boolean { return usePlatformPathExists(); } + +export function getEnvFromUsePlatformFile(): string | undefined { + const contents = readUsePlatform(); + if (contents && contents.trim().length > 0) { + return contents.trim(); + } + return undefined; +} diff --git a/core/util/paths.ts b/core/util/paths.ts index 9f8c2beb8..562d2e819 100644 --- a/core/util/paths.ts +++ b/core/util/paths.ts @@ -306,6 +306,13 @@ export function usePlatformPathExists(): boolean { return fs.existsSync(sPath); } +export function readUsePlatform(): string | undefined { + const sPath = path.join(getContinueGlobalPath(), ".use_platform"); + if (fs.existsSync(sPath)) { + return fs.readFileSync(sPath, "utf8"); + } +} + export function getConfigJsonPathForRemote( remoteConfigServerUrl: string, ): string {