From d4debc41851dbb9299bca3d392bf34e442109aa6 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Thu, 22 Oct 2020 11:34:24 -0700 Subject: [PATCH] Use dotenv for dev mode customisation Summary: Allow using of .env file to pass env vars to be used in dev mode. Currently this allow to configure defaults for enabling fast refresh, automatic opening of dev tools and plugins to load. Reviewed By: passy Differential Revision: D24398938 fbshipit-source-id: 30a5d86b7906a7723a404cf84a1b8d50ae497dbc --- .gitignore | 1 + desktop/.gitignore | 1 + desktop/package.json | 1 + desktop/plugin-lib/src/pluginPaths.ts | 2 +- desktop/scripts/start-dev-server.ts | 4 ++++ desktop/static/main.ts | 2 +- 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7a4abb07c..acedfa4a4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ bundle.js bundle.map *.bundle.js *.bundle.map +.env # conflicts with FB internal infra .watchmanconfig diff --git a/desktop/.gitignore b/desktop/.gitignore index 9766c2add..1682a65fe 100644 --- a/desktop/.gitignore +++ b/desktop/.gitignore @@ -5,3 +5,4 @@ node_modules/ /static/defaultPlugins/index.json /app/src/defaultPlugins/index.tsx /coverage +.env diff --git a/desktop/package.json b/desktop/package.json index b66eb95d9..8df7d8962 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -171,6 +171,7 @@ "chalk": "^4.0.0", "cross-env": "^7.0.2", "detect-port": "^1.1.1", + "dotenv": "^8.2.0", "electron": "10.1.3", "electron-builder": "^22.8.0", "eslint": "^7.9.0", diff --git a/desktop/plugin-lib/src/pluginPaths.ts b/desktop/plugin-lib/src/pluginPaths.ts index 7d1d57c6e..2801e37fb 100644 --- a/desktop/plugin-lib/src/pluginPaths.ts +++ b/desktop/plugin-lib/src/pluginPaths.ts @@ -25,7 +25,7 @@ export const pluginCacheDir = path.join(flipperDataDir, 'plugins'); export async function getPluginSourceFolders(): Promise { const pluginFolders: string[] = []; - if (process.env.FLIPPER_NO_EMBEDDED_PLUGINS === 'true') { + if (process.env.FLIPPER_NO_EMBEDDED_PLUGINS) { console.log( '🥫 Skipping embedded plugins because "--no-embedded-plugins" flag provided', ); diff --git a/desktop/scripts/start-dev-server.ts b/desktop/scripts/start-dev-server.ts index b24b19c60..c0395544e 100644 --- a/desktop/scripts/start-dev-server.ts +++ b/desktop/scripts/start-dev-server.ts @@ -7,6 +7,7 @@ * @format */ +const dotenv = require('dotenv').config(); const electronBinary: string = require('electron') as any; import codeFrame from '@babel/code-frame'; import socketIo from 'socket.io'; @@ -356,5 +357,8 @@ function checkDevServer() { await startMetroServer(app, server); outputScreen(socket); await compileMain(); + if (dotenv && dotenv.parsed) { + console.log('✅ Loaded env vars from .env file: ', dotenv.parsed); + } shutdownElectron = launchElectron(port); })(); diff --git a/desktop/static/main.ts b/desktop/static/main.ts index c5fd2fb2b..6ca65ac7f 100644 --- a/desktop/static/main.ts +++ b/desktop/static/main.ts @@ -283,7 +283,7 @@ function createWindow() { }); win.once('ready-to-show', () => { win.show(); - if (argv['open-dev-tools']) { + if (argv['open-dev-tools'] || process.env.FLIPPER_OPEN_DEV_TOOLS) { win.webContents.openDevTools(); } });