Rename first batch for '.ts' files to '.tsx' in doctor, static and test-utils
Summary: Rename first batch for '.ts' files to '.tsx' Reviewed By: nikoant Differential Revision: D33843051 fbshipit-source-id: 68dd2dc6538afce2daaf24c6412dc5db8b38acbc
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6a28a712f9
commit
b4fc108c2e
89
desktop/static/setup.tsx
Normal file
89
desktop/static/setup.tsx
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
import fs from 'fs';
|
||||
|
||||
const flipperHomeDir = path.join(os.homedir(), '.flipper');
|
||||
export const configPath = path.join(flipperHomeDir, 'config.json');
|
||||
export const defaultConfig: Config = {
|
||||
pluginPaths: [],
|
||||
disabledPlugins: [],
|
||||
darkMode: 'light',
|
||||
};
|
||||
|
||||
export type Config = {
|
||||
pluginPaths?: string[];
|
||||
disabledPlugins?: string[];
|
||||
lastWindowPosition?: {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
updater?: boolean | undefined;
|
||||
launcherMsg?: string | undefined;
|
||||
updaterEnabled?: boolean;
|
||||
launcherEnabled?: boolean;
|
||||
darkMode: 'system' | 'light' | 'dark';
|
||||
};
|
||||
|
||||
const ensureConfigDirExists = async (path: fs.PathLike) => {
|
||||
try {
|
||||
await fs.promises.access(path);
|
||||
} catch (e) {
|
||||
console.warn('Config directory not found, creating config directory.');
|
||||
try {
|
||||
await fs.promises.mkdir(path);
|
||||
} catch (e) {
|
||||
console.error('Failed to create config directory', e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const readConfigFile = async (configPath: fs.PathLike) => {
|
||||
let config = defaultConfig;
|
||||
|
||||
try {
|
||||
config = {
|
||||
...config,
|
||||
...JSON.parse((await fs.promises.readFile(configPath)).toString()),
|
||||
};
|
||||
} catch (e) {
|
||||
// file not readable or not parsable, overwrite it with the new config
|
||||
console.warn(`Failed to read ${configPath}: ${e}`);
|
||||
console.info('Writing new default config.');
|
||||
await fs.promises.writeFile(configPath, JSON.stringify(config));
|
||||
}
|
||||
return config;
|
||||
};
|
||||
|
||||
export default async function setup(argv: any) {
|
||||
// ensure .flipper folder and config exist
|
||||
await ensureConfigDirExists(flipperHomeDir);
|
||||
|
||||
let config = await readConfigFile(configPath);
|
||||
|
||||
// Non-persistent CLI arguments.
|
||||
config = {
|
||||
...config,
|
||||
darkMode:
|
||||
typeof config.darkMode === 'boolean'
|
||||
? config.darkMode // normalise darkmode from old format
|
||||
? 'dark'
|
||||
: 'light'
|
||||
: config.darkMode,
|
||||
updaterEnabled: argv.updater,
|
||||
launcherEnabled: argv.launcher,
|
||||
launcherMsg: argv.launcherMsg,
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
Reference in New Issue
Block a user