Summary: This can quite easily happen if you manually edit it and aren't careful. The least we can do is tell the user about it, because it be a bit surprising otherwise. Reviewed By: jknoxville Differential Revision: D17626760 fbshipit-source-id: 8c7d64b041fa4b97ce2753116800d0e855442dd9
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
/**
|
|
* Copyright 2018-present Facebook.
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
* @format
|
|
*/
|
|
|
|
const path = require('path');
|
|
const os = require('os');
|
|
const fs = require('fs');
|
|
|
|
module.exports = function(argv) {
|
|
if (!process.env.ANDROID_HOME) {
|
|
process.env.ANDROID_HOME = '/opt/android_sdk';
|
|
}
|
|
|
|
// emulator/emulator is more reliable than tools/emulator, so prefer it if
|
|
// it exists
|
|
process.env.PATH =
|
|
['emulator', 'tools', 'platform-tools']
|
|
.map(directory => `${process.env.ANDROID_HOME}/${directory}`)
|
|
.join(':') + `:${process.env.PATH}`;
|
|
|
|
// 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 = {
|
|
pluginPaths: [],
|
|
disabledPlugins: [],
|
|
lastWindowPosition: {},
|
|
};
|
|
|
|
try {
|
|
config = {
|
|
...config,
|
|
...JSON.parse(fs.readFileSync(configPath)),
|
|
};
|
|
} 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};
|
|
};
|