From 74a726aaf9ddfdd4af7d5467aeed8dcee444e950 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Tue, 5 Feb 2019 04:46:33 -0800 Subject: [PATCH] Use yargs for non-headless Flipper args parsing Summary: This seems like a better approach than ad-hoc lookup in `electron.remove.argv`. Left a note to a task to provide a better interface to this. I also need this in order to ensure we're starting Flipper through the launcher which needs to happen before we start the Electron runtime. Reviewed By: jknoxville Differential Revision: D13881355 fbshipit-source-id: 69c70d71035a47084f789ddb4dc969b45ba4648b --- headless/index.js | 2 +- src/utils/argvUtils.js | 8 +++++--- static/index.js | 13 ++++++++++++- static/setup.js | 14 ++++++++++++-- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/headless/index.js b/headless/index.js index b4a717e47..a4b04b664 100644 --- a/headless/index.js +++ b/headless/index.js @@ -47,7 +47,7 @@ yargs startFlipper, ) .version(global.__VERSION__) - .help().argv; + .help(); function startFlipper({ dev, diff --git a/src/utils/argvUtils.js b/src/utils/argvUtils.js index fab9de54f..42bf7fcd4 100644 --- a/src/utils/argvUtils.js +++ b/src/utils/argvUtils.js @@ -9,7 +9,9 @@ import electron from 'electron'; import isProduction from './isProduction'; export const isAutoUpdaterEnabled = () => - // $FlowFixMe: argv is not included in the type defs. - !electron.remote.process.argv.includes('--no-updater') && + // TODO(T39788540): Centralise config access and avoid parsing multiple times. + // $FlowFixMe: env is not in the type defs. + JSON.parse(electron.remote?.process.env.CONFIG || process.env.CONFIG || '{}') + .updaterEnabled && isProduction() && - process.platform === 'darwin'; + process.platform === 'darwin'; \ No newline at end of file diff --git a/static/index.js b/static/index.js index 0385cfd34..ea4b3f9c6 100644 --- a/static/index.js +++ b/static/index.js @@ -17,6 +17,7 @@ const compilePlugins = require('./compilePlugins.js'); const os = require('os'); const setup = require('./setup'); const expandTilde = require('expand-tilde'); +const yargs = require('yargs'); // disable electron security warnings: https://github.com/electron/electron/blob/master/docs/tutorial/security.md#security-native-capabilities-and-your-responsibility process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true; @@ -36,7 +37,17 @@ if (process.platform === 'darwin') { } } -let {config, configPath, flipperDir} = setup(); +const argv = yargs + .usage('$0 [args]') + .option('updater', { + default: true, + describe: 'Toggle the built-in update mechanism.', + type: 'boolean', + }) + .version(global.__VERSION__) + .help().argv; + +let {config, configPath, flipperDir} = setup(argv); const pluginPaths = config.pluginPaths .concat( diff --git a/static/setup.js b/static/setup.js index 27fdf322d..7bc8459ec 100644 --- a/static/setup.js +++ b/static/setup.js @@ -9,7 +9,7 @@ const path = require('path'); const os = require('os'); const fs = require('fs'); -module.exports = function() { +module.exports = function(argv) { if (!process.env.ANDROID_HOME) { process.env.ANDROID_HOME = '/opt/android_sdk'; } @@ -27,7 +27,11 @@ module.exports = function() { } const configPath = path.join(flipperDir, 'config.json'); - let config = {pluginPaths: [], disabledPlugins: [], lastWindowPosition: {}}; + let config = { + pluginPaths: [], + disabledPlugins: [], + lastWindowPosition: {}, + }; try { config = { @@ -39,5 +43,11 @@ module.exports = function() { fs.writeFileSync(configPath, JSON.stringify(config)); } + // Non-persistent CLI arguments. + config = { + ...config, + updaterEnabled: argv.updater, + }; + return {config, configPath, flipperDir}; };