From 5bb3820d6a135127ca2806ce04da7a145485ba13 Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Tue, 11 Dec 2018 14:46:03 +0000 Subject: [PATCH] Switch to local mode in unmanaged mode Change-type: major Signed-off-by: Cameron Diver --- src/config/functions.ts | 7 +++++++ src/config/index.ts | 1 + src/local-mode.ts | 17 ++++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/config/functions.ts b/src/config/functions.ts index c3e3940c..eeb95ce2 100644 --- a/src/config/functions.ts +++ b/src/config/functions.ts @@ -149,5 +149,12 @@ export function createProviderFunctions( ]); }, }, + unmanaged: { + get: () => { + return config.get('apiEndpoint').then(apiEndpoint => { + return !apiEndpoint; + }); + }, + }, }; } diff --git a/src/config/index.ts b/src/config/index.ts index 15b15f0c..746c15c1 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -60,6 +60,7 @@ class Config extends EventEmitter { mixpanelHost: { source: 'func' }, extendedEnvOptions: { source: 'func' }, fetchOptions: { source: 'func' }, + unmanaged: { source: 'func' }, // NOTE: all 'db' values are stored and loaded as *strings*, apiSecret: { source: 'db', mutable: true }, diff --git a/src/local-mode.ts b/src/local-mode.ts index d6829318..fcd45b60 100644 --- a/src/local-mode.ts +++ b/src/local-mode.ts @@ -40,9 +40,20 @@ export class LocalModeManager { } }); - const localMode = checkTruthy( - (await this.config.get('localMode')) || false, - ); + // On startup, check if we're in unmanaged mode, + // as local mode needs to be set + let unmanagedLocalMode = false; + if (checkTruthy((await this.config.get('unmanaged')) || false)) { + console.log('Starting up in unmanaged mode, activating local mode'); + await this.config.set({ localMode: true }); + unmanagedLocalMode = true; + } + + const localMode = + // short circuit the next get if we know we're in local mode + unmanagedLocalMode || + checkTruthy((await this.config.get('localMode')) || false); + if (!localMode) { // Remove any leftovers if necessary await this.removeLocalModeArtifacts();