Add support to load settings from options (flag) and default to specific options
Summary: This change gives priority to a user option settingsString to set up the flipper-server configuration and load them from a json string. Also giving the user the chance to avoid flipper-server looking at the launcher config files in the computer Reviewed By: mweststrate Differential Revision: D34210110 fbshipit-source-id: 9e852b79da106b5140c59116fd7d0c0f3155e620
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ff872400c7
commit
b2dae4da81
@@ -13,7 +13,16 @@ import xdg from 'xdg-basedir';
|
||||
import {Settings, Tristate} from 'flipper-common';
|
||||
import {readFile, writeFile, pathExists, mkdirp} from 'fs-extra';
|
||||
|
||||
export async function loadSettings(): Promise<Settings> {
|
||||
export async function loadSettings(
|
||||
settingsString: string = '',
|
||||
): Promise<Settings> {
|
||||
if (settingsString !== '') {
|
||||
try {
|
||||
return replaceDefaultSettings(JSON.parse(settingsString));
|
||||
} catch (e) {
|
||||
throw new Error("couldn't read the user settingsString");
|
||||
}
|
||||
}
|
||||
if (!pathExists(getSettingsFile())) {
|
||||
return getDefaultSettings();
|
||||
}
|
||||
@@ -74,3 +83,7 @@ function getDefaultAndroidSdkPath() {
|
||||
function getWindowsSdkPath() {
|
||||
return `${os.homedir()}\\AppData\\Local\\android\\sdk`;
|
||||
}
|
||||
|
||||
function replaceDefaultSettings(userSettings: Partial<Settings>): Settings {
|
||||
return {...getDefaultSettings(), ...userSettings};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user