Typescriptify the main process code (2/N)
Summary: Converted main.js and setup.js to typescript Reviewed By: mweststrate Differential Revision: D19972273 fbshipit-source-id: f777be737da4233de4d7df3d549206efabfeeadf
This commit is contained in:
committed by
Facebook Github Bot
parent
18c259dc22
commit
0c778af679
63
static/setup.ts
Normal file
63
static/setup.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its 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';
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
export default function setup(argv: any) {
|
||||
// ensure .flipper folder and config exist
|
||||
const flipperDir = path.join(os.homedir(), '.flipper');
|
||||
if (!fs.existsSync(flipperDir)) {
|
||||
fs.mkdirSync(flipperDir);
|
||||
}
|
||||
|
||||
const configPath = path.join(flipperDir, 'config.json');
|
||||
let config: Config = {
|
||||
pluginPaths: [],
|
||||
disabledPlugins: [],
|
||||
};
|
||||
|
||||
try {
|
||||
config = {
|
||||
...config,
|
||||
...JSON.parse(fs.readFileSync(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.');
|
||||
fs.writeFileSync(configPath, JSON.stringify(config));
|
||||
}
|
||||
|
||||
// Non-persistent CLI arguments.
|
||||
config = {
|
||||
...config,
|
||||
updaterEnabled: argv.updater,
|
||||
launcherEnabled: argv.launcher,
|
||||
launcherMsg: argv.launcherMsg,
|
||||
};
|
||||
|
||||
return {config, configPath, flipperDir};
|
||||
}
|
||||
Reference in New Issue
Block a user